概述:keepalived是一个非常灵活的高可用解决方案,因其对端口检测的特性,让他基本可以完成基本所有服务的高可用,但就是因为灵活导致你自己需要配置的就非常多,最主要的地方就是针对不同的地方自己编写不同的脚本。
集群拓扑:
mysql版本:Ver 14.14 Distrib 5.7.11
keepalived版本:Keepalived v1.2.24 (03/30,2017)
集群描述:
该集群主要为mysql集群,与一般不同的是,本集群可以进行mysql主从的自动切换,当mysql1服务down掉后,切换根据优先级切换到2为主,而且将keepalived设置成非抢占模式(就是keepalived全部为BACKUP)。
一mysql主从配置
mysql1配置:
/etc/my.cnf
[mysqld]
binlog-do-db=test
log-bin=mysql-bin
server-id=1
gtid-mode=ON
enforce-gtid-consistency
mysql2
[mysqld]
socket=/usr/local/lnmp/mysql/data/mysql.sock
gtid-mode=ON
enforce-gtid-consistency
log-bin=mysql-bin
log-slave-updates=ON
server-id=2
mysql3
[mysqld]
gtid-mode=ON
enforce-gtid-consistency
socket=/usr/local/lnmp/mysql/data/mysql.sock
log-bin=mysql-bin
log-slave-updates=ON
server-id=3
binlog-do-db=test
keepalived配置
mysql1上keepalived配置
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@master.mo.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
sta