Heartbeat is used to build a dual-host Hot Standby environment. It can be connected through a dedicated heartbeat line, or through
Connect through a common network cable.
Http://www.linux-ha.org
Of course, in addition to heartbeat, there are many other Linux systems, such as the RedHat cluster software. Lower
This section briefly introduces the installation and configuration of heartbeat.
2. Installation
2.1. Preparation
In this test, there are two hosts with IP addresses:
Host Name IP Address
Alssme_probe3 172.18.158.23
Alssme_probe4 172.18.158.24
If the/etc/hosts file is not configured, configure the/etc/hosts file first.
2.2 create users and user groups
Heartbeat requires the haclient user group and the hacluster user.
The two nodes perform the same operation and ensure that the IDs of haclient and hacluster are the same.
[Root @ alsme_probe3 log] # groupadd haclient
[Root @ alsme_probe3 log] # useradd-G haclient hacluster
2.3. Installation
You can download the RPM package directly or download the source code package to compile the package. Here, I use the source code compiled by myself.
Code. Install the Libnet package before installing heartbeat.
[Root @ alsme_probe3 TMP] # tar zxvf heartbeat-2.1.3.tar.gz
[Root @ alsme_probe3 TMP] # rpm-IVH libnet-1.1.2.1-2.2.el4.rf.x86_64.rpm
[Root @ alsme_probe3 TMP] # cd heartbeat-2.1.3
[Root @ alsme_probe3 TMP] #./configure
[Root @ alsme_probe3 TMP] # Make
[Root @ alsme_probe3 TMP] # make install
Similarly, it is installed on another host.
You can search for the Libnet package at http://rpmfind.net/linux/rpm2html/search.php.
3. Configuration
Heartbeat has three configuration files:
Ha. cf
Authkyes
Haresources
These files must be consistent on each machine. We will introduce them one by one.
CP/usr/local/share/doc/heartbeat-2.1.3/ha. Cf/usr/local/etc/ha. d
CP/usr/local/share/doc/heartbeat-2.1.3/haresources/usr/local/etc/ha. d
CP/usr/local/share/doc/heartbeat-2.1.3/authkeys/usr/local/etc/ha. d
3.1 Edit the master configuration file ha. Cf of hertbeat. The content on the two hosts is the same.
The configuration to be enabled is as follows. Detailed descriptions are provided in Ha. Cf.
[Root @ alsme_probe3 TMP] # vi/usr/local/etc/ha. d/ha. cf
# Location of the HA log file. If the directory does not exist, manually add
Logfile/var/log/ha-log # file to write other messages
Logfacility local0 # This is the log for setting heartbeat. Here the system log is used.
# Set the heartbeat (Monitoring) Time to 2 seconds
Keepalive 2 # How long does it take to detect
Warntime 5 # How long does it take to get in touch and start warning
Deadtime 20 # How long can the contact fail and the other party is considered to have crashed (the unit is wonderful)
Initdead 120 # Here is a period of ignore time reserved for the restart (for example, start after restart)
If the network is not connected, keepalive detection will fail, but it cannot be switched at this time.
)
# Send heartbeat information using bond0 UDP Broadcast
# Bcast bond0
# Use the UDP unicast of the network card bond0 to notify the heartbeat. The IP address should be the IP address of the other party. We recommend that you use unicast. When a network
If there are multiple clusters in the same segment, you must use the unicast method. Otherwise, each cluster will see
Node to report an error.
Ucast bond0 172.18.57.154
# Use UDP port 694 for heartbeat monitoring
Udpport 694
Auto_failback off # Whether to automatically switch back after it returns to normal, usually set to off.
# Node 1, which must be consistent with the result obtained by the uname-N command.
Node alsme_probe3
# Node 2
Node alssme_probe4
# Ping the gateway to check whether the heartbeat is normal
Ping 172.18.158.254
Hopfudge 1
Deadping 5
# Specify the process to be started and closed together with heartbeat # respawn hacluster
/Usr/local/lib64/heartbeat/ipfail # apiauth ipfail gid = haclient
Uid = hacluster
# Whether the V2 style mode is used. It must be enabled when there are more than three Nodes
# CRM On
According to the official heartbeat documents, the current Ping node has no practical use, but it is only used for detection.
Node connectivity is not a real basis for node switching. This may be done in future new versions.
.
3.2 edit the file authkeys
[Root @ alsme_probe3 heartbeat-2.1.3] # vi/usr/local/etc/ha. d/authkeys
Auth 1
1 CRC
[Root @ alsme_probe3 heartbeat-2.1.3] # chmod 600
/Usr/local/etc/ha. d/authkeys
Note that authkeys must have 600 permissions.
3.3 edit the cluster resource file: haresources
[Root @ alsme_probe3 heartbeat-2.1.3] # vi/usr/local/etc/ha. d/haresources
Alssme_probe3 ipaddr: 172.18.158.111/24/bond0 MySQL
For details about how to configure it, see haresources.
There are several considerations:
1) the first column of the Resource Group is one of the nodes in the HA. cf configuration file, and it should be the current preparation
The node of the primary node.
2). Each row represents a resource group. If a row cannot be written, you can use "line feed ".
3) The Starting sequence of the resource group is from left to right, and the closing sequence is from right to left.
4). The script parameters are separated and passed through:
5). Different resources in a resource group are separated by spaces.
6) There is no inevitable relationship between different resource groups.
7). Each resource is an angular, which can be under the/etc/init. d directory or
Is the corner book under the/usr/local/etc/ha. d/resource. d directory. These corners must support xxx
Start; XXX stop; mode.
8) for details about the service IP resource setting format, see the haresources file.
9). If MySQL is compiled and installed, modify the basedir in the/etc/init. d/MySQL file.
And datadir Parameters
3.4 resource corner this example-drbd
The following is an example of the Resource Management Role of drbd:
[Root @ alsme_probe3 heartbeat-1, 2.1.3] # vi
/Usr/local/etc/ha. d/resource. d/drbd
#! /Bin/sh
Case "$1" in
Start)
# Declared as the primary node of drbd
Drbdadm primary DB
# Mount a File System
Mount/dev/drbd0/Data
# Start Related Services
Service MySQL start
;;
Stop)
# Reverse operation
Service MySQL stop
Umount/dev/drbd0/Data
Drbdadm secondary DB
; Esac
Exit 0
MySQL we tested is provided when MySQL is installed. It can be implemented under the/etc/init. d directory.
MySQL startup and shutdown.
If we use the heartbeat + dual master mode, we do not need to add a MySQL Resource Group.
If we use the heartbeat + Master/Slave Mode, we need to re-run the MySQL ing.
Change the slave to the master when you start it. The master is changed to slave during stop.
We recommend that you use the heartbeat + dual master mode to minimize data loss.
4. Test
Test switchover is similar to the following: 1) manually call the heartbeat node switchover script.
2) unplug the network cable and test the switchover after the network of the primary node is disconnected.
After the network cable is deployed, when the master node finds that it cannot communicate with the standby node, it records the warn information in the log.
If the duration has reached the length set in Ha. Cf, the resource will be released and the standby node will issue
You cannot communicate with the master node for a period of time (set by HA. CF ).
Active becomes a primary node. The switching period except the time set in Ha. cf is also very short.
. The split of Custer brain is prone to problems. If dual master is used, this problem does not exist.
Question.
3) shut down the primary host and test whether the switchover is normal. 4). The master node loses power. Yes
No.
The first and third test methods must be tested.
5. Management
To enable or disable heartbeat:
/Etc/init. d/hearbeat start or service heartbeat start
And
/Etc/init. d/hearbeat stop or service heartbeat stop
Manual Switch:
[Root @ alsme_probe3 rc. d] #/usr/local/share/heartbeat/hb_standby
2008/07/19 _ 20:01:21 going standby [all].
[Root @ alsme_probe3 rc. d] # service heartbeat status
Heartbeat OK [pid 13763 et al] is running on alsme_probe3
[Alsme_probe3]…
Hand-over
[Root @ alsme_probe3 rc. d] #/usr/local/share/heartbeat/hb_takeover
View heartbeat status
[Root @ alsme_probe3 rc. d] # service heartbeat status
Heartbeat OK [pid 13763 et al] is running on alsme_probe3
[Alsme_probe3]…
6. Miscellaneous
The actual test results show that if the MyISAM storage engine is used
Data will be lost. When the InnoDB Storage engine is used, if the primary node itself does not have a program to go to the local machine
If data is written, data will not be lost. If a program on the primary node is writing data
Data, the Program on the local machine may write some data at the moment, and if it is another host
When the program is connected, data will basically not be lost.
Suggestion: In the drbd + HB environment, it is best to use the InnoDB Storage engine and set
Innodb_flush_log_at_trx_commit = 1, so that almost every committed transaction can be recorded in
In ib_logfile *, the secondary node can be restored to reduce the loss.
Heartbeat has two modes. The default mode only supports two nodes. If the cluster contains more than two
The CIB mode is required, that is, V2 style:
1) add all three nodes to ha. Cf, and add "CRM 1" to ha. Cf ″
2). Use/usr/local/lib64/heartbeat/haresources2cib. py
/Usr/local/etc/ha. d/haresources
/Usr/local/var/lib/heartbeat/CRM/CIb. xml.
"/Usr/local/lib64/heartbeat/haresources2cib. py haresources
/Usr/local/var/lib/heartbeat/CRM/CIb. xml"
3). Clear haresources
In addition, if only one node is started, the Service IP address takes effect in 2 minutes. This time is not
Know how to control it.