centos7下解决keepalived双机都为master问题

来源:互联网 发布:摇奖转盘软件 编辑:程序博客网 时间:2024/06/06 09:49

       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又飘逸回来。

1 0
原创粉丝点击