部署架构
192.168.83.128 | master | nginx + keepalived |
192.168.83.129 | slave | nginx + keepalived |
192.168.83.130 | 虚ip | 当主机宕机后 ip 会自动漂移到slave |
安装
##两台机器都安装
yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel
yum install -y nginx
yum install -y keepalived
# 配置 keepalived
vi /etc/keepalived/keepalived.conf
###########################################
# 主机
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 LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
# 主机 MASTER 备机 BACKUP
state MASTER
# 网卡
interface ens33
# 主备机保持一致
virtual_router_id 60
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
# 虚拟ip
192.168.83.130/24
}
}
###########################################
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 LVS_DEVEL
vrrp_skip_check_adv_addr
vrrp_garp_interval 0
vrrp_gna_interval 0
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 60
# 备机 需要小于 主机的
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.83.130/24
}
}
# 启动主机
systemctl start keepalived
# 查看日志
tail -f -n 1000 /var/log/messages
# 查看是否绑定了虚拟ip
ip addr | grep 192.168.83.130
-----
# 停止 按照进程名称杀死进程 最有效果 用来修改配置文件
pkill keepalived
# 主机停止后 虚拟ip 会漂移到 备机 当主机恢复后自动漂移到主机
# 重启网络 之后 再重启 keepalived,否则失败
systemctl restart network.service