centos部署keepalived集群
1、yum安装keepalived
sudo yum install keepalived
2、编辑配置文件
global_defs {
notification_email {
user@example.com
}
notification_email_from mail@example.org
smtp_server 192.168.x.x
smtp_connect_timeout 30
router_id LVS_MASTER # 每个节点名称要唯一
}
#监测haproxy进程状态,每2秒执行一次
vrrp_script chk_haproxy {
script "/bin/bash -c 'if [[ $(netstat -nlp | grep 16443) ]]; then exit 0; else exit 1; fi'"
interval 2
weight 2
}
vrrp_instance VI_1 {
state MASTER #标示状态为MASTER
interface enp0s3
virtual_router_id 51
priority 101 #MASTER权重要高于BACKUP
advert_int 1
#mcast_src_ip 192.168.0.183 #Master服务器IP
unicast_src_ip 192.168.0.183 #当前机器地址
unicast_peer {
192.168.0.228 #peer中其它地址
192.168.0.169 #peer中其它地址
}
authentication {
auth_type PASS #主从服务器验证方式
auth_pass 1111
}
track_script {
chk_haproxy #监测haproxy进程状态
}
#VIP
virtual_ipaddress {
192.168.0.200 #虚拟IP
}
}
3、如出以下错误
执行命令
/sbin/restorecon -v /etc/keepalived/keepalived.conf
4、再次启动
sudo systemctl start keepalived
5、设置开机自启动
sudo systemctl enable keepalived