Environment Description: This article uses three linux instances, virtual VIP: 192.168.8.11, When configuring LVS.
One is used as the Directorserver (192.168.8.2), and the operating system RedhatAS4
The two servers are used as the realserver (192.168.8.5, 192.168.8.6) Operating System RedhatAS4.
When configuring lvs + heartbeat, another (192.168.8.3) is added as the backup master node, and the operating system Fedora7
Virtual IP: 192.168.8.11
Load Balancer: 192.168.8.2
Backup: 192.168.8.3
Real Server 1: 192.168.8.5
Real Server 2: 192.168.8.6
Software List:
Ipvsadm-1.24.tar.gz:
Http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
Ipvsadm-1.24-8.1.i386.rpm
Ftp://rpmfind.net/linux/fedora/releases/7/Everything/i386/ OS /Fedora/ipvsadm-1.24-8.1.i386.rpm
Libnet.tar:
Stable http://www.packetfactory.net/libnet/ version: 1.1.2.1
Heartbeat-2.0.2.tar.gz:
Http://linux-ha.org/download/heartbeat-2.0.8.tar.gz
2.6 The kernel has been integrated with the IPVS kernel, so you do not need to re-compile the kernel.
This cluster is configured in the following situations:
1. Configure the DR-mode Lvs Cluster
1. Download The ipvsadm Management Program
Http://www.linuxvirtualserver.org/software/
Note that the corresponding kernel version
Ipvsadm-1.24.tar.gz
Tar zxvf ipvsadm-1.24.tar.gz
Cd ipvsadm-1.24
Make & make install
Note that many errors may occur during make. follow the steps below to compile properly.
Ln-s/usr/src/kernels/2.6.9-22. EL-i686 // usr/src/linux
Cd ipvsadm-1.24
Make & make install
2. Configure the VIP script
[Root @ test7 chang] # vi LvsDR
#!/bin/sh VIP=192.168.8.11 RIP1=192.168.8.6 RIP2=192.168.8.5 /etc/rc.d/init.d/functions case "$1" in start) echo "start LVS of DirectorServer" #Set the Virtual IP Address /sbin/ifconfig eth0:1 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev eth0:1 #Clear IPVS Table /sbin/ipvsadm -C #Set Lvs /sbin/ipvsadm -A -t $VIP:80 -s rr /sbin/ipvsadm -a -t $VIP:80 -r $RIP1:80 -g /sbin/ipvsadm -a -t $VIP:80 -r $RIP2:80 -g #Run Lvs /sbin/ipvsadm ;; stop) echo "close LVS Directorserver" /sbin/ipvsadm -C ;; *) echo "Usage: $0 {start|stop}" exit 1 esac |
Note:-s rr uses the wheel call algorithm and you can select the corresponding algorithm. The default value is-wlc, and-g uses the direct routing mode of lvs working DR, ipvsadm-h to view help ).
3. Configure the realserver script
[Root @ test5 chang] # vi realserver
#!/bin/sh VIP=192.168.8.11 /sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up /sbin/route add -host $VIP dev lo:0 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 sysctl –p |
If there are multiple realservers, you can directly add them, and then start this script.
Test: Start the httpd service on the realserver respectively.
Run echo "This is realserver1">/var/www/html/index.html in realserver1.
Run echo "This is realserver2">/var/www/html/index.html in realserver2.
Open the IE browser and enter http: // 192.168.8.11. You can see This is realserver1 and This is realserver2.