keepalived热备份(双机热备)
主keepalived服务器:192.168.80.105
备keepalived服务器:192.168.80.104
在80.105做主服务器:
systemctl stop firewalld //关闭防火墙
setenforce 0 //关闭监控
yum install keepalived -y //keepalived软件安装
vi /etc/keepalived/keepalived.conf //进入keepalived服务主配置文件
删除所有内容,添加以下内容:
主负载均衡服务器配置
! Configuration File for keepalived
global_defs { //全局配置
router_id lb01 //调度器的名称
}
vrrp_instance VI_1 { //定义实例
state MASTER //状态参数
interface ens32 //虚拟IP地址放置的网卡位置
virtual_router_id 51 //集群id
priority 150 //优先级
advert_int 1 //主备通讯时间间隔
authentication { //认证设置
auth_type PASS //密码认证
auth_pass 1111
}
virtual_ipaddress { //虚拟IP地址
192.168.80.188
}
}
systemctl start keepalived //启动keepalived
systemctl status keepalived //查看keepalived状态
ip addr show ens32 //查看ens32网卡ip地址
cat /var/log/messages //查看日志
在80.104做备服务器
systemctl stop firewalld
setenforce 0
yum install keepalived -y //keepalived软件安装
vi /etc/keepalived/keepalived.conf //进入keepalived服务主配置文件
删除所有内容,添加以下内容:
备负载均衡服务器配置
! Configuration File for keepalived
global_defs { //全局配置
router_id lb02 //调度器的名称
}
vrrp_instance VI_1 { //定义实例
state BACKUP //状态参数
interface ens32 //虚拟IP地址放置的网卡位置
virtual_router_id 51 //集群id
priority 100 //优先级
advert_int 1 //主备通讯时间间隔
authentication { //认证设置
auth_type PASS //密码认证
auth_pass 1111
}
virtual_ipaddress { //虚拟IP地址
192.168.80.188
}
}
systemctl start keepalived //启动keepalived
ip addr show ens32 //查看ens32网卡ip地址
cat /var/log/messages //查看日志
把主服务器的虚拟机关闭:systemctl stop keepalived
在备服务器输入:ip addr show ens32 就能显示