LVS配置实例
环境描述:本文在配置LVS时使用三台linux,虚拟VIP:172.18.3.209
一台做Directorserver(172.18.3.208)
两台做realserver(172.18.3.205,172.18.3.207)
在配置lvs+heartbeat时,又添加了一台(192.168.8.3)做为备份主节点Virtual IP: 192.168.8.11
Load Balancer: 172.18.3.208
Backup: 192.168.8.3 ...............还没有实践
Real Server 1: 172.18.3.205
Real Server 2: 172.18.3.207
软件
ipvsadm-1.24.tar.gz:
tar zxvf ipvsadm-1.24.tar.gz
cd ipvsadm-1.24
make && make install
注意在make时可能会出现很多错误的信息,请按照如下操作就可以心编译正常
ln -s /usr/src/kernels/2.6.11-1.1369_FC4-i686/ /usr/src/linux
在进行编译就不会出错了
======================================
配置基于DR模式Lvs集群
172.18.3.208
[root@localhost lvs]# cat /usr/local/lvs/LvsDR
#!/bin/sh
#VIP=192.168.8.11
VIP=172.18.3.209
#RIP1=192.168.8.6
RIP1=172.18.3.205
RIP2=172.18.3.207
/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
=======================================
172.18.3.205
[root@localhost lvs]# cat /usr/local/lvs/realserver
#!/bin/sh
#VIP=192.168.8.11
VIP=172.18.3.209
/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
================================================
172.18.3.207
[root@localhost lvs]# cat /usr/local/lvs/realserver
#!/bin/sh
#VIP=192.168.8.11
VIP=172.18.3.209
/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
==================================
[root@localhost lvs]# cat /usr/local/apache/htdocs/index.html
This is realserver1
[root@localhost lvs]# cat /usr/local/apache/htdocs/index.html
This is realserver2
分别启动服务
./LvsDR start
./realserver
./realserver
启动apache
访问: http://172.18.3.209
验证的时候可以人为造成负载过高,这样就从一台跳转到另一台
find / -name aaaaaaaaa
不断刷新会出现This is realserver1 This is realserver2
目录 返回
首页