CentOS7 keepalived 无法切换主从若干原因

Email: [email protected]

今天用keepalived 作高可用集群发现无法切换主从服务器,一下几点原因避免后来者踩坑。

(1)查看防火墙是否关闭,当防火墙开启且没有放行vrrp,从服务器接受不到主服务器的心跳,从服务器认为主服务器挂了,在抢占模式中,从服务器反客为主。此时用ifconfig或者ip addr list 查看发现主从服务器都配置了vip。

(2)vrrp_script配置错误,在CentOS7.4(我的测试版本)中配置

vrrp_script chk {
   script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"
   script "/etc/keepalived/keep_down.sh"
   interval 1
   weight -20
 }

以上配置在日志文件中会报“Unable to access script `[[`”的错误,新版本的不支持,解决方式如下:

主服务器配置:

! Configuration File for k

global_defs {
   notification_email {
     root@localhost
   }
   notification_email_from
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id  node1.yongge
   vrrp_skip_check_adv_add
   vrrp_strict
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_script chk {
#    script "[[ -f /etc/keepalived/down ]] && exit 1 || exit 0"  新版无效
   script "/etc/keepalived/keep_down.sh"
   interval 1
#   weight -20
}

vrrp_instance VI_1 {
    state MASTER
    interface enp0s3
    virtual_router_id 51
    priority 100
    adver_int 1
     authentication {
          auth_type PASS
          auth_pass 1111
      }
      virtual_ipaddress {
          192.168.0.80/16 dev enp0s3  label enp0s3:0
      }
      track_script {
        chk
      }
  
  }

keep_down.sh(注意给执行权限) 脚步内容如下

cat etc/keepalived/keep_down.sh
#!/bin/bash
if [ -f /etc/keepalived/down ];then
weight -2
fi
在/etc/keepalived目录下新建down文件,即可切换主从服务器

你可能感兴趣的:(CentOS7 keepalived 无法切换主从若干原因)