LVS+Keepalived
、 load balancingtechnology?
1、systemhigh availability
2、 systemextensibility
3、 load balancing
LVS+keepalivedImplementation,LVS load balancing,keepalivedhealth check,failover,systemavailability!Architecture system,Addrealserver,lvs configuration file,ImplementationConfiguration!
、LVS+Keepalived
1、 LVS
LVSopen-sourcesoftware,ImplementationLINUXplatformload balancing。LVSLinux Virtual Server,Linuxvirtual server。CurrentlyIP technology(VS/NAT、VS/TUNVS/DR);scheduling algorithm(rr,wrr,lc,wlc,lblc,lblcr,dh,sh)。
2、 keepalived
Keepalived lvs ,FunctionsImplementationfaultload balancingfailure ,systemavailability
、LVS+keepalivedload balancingArchitecture:
、LVS+keepalivedInstallationConfiguration
1. ConfigurationEnvironment
System OS:CentOS release 5.6
Software:ipvsadm-1.24.tar.gz, keepalived-1.1.19.tar.gz
2.
|
|
IP
|
|
LVS-Master
|
192.168.3.20
|
|
LVS-BACKUP
|
192.168.3.21
|
|
LVS-VIP
|
192.168.3.50 / 192.168.3.51
|
|
Web1
|
192.168.3.45 /192.168.3.47
|
|
Web2
|
192.168.3.46 / 192.168.3.48
|
Note: :CentOS 6.0Installationipvsadm 1.26
CentOS 5.xInstallationipvsadm 1.26。ipvsadm 1.26kernel 2.6.28version。
IfCentOS 5.XCompilationInstallationipvsadm,DownloadInstallation1.24
systemEnvironmentInstallationtool,gccInstallation。CentOS 5.x
IfCentOS 5.XCompilationInstallationipvsadm,DownloadInstallation1.24
systemEnvironmentInstallationtool,gccInstallation。CentOS 5.x
、Installation:
1、InstallationdependencyCreate:
#yum check-update
#yum -y install ibnl* popt*
1、InstallationdependencyCreate:
#yum check-update
#yum -y install ibnl* popt*
2、cenos5.X2.6.18-238.el5,However/usr/src/kernels2.6.18-238.el6;CompilationInstallation,kernel.orgmaintenance。
#yum -y install kernel-devel
#yum -y update kernel
3、Installation:
#modprobe ip_vs //ip_vsmodule
#lsmod |grep ip_vs //success。
ip_vs 122113 0
#ln -s /usr/src/kernerls/2.6.18-274.el5-x86_64/ /usr/src/linux //file
#cp /usr/src/kernels/2.6.18-274.el5/include/net/ip_vs.h /usr/inclide/net/ //,Installationipvsadm*.hfile
#yum -y install openssl openssl-devel //Installationkeepalived
,InstallationsoftwaredependencyfileInstallation。For instancegcc gcc-c++。Downloadipvsadmkeepalived
4、Downloadipvsadm 1.24
For CentOS 5.x
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
For CentOS 6.x
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
For CentOS 6.x
#cd /usr/src/ipvsadm-1.24/
# make && make install
2、DownloadInstallationInstallationkeepalived
# tar zxvf keepalived-1.1.19.tar.gz -C /usr/src/
# cd /usr/src/keepalived-1.1.19/
# ./configure –prefix=/usr/local/keepalived
Installation:
Keepalived configuration
————————
Keepalived version : 1.1.19
Compiler : gcc
Compiler flags : -g -O2
Extra Lib : -lpopt -lssl -lcrypto
Use IPVS Framework : Yes
IPVS sync daemon support : Yes
Use VRRP Framework : Yes
Use Debug flags : No
# make && make install
# mkdir -p /etc/keepalived
# cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
# cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
3、 Configurationkeepadlived LVS-Master()configuration file:
# vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected] #email notification
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS1 # Settingslvsid,network
}
vrrp_sync_group test { #Settingsvrrp
group {
xxoo
}
}
vrrp_instance xxoo {
state MASTER #Settingslvs,MASTERBACKUP,
interface eth0 #Settingsserviceinterface
lvs_sync_daemon_inteface eth0 #Settingslvsinterface
virtual_router_id 51 #Settings
priority 150 #Settings,,
advert_int 5 #Settingssynchronize
authentication { #SettingsPassword
auth_type PASS
auth_pass 1111
}
virtual_ipaddress { #Settingslvs vip
192.168.3.50
}
}
virtual_server 192.168.3.50 80 {
delay_loop 6 #health check
lb_algo rr #load balancingscheduling algorithm
lb_kind DR #load balancing
nat_mask 255.255.255.0
persistence_timeout 20 #(IPconnection60realserver) protocol TCP #(TCPcheckrealserver)
real_server 192.168.3.45 80 {
weight 3 #Settings
TCP_CHECK {
connect_timeout 5 #(5responsetimeout)
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.3.47 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
4、 Configurationkeepadlived LVS-BACKUP()configuration file:
# vi /etc/keepalived/keepalived.conf:
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS2
}
vrrp_sync_group test {
group {
xxoo
}
}
vrrp_instance xxoo {
state BACKUP
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 100
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.50
}
}
virtual_server 192.168.3.50 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 20
protocol TCP
real_server 192.168.3.45 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.3.47 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
5、webserver CreatescriptStart:
# vi /etc/init.d/lvs_keepd.sh
# chmod a+x /etc/init.d/lvs_keepd.sh
# /etc/init.d/lvs_keepd.sh start
#!/bin/bash
# description: Config realserver lo and apply noarp
SNS_VIP=192.168.3.50
/etc/rc.d/init.d/functions
case "$1" in
start)
ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
/sbin/route add -host $SNS_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 >/dev/null 2>&1
echo "RealServer Start OK"
;;
stop)
ifconfig lo:0 down
route del $SNS_VIP >/dev/null 2>&1
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 "RealServer Stoped"
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
6、Start:
# /etc/init.d/keepalived start
# ip add list
#watch ipvsadm –ln lvsservice
#tail -f /var/log/message Log,,TestingLVSload balancinghigh availability
Masterserverkeepalivedservice,BAKCUPserverservice
: VIP web Configuration、Configuration:
! Configuration File for keepalived
global_defs {
notification_email {
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS1
}
vrrp_sync_group test {
group {
xxoo
xxoo1
}
}
vrrp_instance xxoo {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 51
priority 150
advert_int 5
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.3.50
}
}
virtual_server 192.168.3.50 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 20
protocol TCP
real_server 192.168.3.45 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.3.47 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
vrrp_instance xxoo1 {
state MASTER
interface eth0
lvs_sync_daemon_inteface eth0
virtual_router_id 52
priority 150
advert_int 5
authentication {
auth_type PASS
auth_pass 111111
}
virtual_ipaddress {
192.168.3.55
}
}
virtual_server 192.168.3.55 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
persistence_timeout 20
protocol TCP
real_server 192.168.3.46 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
real_server 192.168.3.48 80 {
weight 3
TCP_CHECK {
connect_timeout 5
nb_get_retry 3
delay_before_retry 3
connect_port 80
}
}
}
Testing success ConfigurationShare!!
This article is from “” Blog,http://s2t148.blog.51cto.com/3858027/888263
