November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Nginx load balancing servers are available for dual machines

If the Web server cluster as a city, then the load balancing server is equivalent to the gates, the importance of self-evident.If the “gates” off, and the outside world is broken, if only a balanced server , When the server fails, it will lead to the entire site can not access.Therefore, we need to more than two servers, to achieve a high transition and high availability.

Dual high availability is generally achieved through the virtual IP (drift IP) method, based on Linux / Unix IP alias technology. Dual high-availability method is divided into two types:

(1): a server plus a hot by the server, under normal circumstances, the main server binding a public network virtual IP, to provide load balancing services, hot standby server is idle, when the main server failure, hot standby The server takes over the public network virtual IP of the main server and provides the load balancing service;

(2): two load balancing servers are active, each binding a public network virtual IP, to provide load balancing services, when one of the failure, the other to take over the failure of the public network virtual server IP.
?1?rmohan.com IP 61.1.1.2
?2?61.1.1.4 IP 61.1.1.2

/sbin/ifconfig eth0:1 61.1.1.2 broadcast 61.1.1.255 netmask 255.255.255.0 up
/sbin/route add -host 61.1.1.2 dev eth0:1
/sbin/arping -I eth0 -c 61.1.1.2 61.1.1.1
(3) rmohan.com?IP? 61.1.1.2? 61.1.1.4? 61.1.1.5
?4? 61.1.1.4 61.1.1.5 IP 61.1.1.2?ping MAC?

/sbin/ifconfig etho:1 61.1.1.2 broadcast 61.1.1.255 netmask 255.255.255.0 up
/sbin/ifconfig add -host 61.1.1.2 dev eth0:1
/sbin/arping -I etho -c 3 -s 61.1.1.2 61.1.1.1
(5) rmohan.com(IP) 61.1.1.1?

VRRP Keepalive ?
?1??rmohan.com DNS IP 61.1.1.2 61.1.1.3
?2? IP? 61.1.1.4
/sbin/ifconfig etho:1 61.1.1.2 broadcast 61.1.1.255 netmask 255.255.255.0 up
/sbin/ifconfig add -host 61.1.1.2 dev eth0:1
/sbin/arping -I etho -c 3 -s 61.1.1.2 61.1.1.1 61.1.1.5
/sbin/ifconfig etho:1 61.1.1.3 broadcast 61.1.1.255 netmask 255.255.255.0 up
/sbin/ifconfig add -host 61.1.1.2 dev eth0:1
/sbin/arping -I etho -c 3 -s 61.1.1.3 61.1.1.1
(3) www,linuxidc.com IP 61.1.1.2 61.1.1.3? DNS
(4)IP 61.1.1.2?ARPing IDC MAC ?
/sbin/ifconfig etho:1 61.1.1.2 broadcast 61.1.1.255 netmask 255.255.255.0 up
/sbin/ifconfig add -host 61.1.1.2 dev eth0:1
/sbin/arping -I etho -c 3 -s 61.1.1.2 61.1.1.1

Nginx?

#!/bin/sh
LANG=C
date=$(date -d “today” +”%Y-%m-%d %H?%M:%S”)

function_bind_vip1()
{
/sbin/ifconfig etho:ha1 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:hal
}
function_bind_vip2()
{

/sbin/ifconfig etho:ha2 61.1.1.3 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.2 broadcast 219.232.254.255 netamsk 255.255.255.192 down
}

function_remove_vip2()
{
/sbin/ifconfig etho:ha2 61.1.1.3 broadcast 219.232.254.255 netamsk 255.255.255.192 down
}
function_vip_arping1()
{
/sbin/ifconfig -I eth0 -c 3 -e 611..1.1.2 61.1.1.1 > /dev/null 2>&1
}
function_vip_arping2()
{
/sbin/ifconfig -I eth0 -c 3 -e 611..1.1.3 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} http://61.1.1.4′
httpcode_arp2=’/usr/bin/cur1 -o /dev/null s -w %{http_code} http://61.1.1.5′

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
nohup /bin/sh ./nginx_hal.sh 2>&1 > dev/null &
#!/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} http://61.1.1.5′
httpcode_arp2=’/usr/bin/cur1 -o /dev/null s -w %{http_code} http://61.1.1.4′

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

nohup /bin/sh ./nginx_ha2.sh 2>&1 > dev/null &

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>