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? # 每個節(jié)點名稱要唯一
}
#監(jiān)測haproxy進程狀態(tài),每2秒執(zhí)行一次
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 #標示狀態(tài)為MASTER
? ? interface enp0s3
? ? virtual_router_id 51
? ? priority 101? #MASTER權(quán)重要高于BACKUP
? ? advert_int 1
? ? #mcast_src_ip 192.168.0.183 #Master服務(wù)器IP
? ? unicast_src_ip 192.168.0.183? #當前機器地址
? ? unicast_peer {
? ? ? 192.168.0.228? ? ? ? ? ? ? #peer中其它地址
? ? ? 192.168.0.169? ? ? ? ? ? ? #peer中其它地址
? ? }
? ? authentication {
? ? ? ? auth_type PASS #主從服務(wù)器驗證方式
? ? ? ? auth_pass 1111
? ? }
? ? track_script {
? ? ? ? chk_haproxy #監(jiān)測haproxy進程狀態(tài)
? ? }
? ? #VIP
? ? virtual_ipaddress {
? ? ? ? 192.168.0.200 #虛擬IP
? ? }
}
3拧篮、如出以下錯誤
執(zhí)行命令
/sbin/restorecon -v /etc/keepalived/keepalived.conf
4蠢壹、再次啟動
sudo?systemctl start keepalived
5区匠、設(shè)置開機自啟動
sudo systemctl enable keepalived