环境说明
Centos 7版本
主机名 | IP地址 | 其他 |
nginx | 192.168.10.150 | 主 |
nginx-2 | 192.168.10.151 | 备 |
配置
-
主-192.168.10.150
[root@nginx ~]# yum install keepalived
[root@nginx ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
#定义全局参数
global_defs {
#当前机器ID
router_id LVS_1
}
#定义vrrp实例
vrrp_instance VI_1 {
#当前身份为主
state MASTER
#网络接口
interface ens33
#虚拟路由器ID
virtual_router_id 51
#优先级
priority 100
#vrrp通告时间间隔
advert_int 1
#定义认证参数
authentication {
#认证类型为密码
auth_type PASS
#认证密码
auth_pass 1111
}
#定义虚拟IP地址,可多个
virtual_ipaddress {
#虚拟IP地址
192.168.10.200
}
}
[root@nginx ~]# systemctl restart keepalived
-
备-192.168.10.151
[root@nginx-2 ~]# yum install keepalived -y
[root@nginx-2 ~]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
#ID需与主不一致
router_id LVS_2
}
vrrp_instance VI_1 {
#身份为备
state BACKUP
interface ens33
virtual_router_id 51
#优先级比主低
priority 80
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.10.200
}
}
[root@nginx-2 ~]# systemctl restart keepalived
验证
#在主上查看vip地址
#在备上查看VIP地址
#访问VIP地址中途,在主上关机输入poweroff,模拟宕机,结果如下
完成!