Configure LVS + Heartbeat + Ldirectord cluster on RedHat5.4

Source: Internet
Author: User
Tags openssl md5
In the cluster technology currently used in large-scale websites, it can provide load balancing and high availability web services. Of course there are other solutions that can also provide load balancing and high availability, here we will implement lvs + heartbeat + ldirectord. In the need of Software Package heartbeat-2.1.4-9.el5.i386.rpmheartbeat-p in the current large-scale website application cluster technology, can provide load balancing, high availability web Services, of course, there are other solutions that can also provide load balancing and high availability. Here we will implement lvs + heartbeat + ldirectord.
In the required software package
Heartbeat-2.1.4-9.el5.i386.rpm
Heartbeat-pils-2.1.4-10.el5.i386.rpm
Heartbeat-devel-2.1.4-9.el5.i386.rpm
Heartbeat-stonith-2.1.4-10.el5.i386.rpm
Heartbeat-gui-2.1.4-9.el5.i386.rpm
Libnet-1.1.4-3.el5.i386.rpm
Heartbeat-gui-2.1.4-9.el5.x86_64.rpm
Perl-MailTools-1.77-1.el5.noarch.rpm
Heartbeat-ldirectord-2.1.4-9.el5.i386.rpm
Network and system environment requirements:
Network Planning:
192.168.10.0
192.168.20.0 This CIDR block is the heartbeat CIDR block.
Five hosts are required
The two hosts act as the heartbeat server, and the assigned IP address is
Master node: 192.168.10.1
Heartbeat address: 192.168.20.1
Secondary Contact: 192.168.10.2
Heartbeat address: 192.168.20.2
Floating IP Address:
192.168.10.10
1. Configure the Real Server first
1. This is because the web Cluster is implemented
First, install apache on the Real Server and test whether it can run.
# Yum install httpd
# Service httpd start
# Use a client to access the web service. If the service runs properly,
2. Hide arp Resolution on the Real Server and set the IP address to be declared.
# Echo 1>/proc/sys/net/ipv4/conf/lo/arp_ignore
# Echo 2>/proc/sys/net/ipv4/conf/lo/arp_announce
# Echo 1>/proc/sys/net/ipv4/conf/all/arp_ignore
# Echo 2>/proc/sys/net/ipv4/conf/all/arp_announce
3. Configure floating ip
# Ifconfig lo: 0 192.168.10.10 broadcast 192.168.10.10 netmask 255.255.255.255 up
# Ifconfig
Confirm that the configured floating IP address is normal. Of course, the IP address configured in this method disappears when the NIC is restarted.
Of course, you can create the ifcfg-lo: 0 file under/etc/sysconfig/network-scripts/and change the IP address to a floating IP address.
4. Add a route
# Route add-host 192.168.10.10 dev lo: 0
5. configure it on other real servers.
2. Configure and configure dual-machine Hot Standby heartbeat
1. Install the apache service on the master and secondary nodes.
# Yum install httpd
Create an index.html file under the root directory of the web. The content in the file is that when the real server cannot run normally, the primary and secondary nodes provide descriptive information and test whether apache can run normally.
# Service httpd start
Use a client to perform the test. After the test is completed, disable the service.
# Service httpd stop
# Chkconfig httpd off
2. Install the ipvsadm package
# Yum install ipvsadm
3. Configure ipvsadm
# Ipvsadm-A-t 192.168.10.10: 80-s wlc
# Ipvsadm-a-t 192.168.10.10: 80-r 192.168.10.3-w 1-g
# Ipvsadm-a-t 192.168.10.10: 80-r 192.168.10.4-w 2-g
4. install and configure heartbeat
# Yum-nogpgcheck localinstall *. rpm
Note: before installation, attach the disc because some software packages are required when installing heartbeat.
5 from/usr/share/doc/heartbeat-2.14/authkeys ha. cf haresource to/etc/ha. d/
# Cp/usr/share/doc/heartbeat-2.14/{authkeys, ha. cf, haresource}
/Etc/ha. d/
6. Modify the file authkeys
# Echo-ne "auth 1 \ nl shal">/etc/ha. d/authkeys
# Dd if =/dev/urandom bs = 512 count = 1 | openssl md5>/etc/ha. d/authkeys
# Vim/etc/ha. d/authkeys (check whether the key is appended to the file, and keep the key with 1 shal)
And set the authkeys File Permission to 0600.
# Chmod 0600 authkeys
7. Modify the master configuration file of heartbeat
# Vim/etc/ha. d/ha. cf
Make sure the following lines are enabled:
Debugfile/var/log/ha-debug
Logfile/var/log/ha-log
Logfacility local0
Keepalive 2
Deadtime 30
Warntime 10
Initdead 120
Udpport 694
Bcast eth1
Auto_failback
Node node1.example.com
Node node2.example.com
Respawn hacluster/usr/lib/heartbeat/ipfail
8 copy the file ldirectord. cf from the directory/usr/share/doc/heartbeat-ldirectord-2.1.4 to the directory/etc/ha. d/, change its name to heartbeat-ldirectord-lvs-httpd.cf, and modify
Make sure that the following line is removed.
Checktimeout = 3
Checkinterval = 1
Fallback = 127.0.0.1: 80
Autoreload = yes
Quiescent = yes
Virtual = 192.168.10.10: 80
Real = 192.168.10.3: 80 gate 1
Note: The weight behind the gate is
Real = 192.168.10.4: 80 gate 2
Fallback = 127.0.0.1: 80 gate
NOTE: If fallback is a real Server service that cannot run normally, the customer's request will be forwarded to the service on the node.
Service = http
Requestdomain.ldirectord.html"
Note: This is the file under the root directory of apache to check whether the server is running normally.
Receive = "GOOD"
Note: This information is the confirmation information returned to the master node. When the returned information is the above content, the service runs normally; otherwise, the service is down.
Protocol = tcp
Checktype = negotiate
Checkport = 80
Save the modification
Note: The configuration of ipvsadm is repeated in this section and in the third part. Of course, the configuration in step 3 can be omitted.

# Cp/usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord. cf/etc/ha. d/ldirectord-lvs-httpd.cf
9 modify the file haresource
# Vim/etc/ha. d/harecource
Add
Node1.example.com 192.168.10.10 ldirectord-lvs-httpd.cf Note: node1.example.com master node Host Name
192.168.10.10 is a floating address.
10 configure the secondary node as the primary node
11. create files under the apache root directory on the server.
.Ldirectord.html
And the content must contain
GOOD
12. Start the apache service on the server.
# Service httpd start
# Chkconfig httpd on
13 start the heartbeat Service of the master node first
# Service heartbeat start
# Chkconfig heartbeat on
Use ifconfig to check whether eth0: 0 appears. The IP address is
192.168.10.10, even if the floating address
When a floating address appears, start the secondary Node
# Service heartbeat start
# Chkconfig heartbeat on
14 on the master node
# Ipvsadm-L-n
View the lvs configuration and test it with the client.
15 Note: In heartbeat + lvs + ldirectord configuration, do you need to manually start the services on the server? Some people say that when heartbeat is started, I started the server on the server, but when I configured it, I started the service on the server manually, such as apache.
I hope you will point out the incorrect configuration.
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.