Two Linux servers, one main machine (ip:124.158.26.30) to provide a certain network services, and another slave (ip:124.158.26.31) to provide the same services, But the IP address is not the external public client connection is 124.158.26.30 this IP address, if the host failure, it will make the network service temporarily interrupted, the longer the loss due to the lack of dual-machine hot standby technology, consider their own Linux script to implement simple floating IP technology, when the host failed to get 124 from the machine .158.26.30 This IP, temporarily replace the host to provide services, when the host recovery, the slave automatically release this IP
Realize:
Technology to bind multiple IP addresses with a single NIC and crontab automatic execution technology
For the host's network card more binding a static IP, such as 124.158.26.32, this address is easy to determine from the machine, for slave network card binding a dynamic ip,127.0.0.1, it will be modified by the script when the host failure 124.158.26.30
Add a script to the slave machine floatip.sh, using crontab technology to make this script to execute every minute, the role of this script is to determine the host address 32 can ping, once the general will let their network card redundant that IP address to 124.158.26.30, if the host recovery, the address is changed back to 127.0.0.1
Steps:
One, multiple bindings for the host a static ip124.158.26.32
In
Inside the/etc/sysconfig/network-scripts directory, create a name
Ifcfg-eth0:1 file with the following contents:
Device=eth0:1
ipaddr=139.24.214.82
netmask= 255.255.255.0
onboot= Yes
Second, set up script floatip.sh on the slave machine
c1= ' Ping 124.158.26.32-c 1 | grep Unreachable | Wc-l '
C2= ' Ping 124.158.26.32-c 10 | grep Unreachable | Wc-l '
c3= ' Ping 124.158.26.30-c 10 | grep Unreachable | Wc-l '
c4= '/sbin/ifconfig |grep 124.158.26.30 |wc-l '
If [$c 1-gt 0]; then
If [$c 2-gt 9]; then
If [$c 3-gt 9]; then
/sbin/ifconfig eth0:1 124.158.26.30 netmask 255.255.255.0
echo "Float IP to 30"
Fi
Fi
echo "Can not connect"
Else
If [$c 4-gt 0]; then
/sbin/ifconfig eth0:1 127.0.0.1 netmask 255.255.255.0
echo "Reset IP"
Fi
echo "Connection is OK"
Fi
With chmod +x autofloatip.sh
Let it be executed, the contents of the script are
c1=$ (ping 139.24.214.82-c 1|grep unreachable|wc-l)
If [$c 1-gt 0] Then
c2=$ (ping 139.24.214.82-c 10|grep unreachable|wc-l)
If [$c 2-gt 9] Then
c3=$ (ping 139.24.214.22-c 10|grep unreachable|wc-l)
If [$c 3-gt 9] Then
/sbin/ifconfig eth0:1 139.24.214.22 netmask 255.255.254.0
echo "Float IP to 22"
Fi
Fi
echo "Can not connect"
Else
c4=$ (/sbin/ifconfig|grep 139.24.214.22|wc-l)
If [$c 4-gt 0] Then
/sbin/ifconfig eth0:2 127.0.0.1 netmask 255.255.254.0
echo "Reset IP"
Fi
echo "Connection is OK"
Fi
One of the key commands is
/sbin/ifconfig eth0:1 139.24.214.22 netmask 255.255.254.0
/sbin/ifconfig eth0:2 127.0.0.1 netmask 255.255.254.0
Use this method to dynamically modify
Ip
Dynamic
Ip
When the computer restarts, it disappears.
Build Crontab from the machine
Let's add such a line and save
* * * * * */root/autofloatip.sh >/dev/null 2>&1
Little Tips
In the test, you can first change this sentence to
* * * * * */root/autofloatip.sh
So you can use
Mutt
A lot of messages are received, and the user keeps track of script execution
Manually implement floating IP technology on Linux dual machine