Using heartbeat in linux to implement hot standby

Source: Internet
Author: User
In linux, heartbeat is used to implement dual-host hot backup-Linux Enterprise Application-Linux server application information. The following is a detailed description. 1. install two linux (rh4.5-32-bit) systems and disable the firewall. selinux is set to disable. Two NICs are required for each computer. The two computers are node1 and node2 respectively.

The IP addresses of node1 are:
Eth0: 192.168.0.65
Eth1: 10.0.0.3 (Heartbeat address)
The IP addresses of node2 are:
Eth0: 192.168.0.66
Eth1: 10.0.0.4 (Heartbeat address)
192.168.0.30 (virtual IP address)
Note: ensure that each Nic of the two computers can be pinged.

Ii. Ensure that the files under the two computers must be the same
/Etc/hosts
/Etc/host. conf
/Etc/resolv. conf
# Vi/etc/hosts

The hosts content of node1 is as follows:
IP address domain name machine name
192.168.0.65 node1.example.com node1
10.0.0.3 node1
192.168.0.66 node2.example.com node2
10.0.0.4 node2
(Ensure that the machine name and parameter uname-n output are consistent)
# Vi/etc/host. conf
Order hosts, bind
# Vi/etc/resolv. conf
Nameserver 202.96.209.20.( enter the DNS address based on the Local dns if it is null)

The hosts content of node2 is as follows:
IP address domain name machine name
192.168.0.65 node1.example.com node1
10.0.0.3 node1
192.168.0.66 node2.example.com node2
10.0.0.4 node2
(Ensure that the machine name and parameter uname-n output are consistent)
# Vi/etc/host. conf
Order hosts, bind
# Vi/etc/resolv. conf
Nameserver 202.96.209.20.( enter the DNS address based on the Local dns if it is null)

3. Install the heartbeat software package on both computers.
In the following order
1: heartbeat-gui-2.1.2-2.el4.centos.i386.rpm
2: heartbeat-pils-2.1.2-2.el4.centos.i386.rpm
3: heartbeat-stonith-2.1.2-2.el4.centos.i386.rpm
4: heartbeat-2.1.2-2.el4.centos.i386.rpm

4. configuration file.
Go to the/usr/share/doc/heartbeat-2.1.2/directory and copy authkeys, ha. cf, and haresources to the/etc/ha. d/directory for configuration.
(These three files must be consistent on two computers .) The configuration is as follows:

Configure the heartbeat encryption method: authkeys
# Vi/etc/ha. d/authkeys

Use dual-host couplet line (the network cable is a crossover Line). The configuration is as follows:
# Vi/etc/hc. d/authkeys
Auth 1
1 crc
Save the disk and exit, and then
# Chmod 600 authkeys
Modify file permissions (required)

Configure the heartbeat configuration file: ha. cf
# Vi/etc/ha. d/ha. cf
Logfile/var/log/ha-log (location where the ha log file is recorded. If this directory does not exist, you need to manually add it)

Bcast eth1

Keepalive 2 (set the heartbeat (Monitoring) Time to 2 seconds)

Warntime 10 (if the heartbeat of the peer node is not received beyond this interval, a warning is issued and recorded in the log .)

Deadtime 30 (if the heartbeat of the other node is not received beyond this interval, the other node is considered dead)

Initdead 120
(In some systems, it takes some time for the Network to work normally after the system is started or restarted. This option is used to solve the time interval generated in this case. The value must be at least twice the deadtime value .)

Udpport 694 (use udp port 694 for heartbeat Monitoring)

Auto_failback off
Nice_failback on

(Nice_failback is not available in heartbeat of this version. If not, you can manually add it as needed. The two master nodes of heartbeat are the master node and slave node respectively. The master node normally occupies resources and runs all services. In case of a fault, the master node delivers the resources to the slave node and the slave node runs the services. 1: When the auto_failback option is on, resources are automatically restored once the master node resumes running. 2: When the auto_failback option is off and the nice_failback option is on, resources are not automatically restored once the master node recovers. This is the second case .)

Node node1 (node 1, which must be consistent with the result obtained by the uname-n command .)
Node node2 (node 2)

Configure heartbeat resources: haresources
# Vi/etc/ha. d/haresources

Node1 192.168.0.30 httpd mysql (start httpd first and then start mysql, close mysql first and then disable httpd) specify node1 to start httpd and mysql services, and the system attaches a virtual IP address 192.168.0.30 to eth0: 0. If node1 goes down, node2 can automatically start httpd and mysql services, and assign the IP address 192.168.0.30 to the eth0: 0. The web Service Listening address of node2.

5. Set heartbeat to automatically start (start when the system is started)
Cd/etc/rc. d/rc0.d
Ln-s/etc/init. d/heartbeat K05heartbeat

Cd/etc/rc. d/rc3.d
Ln-s/etc/init. d/heartbeat S75heartbeat

Cd/etc/rc. d/rc5.d
Ln-s/etc/init. d/heartbeat S75heartbeat

Cd/etc/rc. d/rc6.d
Ln-s/etc/init. d/heartbeat K05heartbeat
(Uppercase letters are S and K)

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.