Keepalive双主搭建配置
Posted 厚积薄发
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Keepalive双主搭建配置相关的知识,希望对你有一定的参考价值。
Keepalive 双主搭建配置
keepalived保证双主数据库的可用性
环境说明
192.168.1.10 keepalive 主1
192.168.1.20 keepalive 主2
192.168.1.111 keepalive 主1 从2 VIP
192.168.1.222 keepalive 从1 主2 VIP
1、官网下载最新版本
keepalived-1.2.19
2、部署安装
yum install gcc gcc-c++ make openssl openssl-devel tar zxvf keepalived-1.2.19.tar.gz cd keepalived-1.2.19 ./configure --sysconf=/etc/ --with-kernel-dir=/usr/src/linux --prefix=/usr/local/keepalived make ; make install cp /usr/local/keepalive/sbin/keepalived /usr/bin/ cp /usr/local/keepalived/sbin/keepalived /usr/bin/ cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/ chkconfig keepalived on
3、建立配置文件
vim /etc/keepalived/keepalived.conf global_defs { notification_email { cwliu@atman.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id Mariadb_keepalive1 } vrrp_script notification { script "/data/ops/script/mail.sh" interval 1 weight 2 } vrrp_script check_alive { script "/data/ops/script/mysql_check.sh" interval 1 weight 2 } vrrp_instance Mariadb_keepalive_channel1 { state MASTER interface eth0 virtual_router_id 100 priority 200 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.111 } track_script { check_alive } } vrrp_instance Mariadb_keepalive_channel2 { state BACKUP interface eth0 virtual_router_id 101 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.222 } track_script { check_alive } }
4、然后启动即可
/etc/init.d/keepalived start
5、Keepalive 另一主服务器除配置文件不一样,其他配置步骤如上,配置文件如下
vim /etc/keepalived/keepalived.conf global_defs { notification_email { cwliu@atman.com } notification_email_from root@localhost smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id Mariadb_keepalive } vrrp_script notification { script "/data/ops/script/mail.sh" interval 1 weight 2 } vrrp_script check_alive { script "/data/ops/script/mysql_check.sh" interval 1 weight 2 } vrrp_instance Mariadb_keepalive_channel1 { state BACKUP interface eth0 virtual_router_id 100 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.111 } track_script { check_alive } } vrrp_instance Mariadb_keepalive_channel2 { state MASTER interface eth0 virtual_router_id 101 priority 200 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.1.222 } track_script { check_alive } }
6、效果图
两台同时运行:
192.168.1.10:
192.168.1.20
192.168.1.10 keepalive 关闭后:
以上是关于Keepalive双主搭建配置的主要内容,如果未能解决你的问题,请参考以下文章