1. 高可用
2. 修改 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.18.100
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_nginx
{
script
"/home/eric/file/nginx_check.sh"
interval 2
weight -20
}
vrrp_instance VI_1
{
state MASTER
interface ens33
virtual_router_id 50
mcast_src_ip 192.168.18.100
priority 100
nopreempt
advert_int 1
authentication
{
auth_type PASS
auth_pass 1111
}
track_script
{
chk_nginx
}
virtual_ipaddress
{
192.168.18.50
}
}
3. 添加 nginx_check.sh 检测脚本
作用:如果nginx没有启动,则启动nginx ,如果启动不成功,则杀掉keepalived
#!/bin/bash
A
=`ps -C nginx –no-header |wc -l`
if [ $A -eq 0
];then
/home/eric/nginx/sbin/nginx
sleep 2
if [ `ps -C nginx --no-header |wc -l` -eq 0
];then
killall keepalived
fi
fi
4. 启动 nginx 和 keepalived
./nginx
./keepalived -f /home/eric/keepalived/etc/keepalived/keepalived.conf
5. 测试,当一台nginx 挂掉, 依然能正常访问
http://192.168.18.50:9000/1.html