MySQL+Keepalived高可用配置

注意:首先关闭两台机器的防火墙 setenforce 0

 

Environment: 2台CentOS测试机器  安装好MySQL

1.两台机器安装keepalived

 1 yum -y install keepalived 

2.编辑配置文件

1 vim /etc/keepalived/keepalived.conf
2 
3     virtual_route_id  51 #广播的路由ID
4     priority 100              #优先级权限,一台100,另一台90即可
5     virtual_ipaddress{
6             192.168.10.181  #设置漂移的ip
7     }

3.生成停止mysql的脚本

vim /root/kill.sh
    #!/bin/bash
    service keepalived stop

4.service keepalived restart 

5.查看vip是否生成

ip a

备份主机的操作

1.可以拷贝master主机的配置文件到本地,也可以在本地直接配置

 1 scp 192.168.%:/etc/keepalived/keepalived.conf /etc/keepalived.conf 

2.编辑配置文件内部参数

1 vim /etc/keepalived/keepalived.conf
2         state  BACKUP
3         interface  eth0
4         priority  90  #优先级设置为比master稍微低点即可
5             real-server 192.168.189.%  3306

3.生成停止mysql的脚本

在root根目录下创建即可 vim /root/kill.sh

#!/bin/bash

service keepalived stop 

posted @ 2019-12-01 21:07  Security  阅读(146)  评论(0编辑  收藏  举报