keepalived uses scripts to monitor mysql status

1. centos7 keepalived+mysql master and slave high-availability cluster

Link >> https://blog.csdn.net/m0_46674735/article/details/112425808

2. Keepalived uses scripts to monitor mysql status

2.1 Write a script to monitor the mysql status on server1. The content of the script is:

#!/bin/bash
port_num=$(ss -nltp|grep -wc 3306)
if [ $port_num -eq 0 ];then
    pkill keepalived
fi

Add execution permissions to the script after writing

chmod +x check_mysql.sh 

2.2 Modify the keepalived configuration file of server1 and call the script

vim /etc/keepalived/keepalived.conf 

1) Comment out the content of line 14, the comment symbol is!

Insert picture description here

2) Define the script and call

Insert picture description here

3) Restart the keepalived service after saving and exiting

systemctl restart keepalived

2.3 Perform the same operation on server2

3. Verification

3.1 View the VIP address of server1

command:ip add

Insert picture description here

3.2 Turn off the mysql service on server1

 systemctl stop mariadb

3.3 VIP successfully drifted to server2

Insert picture description here

3.4 Recover mysql service and keepalived service on server1

systemctl start mariadb
systemctl start keepalived

3.5 VIP successfully drifted back to server1

Insert picture description here

Guess you like

Origin blog.csdn.net/m0_46674735/article/details/112426865