MySQL+keeplived高可用配置
MySQL高可用
基础环境:
基于MySQL互为主从(双主、主主),请现配置
主备两台机器
主的操作
1.在keepalived主服务器上安装keepalived
yum -y install keepalived
2.编辑配置文件
vim /etc/keepalived/keepalived.conf 内容更改如下: vrrp_instance VI_1 { state MASTER \\初始状态:MASTER/BACKUP interface eth0 \\生成VIP的网卡设备 virtual_router_id 51 \\广播的路由ID priority 100 \\优先级 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.189.181 \\VIP地址 } } virtual_server 192.168.189.181 3306 { \\虚拟机服务器 delay_loop 6 nat_mask 255.255.255.0 protocol TCP real_server 192.168.189.120 3306 { \\真实服务器 weight 1 notify_down /root/kill.sh \\当检测的真实服务器器3306端口不可用时,要执行的脚本 TCP_CHECK { connect_timeout 3 connect_port 3306 \\检测的端口 nb_get_retry 3 delay_before_retry 3 } } }
3. 生成停止mysql的脚本
vim /root/kill.sh 内容: #!/bin/bash service keepalived stop
4.脚本保存退出后重启keepalived
service keepalived restart
5.查看VIP是否生成
ip a
备份主机的操作
操作和主基本一致,需要更改的有:初始状态、优先级、真实服务器ip地址
1.复制主的keepalived的配置文件到服务器
scp 192.168.189.129:/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf
2.编辑配置文件
vim /etc/keepalived/keepalived.conf
注意如下配置:
state BACKUP interface eth0 priority 90
real_server 192.168.189.130 3306
3. 生成停止mysql的脚本
vim /root/kill.sh 内容: #!/bin/bash service keepalived stop
4.更改完毕后重启keepalived
service keepalived restart
测试
停止主的mysql查看 VIP是否漂移到备份主机上,如成功飘逸则是配置成功