在keepalived的VRRP实例配置中会一般会设置Master和Backup来指定初始状态,但是这并不意味着此节点一直就是Master角色。控制节点角色的是Keepalived配置文件中的“priority”值和vrrp_script模块中设置的“weight”值。下面分别分情况对主备机切换机制作详细说明。
配置简介:
主机 |
IP |
操作系统 |
软件 |
VIP |
备注 |
nginx01 |
172.27.9.91 |
Centos7.3.1611 | keepalived nginx |
172.27.9.200 |
关闭防火墙和selinux,nginx端口为82 |
nginx02 |
172.27.9.92 |
Centos7.3.1611 | keepalived nginx |
172.27.9.200 |
关闭防火墙和selinux,nginx端口为82 |
初始nginx01中keepalived配置:
[root@nginx01 keepalived]# more keepalived.conf ! 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 proxy1 } vrrp_script chk_nginx { script "/etc/keepalived/test.sh" interval 2 #健康检查周期 weight 20 #优先级变化幅度 fall 3 #判定服务异常的检查次数 rise 2 #判定服务正常的检查次数 } vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virt