前期准备2台机器,分别先安装nginx, 再操作下面
# 下载keepalived
yum install keepalived -y
# 进入目录修改文件名
cd /etc/keepalived
mv keepalived.conf keepalived.conf.bak
# 配置文件内容
vi 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.5.147
smtp_connect_timeout 30
router_id LVS_DEVEL # 访问的主机地址
}
vrrp_script chk_nginx {
script "/usr/local/src/nginx_check.sh" # 检测文件的地址
interval 2 # 检测脚本执行的间隔
weight 2 # 权重
}
vrrp_instance VI_1 {
state BACKUP # 主机MASTER、备机BACKUP
interface ens33 # 网卡
virtual_router_id 51 # 同一组需一致
priority 90 # 访问优先级,主机值较大,备机较小
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.5.50 # 虚拟ip
}
}
# 配置host文件
vi /etc/hosts
smtp_server 192.168.5.147
备注:2台机器都要如上配置