1. Experimental logic diagram
2. Configuration of the master host (192.168.153.136)
2.1 Modify the keepalived configuration file
vim /etc/keepalived/keepalived.conf
The revised content is as follows:
2.2 After the modification is completed, save and exit to open the keepalived service
systemctl start keepalived
3. Configuration of the backup host (192.168.153.137)
3.1 Modify the keepalived configuration file
vim /etc/keepalived/keepalived.conf
The revised content is as follows
3.2 After the modification is completed, save and exit to open the keepalived service
systemctl start keepalived
4. Verification
4.1 View the VIP address of the master host
View command: ip a
4.2 Stop the Apache service of the master host
systemctl stop httpd
4.3 Check that the VIP successfully drifted to the backup host
4.4 Restoring the Apache service on the master host
systemctl start httpd
4.5 VIP successfully drifted back to the master host
5. Extension
5.1 The script name can be written as check_httpd.sh, the content is as follows:
#!/bin/bash
ss -nltp|grep -wq 80
if [ $? -ne 0 ];then
pkill keepalived
fi
5.2 Increase the execution permission after the script is written
chmod +x /root/check_httpd.sh
5.3 Keepalived is only the script definition part is different from the above, the rest are the same
5.4 The effect can be achieved by turning on the keepalived service after writing
systemctl start keepalived