Heartbeat dual-host hot standby service setup on Linux

Source: Internet
Author: User
Article Title: heartbeat dual-host hot standby service setup on Linux. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.

[1] environment setting before installation

Hardware environment of the two hosts (not completely consistent ):

CPU: Xeon 3G * 2 (EM64T)

MEM: 2G

NIC: Intel 1G * 2

Eth0: external IP address

Eth1: internal IP address (for HA)

The eth1 of the two hosts are directly connected through dual-host couplets.

Partitioning Method:

Filesystem capacity mount point

/Dev/sda2 9.7G/

/Dev/sda6 45G/Datas

/Dev/sda1 99 M/boot

None2.0G/dev/shm

/Dev/sda3 9.7G/opt

In addition, each host should reserve MB of raw space or use it as a shared space for HA.

Operating System:

RedHat Enterprise 4 Update2 (2.6.9-22 EL)

Pre-installed software:

@ X Window System

@ GNOME Desktop Environment

@ KDE Desktop Environment

@ Editors

@ Engineering and Scientific

@ Graphical Internet

@ Text-based Internet

@ Authoring and Publishing

@ Server Configuration Tools

@ Development Tools

@ Kernel Development

@ X Software Development

@ GNOME Software Development

@ KDE Software Development

@ Adminitools

@ System Tools

[2] network environment settings before installation:

Node1: Host Name: servers201 (HA01)

Eth0: 192.168.10.201 // external IP address

Eth1: 10.0.0.201 // HA heartbeat address

Node2: Host Name: servers202 (HA02)

Eth0: 192.168.10.202 // external IP address

Eth1: 10.0.0.202 // HA heartbeat address

Check the following files:

/Etc/hosts

/Etc/host. conf

/Etc/resolv. conf

/Etc/sysconfig/network

/Etc/sysconfig/network-scripts/ifcfg-eth0

/Etc/sysconfig/network-scripts/ifcfg-eth1

/Etc/nsswitch. conf

# Vi/etc/hosts

The hosts content of node1 is as follows:

127.0.0.1 localhost. localdomain localhost

192.168.10.201 servers201 HA01

10.0.0.201 HA01

10.0.0.202 HA02

192.168.10.202 server202

The hosts content of node2 is as follows:

127.0.0.1 localhost. localdomain localhost

192.168.10.202 servers202 HA02

10.0.0.202 HA02

10.0.0.201 HA01

192.168.10.201 server201

# Cat/etc/host. conf

Order hosts, bind

# Cat/etc/resolv. conf

Nameserver 61.139.2.69 // DNS address

# Cat/etc/sysconfig/network

NETWORKING = yes

HOSTNAME = servers201 // host name

GATEWAY = "192.168.10.1" // GATEWAY

GATEWAY = "eth0" // The network card used by the GATEWAY

ONBOOT = YES // load at startup

FORWARD_IPV4 = "yes" // only IPV4 addresses are allowed

# Cat/etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE = eth0

ONBOOT = yes

BOOTPROTO = static

IPADDR = 192.168.10.201

NETMASK = 255.255.255.0

GATEWAY = 192.168.10.1

TYPE = Ethernet

IPV6INIT = no

# Cat/etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE = eth1

ONBOOT = yes

BOOTPROTO = none

IPADDR = 10.0.0.201

NETMASK = 255.255.255.0

TYPE = Ethernet

[Node1] and [node2] in the preceding configuration,

/Etc/hosts

/Etc/sysconfig/network

/Etc/sysconfig/network-scripts/ifcfg-eth0

/Etc/sysconfig/network-scripts/ifcfg-eth1

Except for modification.

After the configuration is complete, try to ping the Host Name of the other host. You can ping the Host Name of the other host:

/Root # ping HA02

PING HA02 (10.0.0.202) 56 (84) bytes of data.

64 bytes from HA02 (10.0.0.202): icmp_seq = 0 ttl = 64 time = 0.198 MS

64 bytes from HA02 (10.0.0.202): icmp_seq = 1 ttl = 64 time = 0.266 MS

