安装约定
KEEPALIVED-VIP:192.168.1.4
MYSQL_MASTER-1:192.168.1.20
MYSQL_MASTER-2:192.168.1.21
在MYSQL_MASTER-1服务器上配置keepalived.conf
# vim /etc/keepalived/keepalived.conf
添加如下内容
! Configuration File for keepalived global_defs { notification_email { example@163.com #failover@firewall.loc #sysadmin@firewall.loc } notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_MASTER } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 100 advert_int 1 nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.4 } }
在MYSQL_MASTER-2服务器上配置keepalived.conf
# vim /etc/keepalived/keepalived.conf
添加如下内容
! Configuration File for keepalived global_defs { notification_email { example@163.com #failover@firewall.loc #sysadmin@firewall.loc } notification_email_from keepalived@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_BACKUP } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 51 priority 99 advert_int 1 #nopreempt authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.4 } }
此架构可以做到只有一台主服务器进行写操作,确保数据一致性,又能做到高可用。