Sharing IP addresses between two servers

There are two virtual servers with HAProxy posted on different physical machines, the task is to make the failover, ie to raise the IP address on the machine which is now available if the other stops responding.

All IP address from one pool, broadcast the same, but one machine does not see what the other sends, in broadcast, so solutions such as keepalived, ucarp, heartbeat not suitable. Why not see, do not know, but since no access to the network or to klenowski hypervisors that this side is nothing to fix. What else can you use to achieve the result without the broadcast? (To send in the broadcast is not a problem — still have to send ARP request blashemy to the router to change IP. The problem — read the other Itske of the broadcast).

Thank you.
October 14th 19 at 10:43
4 answers
October 14th 19 at 10:45
But all the same was faster and easier to write. Tell us more, for it is a good thing. I don't raspisyvaya as on different systems, but should work without problems on any redhat'about that.

two servers with the main yeskali and
necessary third ipishka, which will rise on a live server if the other fell

20 let the server be in charge, prescribe it in /etc/rc.local lifting alpiski and request to clear the cache::
ifconfig eth0:1 netmask
arping -c 1-s

Other 30 the server will be on support, if suddenly the first will refuse. It creates the script /usr/local/sbin/setupip inside:


sleep 10
while true; do
count=$(ping -c 1 $MASTERHOST | grep 'received' | awk -F',' '{ print $2 }' | awk '{ print $1 }')
localip=$(ifconfig | grep "$IP1 " | wc-l)
if [ $count -eq 0 ]; then
 if [ $localip -eq 0 ]; then
 #if the IP is not set - do add it, send ARP cache clear
 logger "setupip :: Host $MASTERHOST is down at $(date); Binding up $IP1"
 ifconfig $INERFACE1 $IP1 netmask $MASK1
 arping -c 1-s $IP1 $GATE1
 if [ $localip -gt 0 ]; then
 logger "setupip :: Host $MASTERHOST is UP at $(date); Shutting down $IP1"
 ifconfig $INERFACE1 down

sleep 10

Make it executable, put the script in /etc/rc.local to run at startup:
/usr/local/sbin/setupip &

Reboot. Everything is ready.

The result is:
  • every 10 seconds the second server pings first
  • if the first is the second raises the desired IP, cleans the ARP cache, and makes an entry in syslog (/var/log/messages)
  • if the first rises, he runs at himself and cleaned the IP ARP cache from itself, and takes all request themselves
  • the second sees that the first has risen, and puts IP at

All the tests ended well. Variables must be intuitive.
Think someone this script will be useful.
Oh! Habr cake, excuse me.
And in the case — Yes, Keep It Simple Stupid type of script in half a page usually works better than a strange monster with tons of features. - angel86 commented on October 14th 19 at 10:48
October 14th 19 at 10:47
Something I think that the Bicycle invented long ago. One of the variants of this bike is called heartbeat one line config is written what is above is painted on half a page
If you carefully read my question it says "solutions such as keepalived, ucarp, heartbeat doesn't work." And even says why. - angel86 commented on October 14th 19 at 10:50 - linda_Pollich commented on October 14th 19 at 10:53
October 14th 19 at 10:49
It is called VRRP

We advise to use keepalived
sorry, was not attentive. - angel86 commented on October 14th 19 at 10:52
:) waiting for the third proposal ucarp - linda_Pollich commented on October 14th 19 at 10:55
October 14th 19 at 10:51
simple failover can be done on scripts service is allocated additional IP which is hung an alias on the interface is unavailable, and then lifted the service itself.
How do you suggest to run a script? Ideally, this should be the demon and not the script in the crown. In fact, I used to check ping came up, but what to do if one have to do with the big priority (master) — second you need to lay down and the ARP cache is cleaned. Poluchaetsya two scripts? There is more to consider necessary, that asking about such ready solution. - angel86 commented on October 14th 19 at 10:54

Find more questions by tags Linux