64 bytes from HA02 (10.0.0.202): icmp_seq = 2 ttl = 64 time = 0.148 MS

--- HA02 ping statistics ---

3 packets transmitted, 3 bytes ed, 0% packet loss, time 2002 ms

Rtt min/avg/max/mdev = 0.148/0.204/0.266/0.048 MS, pipe 2

[3] install the HA and HA dependency packages

Rpm-Uvh libnet-1.1.2.1-1.rh.el.um.1.i386.rpm // can be left empty

Rpm-Uvh heartbeat-pils-2.0.4-1.el4.i386.rpm

Rpm-Uvh heartbeat-stonith-2.0.4-1.el4.i386.rpm

Rpm-Uvh heartbeat-2.0.4-1.el4.i386.rpm

Rpm-Uvh ipvsadm-1.24-5.i386.rpm

[4] configuration files for configuring HA

Configure the heartbeat encryption method: authkeys

# Vi/etc/ha. d/authkeys

If you use dual-host couplet wires (twisted pair wires), you can configure the following:

# Vi/etc/hc. d/authkeys

Auth 1

1 crc

Save the disk and exit, and then

# Chmod 600 authkeys

Configure heartbeat monitoring: haresources

# Vi/etc/ha. d/haresources

All hosts should be identical.

Server201 IPaddr: 192.168.10.200 ipvsadm httpd

Specify server201 to call ipvsadm to start the http service. The system attaches a virtual IP address 192.168.10.200 to eth0: 0.

If server201 is down, server202 can automatically start the http service and assign the IP address 192.168.10.200 to the eth0: 0 of server202.

Configure the heartbeat configuration file: ha. cf

# Vi/etc/ha. d/ha. cf

Logfile/var/log/ha_log/ha-log.log # the location where the ha log file is recorded. If the directory does not exist, manually add

Bcast eth1 # Use eth1 for heartbeat monitoring

Keepalive 2 # Set the heartbeat (Monitoring) Time to 2 seconds

Warntime 10

Deadtime 30

Initdead 120

Hopfudge 1

Udpport 694 # Use udp port 694 for heartbeat monitoring

Auto_failback on

Node server201 # node 1, which must be consistent with the result obtained by the uname-n command.

Node server202 # node 2

Ping 192.168.10.1 # ping the gateway to check whether the heartbeat is normal.

Respawn hacluster/usr/lib64/heartbeat/ipfail

Apiauth ipfail gid = root uid = root

Debugfile/Datas/logs/ha_log/ha-debug.log

Configure ingress SADM monitoring

Ipvsadm-A-t 192.168.10.200: 80-s rr

Ipvsadm-a-t 192.168.10.200: 80-r 192.168.10.201: 80-m

Ipvsadm-a-t 192.168.10.200: 80-r 192.168.10.202: 80-m

Perform monitoring after execution:

# Ipvsadm -- list

If the returned result is the same as the following, the setting is correct.

IP Virtual Server version 1.2.0 (size = 4096)

Prot LocalAddress: Port sched1_flags

-> RemoteAddress: Port Forward Weight ActiveConn InActConn

TCP 192.168.10.200: http rr

-> Server202: http Local 1 0 0

-> Server201: http Masq 1 0 0

[5] startup, shutdown, and testing of the HA Service

Start HA: service heartbeat start

Disable HA; service heartbeat stop

The system automatically loads heartbeat at startup.

Use http service to test heartbeat

Start the httpd service

# Service httpd start

Edit the html file used for testing on the respective hosts and put it in the/var/www/html/directory.

Start heartbeat of node1 and execute this command for monitoring: heartbeat status

[6] firewall settings

Heartbeat uses udp port 694 by default for heartbeat monitoring. If the system uses iptables for firewall, remember to open this port.

# Vi/etc/sysconfig/iptables

Add the following content

-A RH-Firewall-1-INPUT-p udp-m udp -- dport 694-d 10.0.0.201-j ACCEPT

This means that udp port 694 is open to the peer's heartbeat NIC address 10.0.0.201.

# Service iptables restart

Reload iptables.

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.