By using Keepalived, the two servers can achieve active-standby failover. When one of the servers fails, the other server can take over.
method/step
-
First download Keepalived from the official website, and then log in to the Centos system to install the necessary environment: gcc, openssl, pcre.
-
Copy the downloaded package to the Centos root directory.
Unzip the package, compile and install:
tar zxvf keepalived-1.2.18.tar.gz
cd keepalived-1.2.18
./configure
make
make install
-
Configuration file after installation: /usr/local/eth/keepalived/keepalived.conf
master node:
-
Standby node:
-
Modify the configuration to allow binding unknown IPs:
/etc/sysctl.conf net.ipv4.ip_nonlocal_bind = 1
sysctl -p
Finally copy the configuration file to the corresponding directory:
cp /usr/local/sbin/keepalived /usr/sbin/
cp /usr/local/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
cp -r /usr/local/etc/keepalived/ /etc/
Restart the service:
service keepalived restart
Check the binding status:
-
In the test, use the machine to ping the virtual address for a long time, and perform the switching test: when the main keepalived is turned off, the backup opportunity will take over, and a packet may be lost at this time.
-