分別在兩臺服務器上安裝vim
yum install keepliaved -y服務器
配置文件 spa
vim /etc/keepalived/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 keep01 #每一個配置文件,該值都要不一樣
vrrp_mcast_group 224.0.0.19 #指定多播地址的配置,指定該地址防止同個局域網內多個keepalived服務器VRRP協議多播地址衝突
}
vrrp_instance VI_1 {
state MASTER #備爲BACKUP
interface eth0
virtual_router_id 151 #主備相同
priority 200 #主比備大50以上
advert_int 1 #響應秒數
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #虛擬IP地址
192.168.0.39/24 dev eth0 label eth0:1
}
}
啓動keeplaived 在主服務器上 rest
ip addr日誌
eth0 後會出現 192.168.0.39 地址router
備服務器不會有,在主服務器down後,會在備服務器出現server
分離出keepalived日誌ip
vim /etc/sysconfig/keepalivedci
# --vrrp -P Only run with VRRP subsystem.
# --check -C Only run with Health-checker subsystem.
# --dont-release-vrrp -V Dont remove VRRP VIPs & VROUTEs on daemon stop.
# --dont-release-ipvs -I Dont remove IPVS topology on daemon stop.
# --dump-conf -d Dump the configuration data. 導出備份配置數據
# --log-detail -D Detailed log messages. #詳細日誌
# --log-facility -S 0-7 Set local syslog facility (default=LOG_DAEMON)
# -S 0 做用是指定爲local0設備
KEEPALIVED_OPTIONS="-D -d -S 0"
#vim /etc/rsyslog.confrem
在結尾添加
#keepalived
local0.* /var/log/keepalived.log
在42行左右添加;local0.none
*.info;mail.none;authpriv.none;cron.none;local0.none /var/log/messages
重啓rsyslog
/etc/init.d/rsyslog restart
tail /var/log/keepalived.log