keepalived多实例高可用配置
Posted 我是一只小小茑
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了keepalived多实例高可用配置相关的知识,希望对你有一定的参考价值。
keepalived多实例高可用配置
一 master节点配置
[root@node2 html]# cat /etc/keepalived/keepalived.conf (master节点)
global_defs notification_email acassen@firewall.loc
notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id node2 #实例一,tomcat vrrp_script chk_tomcat script "/home/check_tomcat.sh" interval 2 weight -20
# script:自己写的监测脚本。 # interval 2:每2s监测一次 # weight -20:根据脚本返回值判断,0为成功,不做任何动作,1为失败,监测失败,则相应的vrrp_instance的优先级会减少20个点 vrrp_instance VI_1 state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication auth_type PASS auth_pass 1111
# state:只有BACKUP和MASTER。MASTER为工作状态,BACKUP是备用状态 # interface:为网卡接口:可通过ip addr查看自己的网卡接口 # virtual_router_id:虚拟路由标志。同组的virtual_router_id应该保持一致。它将决定多播的MAC地址。 # priority:设置本节点的优先级,优先级高的为master # advert_int:MASTER与BACKUP同步检查的时间间隔 virtual_ipaddress 192.168.2.182/24 brd 192.168.2.182 dev ens33 label ens33:0
#virtual_ipaddress:这就是传说中的虚拟ip #要和上面定义的名字一致 track_script chk_tomcat #实例二,apache vrrp_script chk_apache script "/home/check_apache.sh" interval 2 weight -20
vrrp_instance VI_2 state MASTER interface ens33 virtual_router_id 52 priority 100 advert_int 1 authentication auth_type PASS auth_pass 1111
virtual_ipaddress 192.168.2.183/24 brd 192.168.2.183 dev ens33 label ens33:1
track_script chk_apache |
二 backup节点配置
[root@node3 ~]# cat /etc/keepalived/keepalived.conf (BACKUP节点)
global_defs notification_email acassen@firewall.loc
notification_email_from Alexandre.Cassen@firewall.loc smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id node3 vrrp_script chk_tomcat script "/home/check_tomcat.sh" interval 2 weight -20
vrrp_instance VI_1 state BACKUP interface ens33 virtual_router_id 51 priority 99 advert_int 1 authentication auth_type PASS auth_pass 1111
virtual_ipaddress 192.168.2.182/24 brd 192.168.2.182 dev ens33 label ens33:0
track_script chk_tomcat vrrp_script chk_apache script "/home/check_apache.sh" interval 2 weight -20
vrrp_instance VI_2 state BACKUP interface ens33 virtual_router_id 52 priority 99 advert_int 1 authentication auth_type PASS auth_pass 1111
virtual_ipaddress 192.168.2.183/24 brd 192.168.2.183 dev ens33 label ens33:1
track_script chk_apache |
三 检测脚本
[root@node3 ~]# cat
/home/check_HA.sh
#!/bin/bash A=`ps -ef | grep tomcat | grep -v grep | wc -l` if [ $A -eq 0 ];then exit 1 else exit 0 fi |
[root@node3 ~]# cat
/home/check_apache.sh
#!/bin/bash A=`ps -C httpd --no-header | wc -l` if [ $A -eq 0 ];then exit 1 else exit 0 fi |
四 测试
其他应用故障同理,keepalived多实例测试成功
以上是关于keepalived多实例高可用配置的主要内容,如果未能解决你的问题,请参考以下文章