Heartbeat is the core of the HA project in http://linux-ha.org, and HA is short for HighAvailability. Simply put, it is to provide high-Reliability Application Services, such as using two machines for HA and providing WEB services, A sub-host provides WEB Services for the master server at ordinary times. HA ensures that when the master server fails (for example, power loss), the other sub-host can immediately take over and continue to provide WEB services, in this way, the user does not feel that the service has never been interrupted. More machine sub-components may be used in the experiment application.
Heartbeat is the core of the HA project in the http://linux-ha.org, HA is short for (High Availability); simply put, it is to provide High-Reliability Application Services, such as using two machines for HA, provides WEB services. A server sub-provides WEB Services for the master server at ordinary times. HA ensures that when the master server encounters a fault (such as power failure), another server sub-can immediately take over to continue providing WEB services, in this way, the user does not feel that the service has never been interrupted. More machines may be used in the experiment application to form a cluster.
Heartbeat can be used to monitor the host through the serial port or Ethernet. To make it easier for me to use Ethernet, configure the dual Nic on the two machines separately, use a twisted pair to connect two machines and the other two NICs to the route, it is easy to configure the network of Fedora on the command line or GUI. My configuration here is:
PC1 (use this server as the master server ):
Eth0: 192.168.1.110
Eth1: 10.0.0.1
PC2:
Eth0: 192.168.1.111
Eth1: 10.0.0.2
After the network is configured and tested correctly, check whether the WEB services on the two machines can be used normally. If everything is normal, use yum to install Heartbeat:
Yum install heartbeat
After heartbeat is installed, the configuration starts. The three main configuration files are under/usr/share/doc/heartbeat-2.1.3/. You need to manually modify the files and copy them to/etc/ha. d/medium;
Edit the authkeys file. The following configuration uses sha1 as the authentication method (note that the permission of this file must be set to 600 ):
Auth 2
#1 crc
2 sha1 HI!
#3 md5 Hello!
Edit ha. cf:
Keepalive 1 # Set the heartbeat (Monitoring) Time to 1 second
Warntime 10 # Set the warning time
Deadtime 30 # Set the host downtime
Initdead 120 # first downtime
Ucast eth1 10.0.0.2 # Use eht1 for heartbeat monitoring, that is, the network adapter connecting two PCs
Udpport 694 # Use udp port 694 for heartbeat monitoring
Node f801 # node 1, which must be consistent with the uname-n result.
Node f802 # node 2
Edit haresources:
F801 192.168.1.118 httpd
The host uses 192.168.1.118 as the WEB Service IP address, and f801 is the master server.
After configuration, start Heartbeat on the master server:
Service heartbeat start
If an error occurs, you can modify the configuration file as prompted. Heartbeat automatically starts the corresponding service program according to the haresource configuration file.
Start Heartbeat on another server;
After configuration, you can use tcpdump to test the heartbeat between the two machines:
[Root @ f801 ~] # Tcpdump-I eth0-p udp port 694
Tcpdump: verbose output suppressed, use-v or-vv for full protocol decode
Listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
11:43:46. 431448 IP ha01.filenet-nch> ha02.ha-cluster: UDP, length 219
11:43:46. 433968 IP ha01.filenet-nch> ha02.ha-cluster: UDP, length 216
11:43:47. 431456 IP ha01.filenet-nch> ha02.ha-cluster: UDP, length 216
11:43:48. 432516 IP ha01.filenet-nch> ha02.ha-cluster: UDP, length 216
If there is a problem here, it may be a firewall problem, or the setting in ucast in the configuration file. You need to check carefully. During configuration, the eth0 in ucast is set incorrectly.
Finally, you can perform a test to shut down the master server. According to the response time in the configuration file, server PC2 will take over the master server's tasks.