keepalived配置mysql主从自动切换
2020-03-07 本文已影响0人
不知不怪
1.两台机器已配置好mysql主从复制
2.两台机器都安装keepalived
yum install -y keepalived
3.启动停止命令
systemctl start keepalived.service #启动 keepalived
systemctl stop keepalived.service #停止 keepalived
systemctl restart keepalived.service #重启动 keepalived
4.编辑配置文件
vim /etc/keepalived/keepalived.conf
5.主库所在keepalived
global_defs {
router_id LVS_MASTER
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 200
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.218.150/24
}
}
systemctl restart keepalived.service #重启动 keepalived
6.从库所在keepalived
global_defs {
router_id LVS_SLAVE
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.218.150/24
}
}
systemctl restart keepalived.service #重启动 keepalived
7.分别查看两台机器的IP与keepalived进程
ip a
ps -ef | grep keepalived
8.应程序连接VIP
就是
virtual_ipaddress {
192.168.218.150/24
}
中的IP