if [x$httpcode_arp2 == "x200"];
then
if[ $bind_time_vip2 == "Y"]
then
function_rempve_vip2
bind_time_vip2="N"
fi
else
if[$bind_time_vip2 == "N"];
then
function_bind_vip2
function_vip_arping2
function_restart_nginx
bind_time_vip2="Y"
fi
function_vip_arping2
fi
sleep 5
done
在Nginx服务器1将脚本驻留后台运行:
nohup /bin/sh ./nginx_hal.sh 2>&1 > dev/null &
以下代码部署在服务器2:
#!/bin/sh
LANG=C
date=$(date -d "today" +"%Y-%m-%d %H:%M:%S")
function_bind_vip1()
{
/sbin/ifconfig etho:ha1 61.1.1.3 broadcast 219.232.254.255 netmask 255.255.255.192 up
/sbin/route add -host 61.1.1.3 dev eth0:hal
}
function_bind_vip2()
{
/sbin/ifconfig etho:ha2 61.1.1.2 broadcast 219.232.254.255 netmask 255.255.255.192 up
/sbin/route add -host 61.1.1.2 dev eth0:ha2
}
function_restart_nginx()
{
kill -USR1 'cat /usr/local/webserver/nginx/nginx.pid'
}
function_remove_vip1()
{
/sbin/ifconfig etho:ha1 61.1.1.3 broadcast 219.232.254.255 netamsk 255.255.255.192 down
}
function_remove_vip2()
{
/sbin/ifconfig etho:ha2 61.1.1.2 broadcast 219.232.254.255 netamsk 255.255.255.192 down
}
function_vip_arping1()
{
/sbin/ifconfig -I eth0 -c 3 -e 61.1.1.3 61.1.1.1 > /dev/null 2>&1
}
function_vip_arping2()
{
/sbin/ifconfig -I eth0 -c 3 -e 61.1.1.2 61.1.1.1 > /dev/null 2>&1
}
bind_time_vip1="N";
bind_time_vip2="N";
while true
do
httpcode_arp1='/usr/bin/cur1 -o /dev/null s -w %{http_code} '
httpcode_arp2='/usr/bin/cur1 -o /dev/null s -w %{http_code} '
if [x$httpcode_rip1 == "x200"];
then
function_bind_vip1
function_vip_arping1
function_restart_nginx
bind_time_vip1="Y"
fi
function_vip_arping1
else
if [$bind_time_vip1 == "Y"];
then
function_remote_vip1
bind_time_vip="N"
fi
fi
if [x$httpcode_arp2 == "x200"];
then
if[ $bind_time_vip2 == "Y"]
then
function_rempve_vip2
bind_time_vip2="N"
fi
else
if [$bind_time_vip2 == "N"];
then
function_bind_vip2
function_vip_arping2
function_restart_nginx
bind_time_vip2="Y"
fi
function_vip_arping2
fi
sleep 5
done
在Nginx服务器2将脚本驻留后台运行:
nohup /bin/sh ./nginx_ha2.sh 2>&1 > dev/null &
更多Nginx相关教程见以下内容:
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程
CentOS 6.3下配置Nginx加载ngx_pagespeed模块