keepalived 安装及配置VIP漂移
Posted maoxianfei
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived 安装及配置VIP漂移相关的知识,希望对你有一定的参考价值。
环境:
主机 10.10.6.105
备机 10.10.6.106
VIP 10.10.6.188
一、安装
yum install keepalived -y
二、配置文件(/etc/keepalived/keepalived.conf)
主机配置
global_defs { notification_email { [email protected] [email protected] [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL vrrp_skip_check_adv_addr
#注释下行否则ping 不通 #vrrp_strict vrrp_garp_interval 0 vrrp_gna_interval 0 } #脚本监控 vrrp_script chk_mysql { script "/etc/keepalived/check_mysql.sh" interval 2 weight 2 } vrrp_instance VI_1 { #主机设置master
state MASTER
#监听网卡设置 interface ens32 #虚拟路由ID 保持主从配置相同
virtual_router_id 51
#权重主的大于从的 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 }
#引用脚本 track_script { chk_mysql }
#虚拟IP设置 virtual_ipaddress { 10.10.6.188 } }
从机配置与主机大致相同
#vrrp_strict state BACKUP priority 90
监控脚本(/etc/keepalived/check_mysql.sh )
#scripts is check for Mysql Slave status counter=$(netstat -na|grep "LISTEN"|grep "8080"|wc -l) if [ "${counter}" -eq 0 ]; then echo ‘not found‘ else echo ‘pass‘ fi
三、测试
日志查看
tail -f /var/log/messages
两台机器,启动端口
nc -vl 8080
两台机器,启动服务
service keepalived start
关闭主机8080端口后日志
Nov 7 05:28:17 localhost Keepalived[47369]: Stopping
Nov 7 05:28:17 localhost systemd: Stopping LVS and VRRP High Availability Monitor...
Nov 7 05:28:17 localhost Keepalived_vrrp[47371]: VRRP_Instance(VI_1) sent 0 priority
Nov 7 05:28:17 localhost Keepalived_vrrp[47371]: VRRP_Instance(VI_1) removing protocol VIPs.
Nov 7 05:28:17 localhost Keepalived_healthcheckers[47370]: Stopped
Nov 7 05:28:18 localhost Keepalived_vrrp[47371]: Stopped
Nov 7 05:28:18 localhost Keepalived[47369]: Stopped Keepalived v1.3.5 (03/19,2017), git commit v1.3.5-6-g6fa32f2
Nov 7 05:28:18 localhost systemd: Stopped LVS and VRRP High Availability Monitor.
查看从机已经转移VIP
[[email protected] keepalived]# ip a|grep 188
inet 10.10.6.188/32 scope global ens32
漂移过程中无任何延迟问题,ping 返回正常,重启服务后vip 又返回主机
以上是关于keepalived 安装及配置VIP漂移的主要内容,如果未能解决你的问题,请参考以下文章
Redis 主从 keepalived高可用 实现 VIP 自动漂移