133.1 Keepalived安装
- 在MySQLA和MySQLB安装Keepalived服务
yum -y install keepalived
- 加入开机自启
systemctl enable keepalived
133.2 MySQL监测脚本
- MySQL服务状态监测脚本,主要监控MariaDB服务状态是否正常
- 如果不正常则将该MySQL所在服务的Keepalived服务杀死
- 监控MySQL服务是否正常的方法有多种可以通过端口号
- 进程ID以及执行MySQL命令
- 这里使用mysladmin执行命令来监测MariaDB服务是否正常,脚本内容如下(check_mysql.sh)
#!/bin/bash
MYSQL_PING=`mysqladmin -uroot -p123456 ping`
MYSQL_OK="mysqld is alive"
if [[ "$MYSQL_PING" != "$MYSQL_OK" ]]
then
echo "mysql is not running"
killall keepalived
else
echo "mysql is running"
fi
- check_mysql.sh设置
[root@vm1 ~]# chmod +x /etc/keepalived/check_mysql.sh
[root@vm1 ~]# ll /etc/keepalived/check_mysql.sh
-rwxr-xr-x 1 root root 233 Dec 29 07:34 /etc/keepalived/check_mysql.sh
[root@vm1 ~]#
133.3 MySQLA上Keepalived配置
- /etc/keepalived/keepalived.conf配置文件编辑
[root@vm1 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
}
vrrp_script check_mysql {
script "/etc/keepalived/check_mysql.sh"
interval 2
}
vrrp_instance VI_1 {
state BACKUP
interface ens192
virtual_router_id 51
priority 100
advert_int 1
nopreempt
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.188
}
track_script {
check_mysql
}
}
- Keepalived服务启动
[root@vm1 ~]# systemctl start keepalived
-
检查网卡绑定
-
MySQLB服务器上ping
-
停止Keepalived服务查看是否解绑
133.4 MySQLB上Keepalived配置
- /etc/keepalived/keepalived.conf配置编辑
[root@vm2 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
}
vrrp_script check_mysql {
script "/etc/keepalived/check_mysql.sh"
interval 2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.188
}
track_script {
check_mysql
}
}
- Keepalived服务启动
[root@vm2 ~]# systemctl start keepalived
-
网卡检查
-
在MySQLA服务上ping
133.5 Keepalived验证服务IP漂移
133.6 MySQL高可用验证
大数据视频推荐:
网易云课堂
CSDN
人工智能算法竞赛实战
AIops智能运维机器学习算法实战
ELK7 stack开发运维实战
PySpark机器学习从入门到精通
AIOps智能运维实战
腾讯课堂
大数据语音推荐:
ELK7 stack开发运维
企业级大数据技术应用
大数据机器学习案例之推荐系统
自然语言处理
大数据基础
人工智能:深度学习入门到精通
网友评论