MySQL + Keepalived 双主热备搭建(11)

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft foreverinet6 ::1/128 scope host valid_lft forever preferred_lft forever2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP qlen 1000link/ether 00:50:56:8b:71:df brd ff:ff:ff:ff:ff:ffinet 192.168.1.37/24 brd 192.168.1.255 scope global ens192#虚拟 IPvalid_lft forever preferred_lft foreverinet 192.168.1.38/24 scope global secondary ens192valid_lft forever preferred_lft foreverinet6 fe80::2556:f369:b4e7:fb64/64 scope link tentative dadfailed valid_lft forever preferred_lft foreverinet6 fe80::6b8d:29f7:a5fe:dbee/64 scope link tentative dadfailed valid_lft forever preferred_lft foreverinet6 fe80::f387:57a3:4975:d8f2/64 scope link tentative dadfailed valid_lft forever preferred_lft forever
复制代码 
客户端发生了重连,通过 select @@hostname 查看可以看到此时连接的是主库 B 。
 
root@192.168.1.38 (none) 09:42:14>select @@hostname;#重连ERROR 2006 (HY000): MySQL server has gone awayNo connection. Trying to reconnect...Connection id:19Current database: *** NONE ***+-------------+| @@hostname|+-------------+| mysql-slave |+-------------+1 row in set (0.04 sec)
复制代码 
客户端插入几条数据:
 
insert into testdb.data01 (name,age) values('peter',28),('mark',27),('marry',26),('hule',25),('handson',20);
复制代码 
查询数据,可以看到在原主库 B 上插入的数据主键会以 10,12,14,16,18 的序号递增 。
 
root@192.168.1.38 (none) 09:44:19>select * from testdb.data01;+----+---------+------+| id | name| age|+----+---------+------+|1 | tom|18 ||3 | jack|17 ||5 | rock|16 ||7 | james|15 ||9 | cris|20 || 10 | peter|28 || 12 | mark|27 || 14 | marry|26 || 16 | hule|25 || 18 | handson |20 |+----+---------+------+10 rows in set (0.01 sec)
复制代码重新启动主库 A,观察数据同步由于我们关闭了抢占模式,当主库 A 重新启动时,主从不会发送切换 。
 
[root@mysql-master]# systemctl start mysql_3308.service
复制代码 
主库 A 的数据可以和主库 B 同步 。
 

MySQL + Keepalived 双主热备搭建

文章插图
参考资料
  • https://www.cnblogs.com/kerrycode/p/11150782.html
  • http://www.linuxe.cn/post-492.html
  • https://blog.csdn.net/JesseYoung/article/details/41942809




推荐阅读