High Availability (HA) clusters

Source: Internet
Author: User

1, HA cluster introduction

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

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/8C/97/wKiom1hwedvh0_HwAAHhcxZkQCI069.png "title=" Clipboard.png "alt=" Wkiom1hwedvh0_hwaahhcxzkqci069.png "/>

For an HA architecture, under a switch there are two machines Web1 and WEB2, where WEB1 is the primary node, which normally provides services, while the WEB2 standby node is idle. Web1 and WEB2 have a heartbeat line in the middle, check the other's survival status. Mobile IP, also known as VIP is to provide services to the IP, under normal circumstances configured on the WEB1, when Web1 down, WEB2 will automatically configure the VIP, external services.


2. Pre-Preparation

Prepare two machines, one using centos6.5, the other centos6.3, and the system version does not affect the experiment

Nic Eth0 IP is as follows

master192.168.1.165

slave192.168.1.163

The following operations are to be operated on two machines:

(1) Set hostname, respectively master and slave Slave

The Lord set:

# hostname Master

# vim/etc/sysconfig/network

Hostname=localhost.localdomain

Revision changed to

Hostname=master

Set from top

# hostname Slave

# vim/etc/sysconfig/network

Hostname=localhost.localdomain

Revision changed to

Hostname=slave

(2) Shut down the firewall, master and slave operation

# iptables-f

# Service Iptables Save

# Getenforce 0

# Vim/etc/selinux/config

Selinux=enforcing

Revision changed to

Selinux=disabled

(3) Configure host, same as master-slave operation

# Vim/etc/host

192.168.1.165 Master

192.168.1.163 slave


3, Heartbeat installation

Both the host and slave need to install the heartbeat and need libnet, the host slave performs the same command

# Yum Install-y Heartbeat

# yum Install-y libnet

If you do not have a package, you need to install an extended Yum source, heartbeat in the Epel source.

# yum Install-y epel-release


4. Master node Configuration

You need to place 3 related configuration files in the heartbeat configuration directory

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

# CP Authkeys HA.CF haresources/etc/ha.d/

You can then start to modify the configuration file, first modify the validation file

# cd/etc/ha.d/

# vim Authkeys # is used to verify that the master/slave communicates to verify that the other is alive and requires encryption

Auth 3 # Opens here, numbers indicate which encryption method to choose

#1 CRC # The simplest

#2 SHA1 hi! # The most complex

3 MD5 hello! # in the middle level encryption method

# chmod 600/etc/ha.d/authkeys

# If permissions are not modified, heartbeat cannot start

The second configuration haresources file, you only need to edit a row. Because currently in the HA.D directory, direct vim. If not, use absolute path or CD

# Vim Haresources

#node1 10.0.0.170 Filesystem::/dev/sda1::/data1::ext2

#找到上面一行, change to below, need to get rid of #

Master 192.168.1.186/24/eth0:0 Nginx

# Master is the host name of the master, 192.168.1.186 is the VIP,/24 designated network segment, network card eth0:0 (where the virtual network card is used); Nginx provides services if the master is down, from the start.

The last configuration ha.cf, which is basically all comments, here choose to delete the re-write, the current still in the/ETC/HA.D directory

# > HA.CF

# Vim HA.CF

Debugfile/var/log/ha-debug

Logfile/var/log/ha-log

Logfacility local0

KeepAlive 2

Deadtime 30

Warntime 10

Initdead 60

Udpport 694

Ucast eth0 192.168.1.163

Auto_failback on

Node Master

Node slave

Ping 192.168.1.1

Respawn Hacluster/usr/lib/heartbeat/ipfail

Configuration Description:

Debugfile/var/log/ha-debug: This file saves debug information for Heartbeat

Log files for Logfile/var/log/ha-log:heartbeat

Logfacility local0: Log level

KeepAlive 2: Heartbeat time interval, default unit seconds

Deadtime 30: The heartbeat of the other node is not received at that time, the other person is considered dead

Warntime 10: A warning is issued and logged to a log when the heartbeat of the other node is not received at that time

Initdead 60: On some systems, it takes a period of time for the network to work after the system starts or restarts, which is used to resolve the time interval that occurs. At least twice times the Deadtime

Udpport 694: Set the port used for broadcast communication, 694 is the default port number

Ucast eth0 192.168.1.163:ucast Specify the other side ip,bcast form to look for; Eth0 Heartbeat detects its own network card, IP each other's IP

The two hosts of the Auto_failback On:heartbeat are primary nodes and slave nodes respectively. The primary node normally consumes resources to run all the services, encountering a failure to hand over the resources from the node to run the service from the node. option is on, once the master node resumes running, the resource is automatically fetched and the service is replaced from the node.

Node Master: Specify the primary

Node Slave: Specifies the

Ping 192.168.1.1

Respawn Hacluster/usr/lib/heartbeat/ipfail: Specifies the process that is started and closed with heartbeat, which is automatically monitored and restarted if a failure occurs. The most commonly used process is ipfail, which is used to detect and handle network failures and to detect network connections with the Pingnode specified by the ping statement. If the system is 64-bit, change the Lib in the address to lib64

Then install an nginx for the rear test

# yum Install-y nginx


5, from the node configuration

Copy the three configuration of the Lord to the slave, use the SCP command, and just modify the ha.cf file from the top to one place.

# SCP Authkeys ha.cf haresources slave:/etc/ha.d/

# VIM/ETC/HA.D/HA.CF

Ucast eth0 192.168.1.163 changed to Ucast eth0 192.168.1.165

Also installs an nginx, used for the rear test

# yum Install-y nginx


6. Heartbeat Test

Start heartbeat, order is important, Guthrie after

# Service Heartbeat Start

Check test (master), first time will need to wait a while, patience

# ifconfig

See if there's eth0:0.

# PS aux | grep nginx

See if there is an Nginx process

Test (1)

Because the heartbeat of the master-slave finger is connected through ping, so the Lord deliberately forbidden Ping, died

# iptables-d Input-p icmp-j DROP

If it fails, check the log to find the card is not moving here

Dec 18:56:53 Master heartbeat: [9590]: Warn:node 192.168.1.1:is dead

Dec 18:56:53 Master heartbeat: [9590]: Info:link 192.168.1.1:192.168.1.1 dead.

Dec 18:56:53 Master ipfail: [9619]: Info:status update:node 192.168.1.1 now have Status dead

HARC (default) [10097]:2016/12/08_18:56:53 info:running/etc/ha.d//rc.d/status status

Dec 18:56:54 Master ipfail: [9619]: Info:NS:We is dead. :<

Dec 18:56:54 Master ipfail: [9619]: Info:link status Update:link 192.168.1.1/192.168.1.1 now have Status dead

Dec 18:56:55 Master ipfail: [9619]: Info:we is dead. :<

Dec 18:56:55 Master ipfail: [9619]: info:asking Other side for Ping node count.

Try a workaround

Change the ucast from the HA.CF configuration file on the following

Bcast eth0

And then re-test


Test (2)

Master Stop Heartbeat Service

# Service Heartbeat Stop


Test (3): Test for brain fissure

The Lord and the eth0 down from the top.

# Ifdown Eth0



This article from "Liew" blog, declined reprint!

High Availability (HA) clusters

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.