Shell resolution Server High Availability

Source: Internet
Author: User
Tags curl

HA (High availability) is highly available and has the following three modes of operation.

(1) Master-slave mode (asymmetric mode)

Working principle: The host work, the standby machine is in the monitoring preparation condition; When the host is down, the standby machine takes over all the work of the host, when the host is back to normal, the user's setting will switch the service to the host automatically or manually, and the data consistency can be solved by the shared storage system

(2) dual-machine duplex mode (Mutual assistance)

Working principle: Two hosts at the same time running their own services and monitoring the situation, when any one host downtime, another host immediately take over all of its work to ensure real-time work, application service system Key data stored in the shared storage system.

(3) The working mode of the cluster (multi-server mutual standby mode)

How it works: Multiple hosts work together, each running one or several services, each for the service to define one or more standby host, when a host failure, the service running on it can be taken over by other hosts.

Linux has a number of tools to provide highly available functionality, such as vrrp,heartbeat.

VRRP hosts regularly broadcast that they're still alive. "I am master, I am still alive, safe", and when the standby machine can not accept the "safe" time, will take over the host's IP address, also took over the host to provide services, and then began shouting "I became a host, I am alive, safe"

Heartbeat uses a heartbeat without broadcasting, which is to establish a monitoring relationship between highly available servers, to avoid the burden of broadcasting on the network, to be more powerful, and to execute scripts while taking over IP.

VRRP use dual duplex mode, but some of the application scenarios do not apply, such as MySQL high availability can not use VRRP. "Shared storage" is the purpose of the three modes of HA to solve data consistency problems, MySQL data file that is, if set up in the NFS service, start slow do not say, standby even if it can not be used, a period of time to the backup machine MySQL service will automatically end. Because the server is not so easy to die (in the test for simplicity, the general is to let the machine die), more time is applied to die. So there is a combination of heartbeat+drbd+mysql, using the Heartbeat script execution function (detection, resource recycling).

Here we use the shell script to implement the VRRP (asymmetric) function of the system. The environment is as follows:

Web (primary) 192.168.1.1 HTTP service

Web (standby) 192.168.1.2 HTTP Service

Realization idea: First is the state monitoring, since is the HTTP service, we monitor the httpd state, uses curl-w%{http_code to obtain. Standby to run the script, when the curl get the status code is not 200, that is, the host has died, we let the standby host IP. and use the arping command to update the LAN's MAC records for host IP.

#/bin/bash

While True

Code= ' Curl-o/dev/null-w%{http_code} http://192.168.1.1/2>/dev/null '

if! [$code-eq];then

Ifconfig eth0 192.168.1.1

Arping-a-C 1-i eth0 192.168.1.1

Kill-9 $$ #IP已经切换, the script has not continued to run the necessary to kill itself.

Fi

Sleep 5

Done

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.