Skip to content

Redis Sentinel doesn't communicate via Virtual IP despite being bound to it #1667

Closed

Description

@Ocado-NickBrown

We're trying Redis for the first time, version 2.8.4.

We've set up 3 Redis instances in 3 VMs. Each of these VMs also runs a Sentinel instance. We've configured the bind parameter in both redis.conf and sentinel.conf so the respective process is bound to a Virtual IP ("VIP") in that VM.

Both processes launch fine and we can see that redis sentinel starts rewriting its sentinel.conf as expected. There's a problem though - it can't talk to the other sentinels.

Despite us binding to the VIP address in each of the 3 x sentinel.conf, any given sentinel sometimes sees another given sentinel at its VM IP address rather than its VIP address.

Running a watch -n 1 tail -n 1 sentinel.conf on one of our VMs shows the following line:

sentinel known-sentinel itfus004 10.97.5.254 26379 aed42071df79730ae28fd00dbe0dee3dcc4d27a8

..this references one of our VM IP addresses, while a split second later that same line can change to the VIP address:

sentinel known-sentinel itfus004 10.97.5.211 26379 aed42071df79730ae28fd00dbe0dee3dcc4d27a8

We can set up IP tables on the VMs to ensure that all traffic from a VM has a source address that is the VIP as we desire. But this still doesn't fix the above issue, and we know that our networking logic works well for other software.

Can someone please look into how the sentinel receives the other sentinels' addresses, and why these can sometimes be different than the address we've instructed each sentinel to bind to?

Many thanks.

Activity

  1. mattsta commented on Apr 7, 2014

    @mattsta
    Contributor

    Redis lies to us a bit here. The bind directive should probably be called listen instead. bind is a set of address Redis uses to listen instead of listening to everything with 0.0.0.0 (default).

    For Redis Cluster we make Redis use the first bind address as the source address of outgoing connections, but the address must be on the server by default. (You can get around the "existence" requirement by setting /proc/sys/net/ipv4/ip_nonlocal_bind and running with the proper CAP_NET_ADMIN capability).

    With your current setup, is the lack of source binding causing the Sentinel problems? If so we can look into binding the source address for Sentinel as well.

  2. Ocado-NickBrown commented on Apr 8, 2014

    @Ocado-NickBrown
    Author

    Thanks for the info.

    The fundamental issue is that when I configure both redis and redis-sentinel to 'bind' to a VIP address this causes them to only listen on that interface as you've pointed out. So thereafter whenever a VM IP is used by sentinel in place of the intended Virtual IP that connection can't succeed since the port's not being LISTENed to on that interface.

    The real question is why does the value flicker in the auto rewrites to sentinel.conf, and specifically where is the VM IP it intermittently lists coming from? In answer to your question - if the origin of the VM IP in the configuration is the TCP source address then yes, it seems like offering the ability to configure that would overcome the issue. Essentially by answering the question of where any address other than the 'bind' address configured comes from we can identify how to resolve the problem in this case.

    For now we've worked around the issue by binding to ports on our VMs but this is less than ideal, and not what we do with other software. I say it's less than ideal because it means we need to start incrementing port numbers across redis+sentinel instances and store that metadata. Whereas with the VIP binding approach we can use the default port number for every instance, creating much better standardisation.

  3. mattsta commented on Apr 8, 2014

    @mattsta
    Contributor

    Can you try out a custom build with source binding to see if your problem goes away?

    I added sentinel source binding at https://github.com/mattsta/redis/tree/source-bind-sentinel

    Sentinel will bind to your bind address instead of letting the system determine its own source.

    You can build it with:

    git clone https://github.com/mattsta/redis matt-redis
    cd matt-redis
    git checkout source-bind-sentinel
    make -j
    

    Let me know how it works out for you. It's based on the current unstable branch. If all goes well, we can get the source binding change added permanently.

    I'll also look into updating the included hiredis to match the hiredis repo instead of being very out of date.

  4. Ocado-NickBrown commented on Apr 10, 2014

    @Ocado-NickBrown
    Author

    It works like a charm, thanks for the quick turnaround!

    Can you please let me know once this is available as an official deb? Until then we'll monkeypatch the fixed redis-server binary over our current deb install.

  5. alistar79 commented on Apr 24, 2014

    @alistar79

    When will this be in an official release? I'm on 2.8.8 and I really need my redis sentinels to announce an AWS Elastic IP and not that of the systems first interface as it seems to currently.

  6. mattsta commented on Apr 24, 2014

    @mattsta
    Contributor

    I'll add a pull request for the new behavior soon. The source address binding is now added to hiredis master, so we can update the version in Redis to get everything working.

  7. alistar79 commented on Apr 24, 2014

    @alistar79

    Cheers! :)

  8. alistar79 commented on Apr 25, 2014

    @alistar79

    Our workaround incase any needs another is to rewrite the local ips to the elastic_ips using iptables as so:
    iptables -t nat -A OUTPUT -d $local_ip -j DNAT --to $elastic_ip

    Don't rewrite the local_ip on on the node owning it tho obviously.

  9. added 2 commits that reference this issue on Jun 23, 2014
    8066334
    02b9480
  10. added a commit that references this issue on Mar 6, 2025
    5cd83ef
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions