vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
# notification_email {
# lipengfei@topnet.net.cn
# }
# notification_email_from lipengfei@topnet.net.cn
# smtp_server smtp.exmail.qq.com
# smtp_connect_timeout 30
router_id master
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}
vrrp_script chk_mysql { #定义脚本并设置规则
script "</dev/tcp/127.0.0.1/3306"
interval 1
weight -2
fall 3
rise 5
timeout 5
}
vrrp_instance VI_1 {
state MASTER
interface ens192
virtual_router_id 51
priority 100
# nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.247
}
# 单播模式,需事先关闭全局 vrrp_strict 选项,否则报错
unicast_src_ip 192.168.3.211 # 本机IP
unicast_peer {
192.168.3.212 # 其他keepalived主机IP
}
track_script {
chk_mysql
}
notify_master /etc/keepalived/sendmail.sh
}
#vrrp_script check_apiserver {
# script "/etc/keepalived/check-apiserver.sh"
# interval 3
# weight -2
#}
#vrrp_instance VI-kube-master {
# state MASTER
# interface ens192
# virtual_router_id 68
# priority 100
# dont_track_primary
# advert_int 3
# virtual_ipaddress {
# 192.168.3.250
# }
# track_script {
# check_apiserver
# }
#}
来源:oschina
链接:https://my.oschina.net/internetafei/blog/4294321