(4) 确保各节点的用于集群服务的接口支持MULTICAST通信;
ip link set multicast on interface
双主模型示例:
vim /etc/keepalived/keepalived.conf
节点一配置:
通过systemctl status keepalived.service查看结果
在各个节点上定义通知脚本,放在vrrp_instance中:
notify <STRING>|<QUOTED-STRING>:通用格式的通知触发机制,一个脚本可完成以上三种状态的转换时的通知;
通知脚本配置:
节点配置示例:
在配置文件中加入下图中的配置
………
配置示例:
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node1
vrrp_mcast_group4 224.0.100.19
}
vrrp_script chk_down {
script “[[ -f /etc/keepalived/down ]] && exit 1 || exit 0”
weight -10
interval 1
fall 1
rise 1
}
vrrp_script chk_ngx {
script ” killall -0 nginx && exit 0 || exit 1″
weight -10
interval 1
fall 1
rise 1
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass tEtMBpfA
}
virtual_ipaddress {
172.16.0.66/16 dev ens33 label ens33:0
}
track_script {
chk_down
chk_nginx
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
vrrp_instance VI_2 {
state BACKUP
interface ens33
virtual_router_id 41
priority 96
advert_int 1
authentication {
auth_type PASS
auth_pass d/aiJhXT
}
virtual_ipaddress {
172.16.0.67/16 dev ens33 label ens33:1
}
}
track_script {
chk_down
chk_nginx
}
notify_master “/etc/keepalived/notify.sh master”
notify_backup “/etc/keepalived/notify.sh backup”
notify_fault “/etc/keepalived/notify.sh fault”
}
原创文章,作者:Immortals、zcy,如若转载,请注明出处:http://www.178linux.com/79409