Heartbeat of high-availability CentOS Linux clusters

Source: Internet
Author: User

CentOS Linux the high-availability cluster Heartbeat

The Heartbeat project is an integral part of the LINUX-HA project, which implements a highly available cluster system. Heartbeat service and cluster communication are two key components of a highly available cluster, and in the Heartbeat project, These two functions are implemented by the Heartbeat module.

Heartbeat , a component of the Linux-ha project , has released numerous versions since the beginning of the 1999 year, and is one of the most successful examples of open source linux-ha projects today. has been widely used in the industry .

with The growing use of Linux in key industries will inevitably provide services from large commercial companies such as IBM and SUN, a key feature of the services offered by these business companies, which are highly available clusters.

Heartbeat (linux-ha) works:heartbeat The core consists of two parts, the Heartbeat monitoring section and the Resource Takeover section, heartbeat monitoring can be carried out via network link and serial port, and support redundant over the link, they send each other a newspaper Greek tell the other side of their current state, if not received within the specified time message sent by the other party, it is considered invalid, then the need to start the Resource takeover module to take over the transport resources or services that are on the other side of the host.

A highly available cluster is a set of independent computers that are connected by hardware and software that behave as a single system in front of the user, where one or more nodes within a set of computer systems stop working, and the service switches from a failed node to a functioning node without interruption of service. As you can see from this definition, the cluster must detect when nodes and services are invalidated and when they are available. This task is usually done by a set of code called "Heartbeat". In linux-ha This function is done by a program called Heartbeat .

The following uses hearbeat to do high availability cluster ha,nginx service as a highly available cluster ha service object, that is, the main server nginx Downtime or inability to provide services, switch to external services from the service.

System environment:

Master(master server):

Hostname:masternginx,eth0:192.168.171.50 ,eth1:192.168.17.50

Slave ( from server ):

Hostname:slavenginx,eth0:192.168.171.51,eth1:192.168.17.51

flow of IP (Virtual IP):192.168.171.100(i.e. IP for external service )

Nginx installed in the system installation or late self-installation.

1), pre-installation preparation work:

(1) Set the hostname of the master-slave server separately ,

Primary server:vim/etc/sysconfig/network modified:Hostname=masternginx

from server:vim/etc/sysconfig/network modified:Hostname=slavenginx

(2), respectively, on the master-slave server to turn off SELinux

Sed–i ' s/selinuxe=enforcing/selinux=disabled/'/etc/selinux/config

(3), respectively, in the master-slave server configuration /etc/hosts corresponding IP and host name:

192.168.17.51 Slavenginx

192.168.17.50 Masternginx

2), install the heartbeat software on the master server and the slave server separately , and install the libnet.

Yum Install libnet heartbeat #yum installation to resolve dependencies

SOURCE Download:

Libnet:http://libnet.sourceforge.net/

Heartbeat:http://www.linux-ha.org/wiki/Downloads

3), modify the configuration of the heartbeat

(1) First modify the configuration on the primary server, mainly the following three files:

(heartbeat Installation sample directory under /usr/share/doc/beartbeat-*)

Authkeys: Used to verify communication, to see if the other side is still alive

Haresources: Service Information for configuring a mobile IP and services that require HA

HA.CF: configuration file for heartbeat

(2) on the primary server, /usr/share/doc/beartbeat copy three files from the heartbeat installation sample directory to/ETC/HA.D Directory under

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

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

(3) Modify the configuration file

Modifications on the main service:

Vim/etc/ha.d/authkeys # Edit Authentication communication mode

AUTH3 # default is a # comment, which authentication method

#1 CRC

#2 SHA1 hi!

3 MD5 hello! # Remove # # ,

Save exit, Modify permissions:Chmod600/etc/ha.d/authkeys

Vim/etc/ha.d/haresources # Service Information for configuring mobile IP and services that require HA , default is all comments

masternginx192.168.171.100/24/eth0:0 Nginx

VIM/ETC/HA.D/HA.CF #heartbeat The main configuration file

Debugfile/var/log/ha-debug # troubleshooting logs

Logfile/var/log/ha-log # where logs are stored

Logfacility local0 # Log Level

KeepAlive 2 -#2-second cycle detection

Deadtime #.30 seconds without a response, he thinks he's dead.

Warntime # If you don't respond more than ten seconds, a warning will occur .

Initdead 60 #. reserved time for restart

Udpport 694 # Heart jumper Communication Port

Ucast eth1 192.168.17.51 #. Heart jumper interface and each other Ip

Auto_failback on #. main switch to from, or master recovery Yes, will automatically switch

Node Masternginx #. host name of the primary server

Node Slavenginx #. host name from the server

Ping 192.168.17.1 # server IP for quorum

Respawn Hacluster/usr/lib64/heartbeat/ipfail # Run the script hacluster to Check the connectivity of the network.

Copy the three configuration files that you just modified to the same directory from the server. Make a change:

cd/etc/ha.d/

SCP Authkeys haresources ha.cfslavenginx:/etc/ha.d/

To modify from the server:

Authkeys and haresources configuration content need not change, only need to modify ha.cf configuration file

VIM/ETC/HA.D/HA.CF #heartbeat The main configuration file

Debugfile/var/log/ha-debug # troubleshooting logs

Logfile/var/log/ha-log # where logs are stored

Logfacility local0 # Log Level

KeepAlive 2 -#2-second cycle detection

Deadtime #.30 seconds without a response, he thinks he's dead.

Warntime # If you don't respond more than ten seconds, a warning will occur .

Initdead 60 #. reserved time for restart

Udpport 694 # Heart jumper Communication Port

Ucast eth1 192.168.17.50 #. Heart jumper interface and each other Ip

Auto_failback on #. main switch to from, or master recovery Yes, will automatically switch

Node Masternginx #. host name of the primary server

Node Slavenginx #. host name from the server

Ping 192.168.17.1 # server IP for quorum

Respawn Hacluster/usr/lib64/heartbeat/ipfail # Run the script hacluster to Check the connectivity of the network.

there is basically no need to change the content, just to modify the heartbeat IIP address modified to each other's IP

(ucast eth1 192.168.171.50)

Test:

If the firewall is turned on, the UDP 694 port must be released.

-A input-m state--state new-m udp-p udp--dport 694-j ACCEPT

1), start the heartbeat service, but must be turned on on the primary server before it can be turned on from the server.

Service Heartbeat Start

2), inspection test:

Ifconfig See if there are eth0:0

PS aux |grep nginx See if there is Nginx process

3), Analog fault test

for testing convenience, we set up a test page under the default Web site of the primary server and the Nginx service from the server:

Contents of the master server:

echo "1111111111111master Server" >/usr/share/nginx/html/index.html

Content from the server:

echo "222222222222 slave Server" >/usr/share/nginx/html/index.html

Analog failure

Test 1: Disable ping on the primary server

Iptables-i input-p icmp-j DROP # reject ICMP packet, simulate failure

iptables-d input-p icmp-j DROP # de-fault

Tests whether a failure occurs on the primary server, whether the service is taken over from the server, and whether the master server is recovering from the server or not releasing the takeover.

Test 2: The primary server stops the heartbeat service directly, simulating a heartbeat failure

Service Heartbeat Stop

Service Heartbeat Start

Test 3: Simulate the heartbeat line segment on both master and slave

Ifdown eth1


This article is from the "Balich" blog, make sure to keep this source http://balich.blog.51cto.com/6641781/1714434

Heartbeat of the CentOS Linux high availability cluster

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.