centos7安裝keepalived後,不關閉防火牆,虛拟ip不能實作漂移,雙機都為master,不能實作雙機熱備的效果。原因是防火牆中沒有方形vrrp的多點傳播 IP 244.0.0.18。centos7下使用的防火請是firewall,本人不會使用centos7預設的防火牆放行多點傳播IP,是以禁用掉centos7預設的防火牆,使用iptables防火牆。
1、關閉預設的firewall防火牆 #systemctl stop firewalld.service停止firewalld服務 #systemctl disable firewalld.service進制開機自啟動
2、開啟iptables
#yum install iptables(根據centOS7的版本和核心,有些版本已經裝過,可以跳過此指令)
#yum install iptables-services
3、編輯iptables檔案 #vim /etc/sysconfig/iptables 在檔案中添加一下内容 -A OUTPUT -o eno16777736 -d 224.0.0.18 -j ACCEPT 注解: eno16777736 是網卡名稱 -A OUTPUT -o eno16777736 -s 224.0.0.18 -j ACCEPT -A INPUT -i eno16777736 -d 224.0.0.18 -j ACCEPT -A INPUT -i eno16777736 -s 224.0.0.18 -j ACCEPT
4、開啟服務,設定開機自啟動
#service iptables restart
#chkconfig iptables on或者systemctl enable iptables.service開機自啟
此時就能實作虛拟ip的漂移,當master(keepalived)挂掉時,虛拟ip會漂移到backup(keepalived)上,master啟動後虛拟ip又飄逸回來。