You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Redis Sentinel doesn't communicate via Virtual IP despite being bound to it #1667
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:
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?
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.
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.
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.
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.
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.
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.
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.
Activity
mattsta commentedon Apr 7, 2014
Redis lies to us a bit here. The
binddirective should probably be calledlisteninstead.bindis a set of address Redis uses to listen instead of listening to everything with0.0.0.0(default).For Redis Cluster we make Redis use the first
bindaddress 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_bindand running with the properCAP_NET_ADMINcapability).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.
Ocado-NickBrown commentedon Apr 8, 2014
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.
mattsta commentedon Apr 8, 2014
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
bindaddress instead of letting the system determine its own source.You can build it with:
Let me know how it works out for you. It's based on the current
unstablebranch. 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.
Ocado-NickBrown commentedon Apr 10, 2014
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-serverbinary over our current deb install.alistar79 commentedon Apr 24, 2014
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.
mattsta commentedon Apr 24, 2014
I'll add a pull request for the new behavior soon. The source address binding is now added to
hiredismaster, so we can update the version in Redis to get everything working.alistar79 commentedon Apr 24, 2014
Cheers! :)
alistar79 commentedon Apr 25, 2014
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.
Sentinel: bind source address
Sentinel: bind source address
Sentinel: bind source address