Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Test of automatic switching Scheme for disaster recovery of Web Server

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

With the growth of the XX service of our website, we need to configure cross-IDC disaster recovery, in order to deal with emergencies and avoid affecting the normal access of the website.

I read a lot of processing methods on the Internet, and combined with my own actual situation, I also practiced it on the test server of the local area network.

The test results are good. Now organize my deployment in the local area network as follows:

Train of thought:

When server A fails, server B can quickly take over the task of server A without affecting the normal access of users.

When server A recovers, server A can immediately take over the task of server B, and server B returns to standby state.

Practice:

A virtual IP address is configured on the two servers. The master server binds the virtual ip address first, and when a failure occurs, the standby computer automatically takes over the virtual ip address.

Refresh the gateway routing address. When the host is restored, the standby releases the virtual ip address, and the host takes over the virtual ip address actively again, refreshing the gateway routing address.

Structure diagram:

Master server: ip 192.168.190.199

Standby server: ip 192.168.190.208

Vip:192.168.190.88

GateWay=192.168.190.254

NetMask=255.255.255.0

Bcast=192.168.190.255

Steps:

1. Configure virtual ip:192.168.190.88 to www.test.com bind virtual ip

/ sbin/ifconfig eth0:1 192.168.190.88 broadcast 192.168.190.255

Netmask 255.255.255.0 up

/ sbin/route add-host 192.168.190.88 dev eth0:1

2. Refresh gateway routing

/ sbin/arping-I eth0-s 192.168.190.88 192.168.190.254 > / dev/null 2 > & 1

3. When a failure occurs, the host 192.168.190.199 releases the virtual ip192.168.190.88, and the standby machine 192.168.190.208 takes over the virtual ip192.168.190.88

/ sbin/ifconfig eth0:1 192.168.190.88 broadcast 192.168.190.255 netmask 255.255.255.0 down

/ sbin/arping-I eth0-s 192.168.190.88 192.168.190.254 > / dev/null 2 > & 1

4. At this time, www.test.com resolves to the standby server 192.168.190.208

5. Restart the standby web server

6. If the host 192.168.190.199 service returns to normal, the standby 192.168.190.208

Release virtual IP, host, bind virtual IP 192.168.190.88 standby to release virtual ip:

/ sbin/ifconfig eth0:1 192.168.190.88 broadcast 192.168.190.255 netmask 255.255.255.0 down

/ sbin/arping-I eth0-s 192.168.190.88 192.168.190.254 > / dev/null 2 > & 1

7. Restart the web service for the master and slave

Host 192.168.190.199

AutoSwitchMain.sh switching script

#! / bin/sh

# # #

# desc: automatically switch services when the server is down

# author:gaozhonghui

# mail:toptreegzh@163.com

# date:20121101

# # #

Vip=192.168.190.88

GateWay=192.168.190.254

NetMask=255.255.255.0

Bcast=192.168.190.255

Function_bind_vip1 () {

/ sbin/ifconfig eth0:1 ${vip} broadcast ${bcast} netmask ${netMask} up

/ sbin/route add-host ${vip} dev eth0:1

}

Function_remove_vip1 () {

/ sbin/ifconfig eth0:1 ${vip} broadcast ${bcast} netmask ${netMask down

}

Function_vip_arping1 () {

/ sbin/arping-I eth0-s ${vip} ${gateWay} > / dev/null 2 > & 1

}

Function_restart_nginx () {

/ web/webserver/nginx/sbin/nginx-s reload

}

Bind_time_vip= "N"

While true

Do

HttpCode_rip1= `/ usr/bin/curl-o / dev/null-s-w% {http_code} http://192.168.190.199`

If [x$ {httpCode_rip1} = = "x200"]

Then

If [${bind_time_vip} = = "N"]

Then

Function_bind_vip1

Function_vip_arping1

Bind_time_vip= "Y"

Fi

Function_vip_arping1

Else

If [${bind_time_vip} = = "Y"]

Then

Function_remove_vip1

Bind_time_vip= "N"

Fi

Fi

Sleep 10

Done

Then linux starts the waiting process

/ usr/bin/nohup / bin/sh / home/Gzh/shell/ autoSwitchMain.sh 2 > & 1 > / dev/null &

Standby 192.168.190.208:

AutoSwitchSlave.sh

#! / bin/sh

# # #

# desc: automatically switch services when the server is down

# author:gaozhonghui

# mail:toptreegzh@163.com

# date:20121101

# # #

Vip=192.168.190.88

GateWay=192.168.190.254

NetMask=255.255.255.0

Bcast=192.168.190.255

Function_bind_vip1 () {

/ sbin/ifconfig eth0:1 ${vip} broadcast ${bcast} netmask ${netMask} up

/ sbin/route add-host ${vip} dev eth0:1

}

Function_remove_vip1 () {

/ sbin/ifconfig eth0:1 ${vip} broadcast ${bcast} netmask ${netMask} down

}

Function_vip_arping1 () {

/ sbin/arping-I eth0-s ${vip} ${gateWay} > / dev/null 2 > & 1

}

Function_restart_nginx () {

/ web/webserver/nginx/sbin/nginx-s reload

}

Bind_time_vip= "N"

While true

Do

HttpCode_rip1= `/ usr/bin/curl-o / dev/null-s-w% {http_code} http://192.168.190.199`

If [x$ {httpCode_rip1} = = "x200"]

Then

If [${bind_time_vip} = = "Y"]

Then

Function_remove_vip1

Bind_time_vip= "N"

Fi

Function_vip_arping1

Else

If [${bind_time_vip} = = "N"]

Then

Function_bind_vip1

Function_vip_arping1

Bind_time_vip= "Y"

Fi

Fi

Sleep 10

Done

Start the waiting process

/ usr/bin/nohup / bin/sh / home/Gzh/shell/autoSwitchSlave.sh 2 > & 1 > / dev/null &

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report