Ha High Availability Cluster

Source: Internet
Author: User
Tags scp command

First, High available

HA (high available) is highly available and is also known as a dual-machine hot standby for critical business. The simple understanding is that there are two machines A and B, the normal is a service, B standby idle, when a down or service outage, will switch to the B machine to continue to provide services. Commonly used high-availability open source software has heartbeat and keepalived, where keepalived has load-balanced functionality.


Ha can also be used in MySQL, but there must be a shared storage between the two MySQL.

Both machines must be dual NICs, each with one connection switch and the other connected (heart jumper).

This experiment is implemented under the virtual machine, in the virtual machine setup, each of the two machines to add more than one NIC.

The new network adapter is set to "Host-only (host mode only)" and cannot be set to bridged mode. The IP setup process is as follows:

650) this.width=650; "src=" http://note.youdao.com/yws/res/5557/84B04F6CC0C74F27BDCD9FB822B26575 "alt=" 2.png " height= "401" width= "657"/>
650) this.width=650; "src=" http://note.youdao.com/yws/res/5560/1DC032A3F9204AB3ABC91354C8D42676 "alt=" 3.png "/>

New network card, the system does not have a corresponding ifcfg-eth1 file, directly copied Ifcfg-eth0, and renamed to Ifcfg-eth1.

eth1 files can only be kept in a few lines:

650) this.width=650; "src=" http://note.youdao.com/yws/res/5565/5B361770BD77404EA25139FAD14D2F82 "alt=" 1.png "/>

1. Two machines are modified separately hostname

Vi/etc/sysconfig/network in effect after reboot

Individually modified to AMINGLINUX1,AMINGLINUX2

Hostname aminglinux1 (2) Change host name, invalid after reboot

Bash takes the changed host name into effect


2, shut down the firewall, both machines to shut down

Iptables-f Clear Firewall rules

Service Iptables Save firewall rule (after cleanup)

Setenforce 0 temporarily shuts down the SELinux system

Vi/etc/selinux/config

Selinux=disabled permanently shuts down the SELinux system

3. Add the Hosts record

Vi/etc/hosts
Two separate host records added to another machine

172.18.18.230 aminglinux1

172.18.18.231 aminglinux2

4. Install Epel extended Yum source

Yum install-y Epel-release facilitates rear mounting heartbeat

5, the two machines are installed heartbeat, libnet, Nginx

Yum Install-y heartbeat*

Yum Install-y libnet

Yum install-y Nginx

6, the main machine (AMINGLINUX1) configuration

cd/usr/share/doc/heartbeat-3.0.4/

CP ha.cf Haresources authkeys/etc/ha.d/

cd/etc/ha.d/


chmod Authkeys

VI Authkeys

This file is used to verify that two machines have the intention of jumper communication to confirm that the other person is alive. Use this file for cryptographic verification to avoid the arbitrary recognition of the master and slave machines by other machines.

The template file contents are as follows

#auth 1
#1 the weakest way to encrypt the CRC
#2 SHA1 hi! SHA encryption, the strongest way to encrypt
#3 MD5 hello! MD5 encryption, encryption is relatively simpler than SHA
We need to make some changes to enable the third type of

Auth 3
#1 CRC
#2 SHA1 hi!
3 MD5 hello!


VI haresoureces

This file is used to specify the primary node , virtual IP, and the services under control .

aminglinux1 172.18.18.233/22/eth0:0 Nginx

Nginx service must be in/etc/init.d/this directory, otherwise, the above nginx will not be found.

Virtual IP to be used to provide services to the IP segment, not the heart jumper that IP segment.

VI ha.cf main configuration file


Debugfile/var/log/ha-debug Open Log function

Logfile/var/log/ha-log Specifying log files

Logfacility local0 error Log level

KeepAlive 22 machines, heart jumper detection, detection every 2 seconds

Deadtime 30 detect the other machine down, 30 after the confirmation is the outage

Warntime 10 detects the other machine down after 10 seconds, send a warning, write to the log

Initdead 60 service Restart, wait for 60s, after which no normal boot will replace it

Udpport 694 to detect survival in the form of a broadcast

#baud 19200 with the serial cable directly connected to the Heart jumper mode, only enable this selection

port Selection in serial mode:
# serial Serialportname ...
#serial/DEV/TTYS0 # Linux
#serial/DEV/CUAA0 # FreeBSD
#serial/dev/cuad0 # FreeBSD 6.x
#serial/dev/cua/a # Solaris
In broadcast mode, select the port:
# What is interfaces to broadcast heartbeats?
#
#bcast eth0 # Linux
#bcast eth1 eth2 # Linux
#bcast LE0 # Solaris
#bcast le1 Le2 # Solaris

Ucast eth1 192.168.126.102

Ucast is a network card that accesses the heartbeat line directly using IP. Here to fill in the other side of the Heartbeat line network card and IP

Auto_failback on

Main downtime and repair normal, from the detection of the main recovery, the initiative to return the service to the master, self-recovery from the state.

Respawn Hacluster/usr/lib/heartbeat/ipfail

Heartbeat Start the Ipfail, this tool is to realize the heartbeat line mutual detection function.

To hacluster this user to start the tool, this user is the user who started the heartbeat process.

Ping 192.168.126.1

The quorum IP, master, or the request to detect the other party's outage is in effect, as determined by this device, the general choice of Gateway

Node Aminglinux1 Master

Node aminglinux2 from


SCP ha.cf haresources Authkeys aminglinux2:/etc/ha.d/

Copy the three configuration files to a Slave

SCP command, both machines are installed openssh-clients to use.

7, from the machine configuration

chmod Authkeys

cd/etc/ha.d/

Authkeys,haresources files are not modified


VI ha.cf only need to change a little, ucast to each other's IP.

Ucast eth1 192.168.126.101


8. Start Heartbeat Service

After Guthrie from

Service Heartbeat Start

Starting high-availability Services:INFO:Resource is stopped


Info:resource is stopped this hint is not an error

Arbitration is through the IMCP protocol to communicate with the master and slave, so the master and slave can not be forbidden ping, otherwise it will be considered as a downtime state


When the heartbeat line off, master and slave will feel that the other side down, the master and slave will start the services, thus wasting resources.

Beware of jumper recovery, both sides will abandon these resources, causing the service is not normal. So, after the heart jumper is restored, from the next heartbeat service to restart



This article from "Eleven" blog, reproduced please contact the author!

Ha High Availability cluster

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.