use mysql; change master to master_host='<mariadb2>', master_user='mysync', master_password='123456', master_log_file='<mariadb2_file>', master_log_pos=<mariadb2_pos>; start slave;
1 2 3 4 5 6 7 8
use mysql; change master to master_host='<mariadb1>', master_user='mysync', master_password='123456', master_log_file='<mariadb1_file>', master_log_pos=<mariadb1_pos>; start slave;
注:master_log_pos 和 master_log_file 要从主机的数据状态当中获得。
状态检查
1
show slave status;
如果观察到如下内容则代表配置正常。
1 2
Slave_IO_Running: Yes Slave_SQL_Running: Yes
Keepalived
安装软件
1
yum -y install keepalived
编写检测脚本(所有设备)
1
vim /etc/keepalived/check_mysql.sh
1 2 3 4 5 6 7 8 9 10 11
#!/bin/bash
MYSQL_PING=`mysqladmin 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
1
chmod +x /etc/keepalived/check_mysql.sh
获取网卡信息
1
nmcli connection show
注:获取到的网卡名需要填入下一步的配置文件中,两台设备都记得要检查
配置 Keepalived 服务 (主要节点)
注:配置中的 interface 要指定当前的网卡,并且需要根据设备优先级设定 priority,且虚拟 IP 地址要与目前 IP 不冲突。
1 2
mv /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bk vim /etc/keepalived/keepalived.conf