Experimental Information and topology:
Note: Centos 6.5 selinux–disabled iptables off
| ServerName |
Ipaddress Information |
| Lvsmaster |
172.16.100.10/24 |
| Lvsbackup |
172.16.100.11/24 |
| Vip |
172.16100.200/24 |
| RealServer1 |
172.16.100.100/24 |
| RealServer2 |
172.16.100.101/24 |
Configuring LVs Master & LVs Backup
# yum Install popt popt-devel popt-static libnl-devel libnl–y
# mkdir-p Mkdir/usr/local/src/lvs
# cd/usr/local/src/lvs/
Installing Ipvsadm
# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz
# tar ZXVF ipvsadm-1.26.tar.gz
# make && make install && echo "Install LVS OK"
Installing keepalived
# wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz
# tar ZXVF keepalived-1.2.13.tar.gz
# CD keepalived-1.2.13
#./configure && make && make install && echo "installkeepalived OK" | | echo "Install keepalived is failed"
Configure keepalived as the startup script:
# cp/usr/local/etc/rc.d/init.d/keepalived/etc/init.d/
# cp/usr/local/etc/sysconfig/keepalived/etc/sysconfig/
# mkdir/etc/keepalived
# cp/usr/local/etc/keepalived/keepalived.conf/etc/keepalived/
# cp/usr/local/sbin/keepalived/usr/sbin/
LVS Backup Configuration Ibid.
Master keepalived.conf configuration file:
! Configuration File for Keepalived
global_defs{
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
router_id Lvs_devel
}
vrrp_instancevi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 100
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1q2w3e4r5t6y
}
virtual_ipaddress {
172.16.100.200
}
}
VIRTUAL_SERVER172.16.100.200 80 {
Delay_loop 6
Lb_algo WRR
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 172.16.100.100 80 {
Weight 3
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 172.16.100.101 80 {
Weight 3
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}
Lvs Backup configuration file:
! Configuration File for Keepalived
global_defs{
Notification_email {
[Email protected]
}
Notification_email_from [email protected]
Smtp_server 127.0.0.1
router_id Lvs_devel
}
vrrp_instancevi_1 {
State BACKUP
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 99
Advert_int 1
Authentication {
Auth_type PASS
Auth_pass 1q2w3e4r5t6y
}
virtual_ipaddress {
172.16.100.200
}
}
VIRTUAL_SERVER172.16.100.200 80 {
Delay_loop 6
Lb_algo WRR
Lb_kind DR
Persistence_timeout 60
Protocol TCP
Real_server 172.16.100.100 80 {
Weight 3
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
Real_server 172.16.100.101 80 {
Weight 3
Tcp_check {
Connect_timeout 10
Nb_get_retry 3
Delay_before_retry 3
Connect_port 80
}
}
}
The two realserver configuration scripts are as follows:
#!/bin/bash
#
# Script to start LVS DR real server.
# Description:lvs DR Real Server
#
. /etc/rc.d/init.d/functions
vip=172.16.100.200
Host= '/bin/hostname '
Case "$" in
Start
# Start LVS-DR Real Server on the this machine.
/sbin/ifconfig Lo Down
/sbin/ifconfig lo 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
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
/sbin/route add-host $VIP Dev lo:0
;;
Stop
# Stop LVS-DR Real Server loopback device (s).
/sbin/ifconfig lo:0 Down
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
;;
Status
# Status of Lvs-dr Real server.
Islothere= '/sbin/ifconfig lo:0 | grep $VIP '
Isrothere= ' Netstat-rn | grep "lo:0" | grep $VIP '
if [! "$islothere"-O! " Isrothere "];then
# either the route or the lo:0 device
# not found.
echo "LVS-DR Real server Stopped."
Else
echo "LVS-DR Real server Running."
Fi
;;
*)
# Invalid entry.
echo "$0:usage: $ {start|status|stop}"
Exit 1
;;
Esac
# sh realserver.sh start
Access verification:
1. Arbitrarily shut down a Web server, the service can be accessed normally
2. Arbitrarily close one LVS, the service can be accessed normally
This article is from the "Sword Slave" blog, be sure to keep this source http://diudiu.blog.51cto.com/6371183/1568003
LVS + keepalived + httpd high Availability cluster (RPM)