In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to use LVS+heartbeat to build a high-availability web cluster. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Engaged in operation and maintenance for more than two years has not touched heartbeat, in the past, all applications involving HA are generally using keepalived. The reason is that heartbeat is so bulky that it is not as simple to configure as keepalived. The more complex an application is, the higher its failure concurrency rate must be and the longer it will take to recover. I had no choice but to contact heartbeat this time, because the company's online cluster environment is distributed using LVS+heartbeat for back-end applications. So we need to make up for the knowledge on heartbeat. There are some minor troubles in building heartbeat. Here we share the deployment process of lvs+heartbeat and the details we should pay attention to when building it.
Preparatory work:
1. Add the following information to the hosts file of master and backup systems
10.10.10.1 master
10.10.10.2 backup
2. Enable the IP forwarding function of master node and backup node system
# vi / etc/sysctl.conf
Net.ipv4.ip_forward = 1
First, install LVS and heartbeat
# tar zxvf ipvsadm-1.24.tar.gz
# cd ipvsadm-1.24
# ln-s / usr/src/kernels/2.6.18-164.el5-i686/ / usr/src/linux
# make & & make install
# tar zxvf libnet-1.1.2.1.tar.gz
# cd libnet
#. / configure
# make & & make install
# groupadd-g 694 haclient
# useradd-u 694-g haclient hacluster
# tar zxvf heartbeat-2.0.8.tar.gz
# cd heartbeat-2.0.8
#. / ConfigureMe configure
# make & & make install
Second, configure heartbeat and LVS
After installing heartbeat, the system generates a / etc/ha.d/ directory, which is used to store the configuration files related to heartbeat. There are many annotations in the configuration file that comes with Heartbeat. We manually write the configuration file here. There are four common configuration files in heartbeat, which are:
Ha.cf:heartbeat main configuration file
Ldirectord.cf: resource management file
Haresources: local resource fil
Authkeys: authentication file
1. Configure ha.cf
# vi / etc/ha.d/ha.cf
Logfile / var/log/ha.log # Log File placement path
Keepalive 2 # heartbeat rate, default is seconds
Deadtime 10 # determines the time of death of a node
Warntime 5 # warning time
At least twice as much as initdead 30 # deadtime
Udpport 694 # listening port
Bcast eth2 # Network interface used by heartbeat
Auto_failback off # whether to switch to the primary node when the primary node returns to normal
Node master # Primary Node
Node backup # standby node
Ping_group group1 192.168.1.103 192.168.1.104 # real server address
Respawn hacluster / usr/lib/heartbeat/ipfail
Apiauth ipfail gid=haclient uid=hacluster
2. Configure ldirectord.cf
# vi / etc/ha.d/ldirectord.cf
Checktimeout=5 # detect timeout
Checkinterval=1 # Test time
Whether autoreload=yes # configuration files are loaded automatically when they are changed
Logfile= "/ var/log/ldirectord.log" # ldirectord log path
Whether to retain the configuration of the real server after quiescent=no # detects the real server exception
Virtual=192.168.1.100:80 # VIP
Real=192.168.1.103:80 gate # real server
Real=192.168.1.104:80 gate # real server
Service=http
Checkport=80
Protocol=tcp
Persistent=600 # connection session duration
Scheduler=wlc # LVS load algorithm
Checktype=negotiate # determines whether the service is normal through interaction
3. Configure haresources
# vi / etc/ha.d/haresources
Master IPaddr::192.168.1.100 ipvsadm ldirectord
Note: master is the host name of the LVS master node; IPaddr is the VIP;ipvsadm ldirectord and the application to be monitored
4. Configure authkeys
# vi / etc/ha.d/authkeys
Auth 3
3 md5 test
# chmod 600 / etc/ha.d/authkeys
Note: permissions must be set to 600, otherwise heartbeat will report an error when it starts.
5. Configure IPVS
# vi / etc/sysconfig/ipvsadm
-A-t 192.168.1.100 virtual 80-s wlc-p 600
-a-t 192.168.1.100 VRO 80-r 192.168.1.103 RV 80-g
-a-t 192.168.1.100 purl 80-r 192.168.0.104 purl 80-g
Note:-p 600 means that the session duration is 600 seconds, which should be consistent with the ldirectord.cf file configuration.
6. Start heartbeat
# / etc/init.d/heartbeat start
# echo "/ etc/init.d/heartbeat start" > > / etc/rc.local
Note: pay attention to three points after starting heartbeat: ①: check whether the system UDP694 is started; ②: observe the heartbeat log to see if there is any error message output. The error message in the log when starting heartbeat this time is as follows
ResourceManager [11840]: 2011/04/09_19:56:51 ERROR: Return code 2 from / etc/init.d/ldirectord
ResourceManager [11840]: 2011/04/09_19:56:51 ERROR: Resource script for ldirectord probably not LSB-compliant.
Later, after troubleshooting, it was found that the system could not start ldirectord through heartbeat. The error message is as follows:
Can't locate LWP/UserAgent.pm
The reason is that due to the lack of corresponding perl modules, ldirectord can be started normally after libwww-perl and perl-MailTools are installed. ③ checks whether the network card is loaded with VIP, and starts heartbeat for about 15 seconds. The system will automatically generate VIP and automatically load it into the eth0:0 network card, which can be viewed using ifconfig.
7. Check whether LVS has real server loaded.
# watch ipvsadm-ln
Every 2.0s: ipvsadm-ln Tue Apr 12 00:33:58 2011
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.100:80 wlc persistent 600
-> 192.168.1.104 Route 80 Route 100 0
-> 192.168.1.103 Route 80 Route 100 0
At present, LVS does not handle access distribution properly, because now LVS only knows how to direct requests to the back-end server, but the back-end server does not know how to handle returned requests. Therefore, you also need to bind the LVS server on real server
Note: the installation and configuration of the environment lvs+heartbeat on master and backup nodes are exactly the same, so I will not repeat the installation and configuration of backup nodes here.
Configure real server (web1 and web2)
Write the following script on web1 and web2 respectively, and then start it. After startup, the system will automatically bind a virtual IP to the loopback interface.
# vi / etc/sysconfig/real.sh
#! / bin/bash
# description: start realserver
VIP=192.168.1.100
/ etc/rc.d/init.d/functions
Case "$1" in
Start)
Echo "start LVS of REALServer"
/ sbin/ifconfig lo:0$ VIP broadcast $VIP netmask 255.255.255.255 up
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
Stop)
/ sbin/ifconfig lo:0 down
Echo "close LVS Directorserver"
Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_ignore
Echo "0" > / proc/sys/net/ipv4/conf/lo/arp_announce
Echo "0" > / proc/sys/net/ipv4/conf/all/arp_ignore
Echo "0" > / proc/sys/net/ipv4/conf/all/arp_announce
*)
Echo "Usage: $0 {start | stop}"
Exit 1
Esac
# chmod + x / etc/sysconfig/real.sh
# / etc/sysconfig/real.sh start
# echo "/ etc/sysconfig/real.sh start" > > / etc/rc.local
IV. Testing
1. Disable any web service on web1 or web1 to see if it is normal to access VIP.
2. Stop the heartbeat process on the master node to see whether the VIP will automatically switch to the backup node; restore the master node, stop the heartbeat process on the backup, and see whether the VIP will automatically switch to the master node
3. Shut down the master node to see if VIP will automatically switch to backup; to enable master node, close backup, and see whether VIP will automatically switch to master node. Take a closer look at the heartbeat log when testing
Note: the installation and configuration of the backup node and the bmaster node are the same in this environment, so I will not repeat the configuration of the backup node here.
This is the end of the article on "how to use LVS+heartbeat to build a highly available web cluster". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.