Master配置文件  注意iptables防火墙(见上个随笔)和健康检查脚本

keepalived 只是高可用,如果keepalived宕机后,ip会飘到备份主机,但是如果nginx掉了,keepalived是不会stop掉的,所以需要脚本做健康检查,代码如下:

! Configuration File for keepalived

global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}

notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id web1
}

vrrp_script check_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight -5
fall 2
rise 1
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.120
}

track_script {
check_nginx
}
}

# virtual_router_id 51必须一致

脚本代码

#!/bin/bash
  A=$(ss -aunpt | grep nginx | wc -l)
        if [ $A -eq 0 ] ; then
              /usr/bin/kill -15 `cat /var/run/keepalived.pid`
              echo -e "keeplived is stoped"
        else
            exit 0
        fi

##注意脚本要加执行权限+x  vrrp_script 


 

注意关闭的keepalived关闭后,要起来,需要先启nginx,然后启keepalived

由于本人只有两台高可用,就不写备份机的代码和脚本了。

 

相关文章:

  • 2022-01-18
  • 2021-12-13
  • 2021-10-19
  • 2021-06-24
  • 2021-11-09
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-15
  • 2021-05-06
  • 2021-10-19
  • 2021-06-12
  • 2021-05-09
  • 2022-02-17
  • 2021-10-24
相关资源
相似解决方案