MySQL主从不介绍
安装keepalived
keepalived在epel源,需要先安装epel
然后直接yum 安装keepalive
默认配置文件安装在/etc/keepalived/下
! Configuration File for keepalived
global_defs {
router_id MySQL-HA
}
vrrp_script check_run {
script "/home/mysql/mysql_check.sh" #脚本权限
interval 5
}
vrrp_instance VI_1 {
state MASTER #备机BACKUP
interface bond0 #网卡地址
virtual_router_id 51
priority 100 #优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
track_script {
check_run
}
virtual_ipaddress {
10.205.28.20
}
}
MySQL检查脚本
#!/bin/bash
count=1
mysql -uroot -pzkjin@mysql123 -S /home/mysql/mysql3306/mysql3306.sock -e "show status;" > /dev/null 2>&1
i=$?
j=`ps aux | grep mysqld | grep -v grep|wc -l`
if [ $i != 0 ] && [ $j != 2 ]
then
systemctl stop keepalived
fi