简介:LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统。本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一。
VIP:1.1.1.99
DIP:1.1.1.24
RIP:1.1.1.11
LVS配置:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
yum install gcc gcc-c++ kernel kernel-devel libnl libnl-devel popt-devel popt-static -y ln -s /usr/src/kernels/`uname -r` /usr/src/linux mkdir /byrd/tools -p cd /byrd/tools/ wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz tar -zxf ipvsadm-1.26.tar.gz cd ipvsadm-1.26 ln -s /usr/src/kernels/`uname -r` /usr/src/linux make && make install =============================== ipvsadm #modprobe ip_vs等价 lsmod | grep ip_vs ifconfig eth0:0 1.1.1.99/32 up ipvsadm --set 30 5 60 ipvsadm -A -t 1.1.1.99:80 -s wrr ipvsadm -a -t 1.1.1.99:80 -r 1.1.1.11:80 -g -w 1 =============================== |
安装shell(安装kernel和kernel-devel后重新启动下计算机,不然ln的时候会有问题):
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
#!/bin/bash # Author:Byrd # Version:0.1 # Site:note.t4x.org # Contact:root#t4x.org #CEN_VER=`cat /etc/redhat-release | awk '{print $3}' | cut -c 1` yum install gcc gcc-c++ kernel kernel-devel libnl libnl-devel popt-devel popt-static -y CEN_VER=`rpm -q centos-release | awk -F '-' '{print $3}'` if [ ${CEN_VER} -ne 6 -a ${CEN_VER} -ne 7 ]; then echo "For Centos 6 or 7" exit 1 fi DON_DIR=/byrd/tools GET_LVS=http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz [ ! -d ${DON_DIR} ] && mkdir ${DON_DIR} -p cd ${DON_DIR} if [ ! -f `basename ${GET_LVS}` ]; then wget ${GET_LVS} tar -zxf ipvsadm-1.26.tar.gz cd ipvsadm-1.26 ln -s /usr/src/kernels/`uname -r` /usr/src/linux if [ -s /usr/src/linux ]; then echo "right" </dev/null 2>&1 else echo "Please chk kernels config" exit 1 fi make && make install RETURN_VALUE=$? if [ $RETURN_VALUE -eq 0 ]; then echo "LVS Installation Success" else echo "LVS Installation Failed" fi #modprobe ip_vs else tar -zxf ipvsadm-1.26.tar.gz cd ipvsadm-1.26 ln -s /usr/src/kernels/`uname -r` /usr/src/linux if [ -s /usr/src/linux ]; then echo "right" > /dev/null 2>&1 else echo "Please chk kernels config" exit 1 fi make && make install RETURN_VALUE=$? if [ $RETURN_VALUE -eq 0 ]; then echo "LVS Installation Success" else echo "LVS Installation Failed" fi #ipvsadm fi #if [ `lsmod | grep ip_vs | wc -l` -gt 0 ]; then # echo "LVS Installation Success" #else # echo "LVS Installation Failed" #fi |
REALSERVER 配置:
0 1 2 3 4 |
ifconfig lo:11 1.1.1.99/32 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 |
实操过程:
LB操作:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
[root@LVS-GS001 ~]# uname -a Linux LVS-GS001 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@LVS-GS001 ~]# yum install kernel kernel-devel gcc gcc-c++ wget -y [root@LVS-GS001 ~]# yum install libnl libnl-devel popt-devel popt-static -y #2.6版本需要的包 [root@LVS-GS001 ~]# reboot [root@LVS-GS001 ~]# uname -r 2.6.32-431.23.3.el6.x86_64 [root@LVS-GS001 ~]# ln -s /usr/src/kernels/2.6.32-431.23.3.el6.x86_64/ /usr/src/linux [root@LVS-GS001 ~]# mkdir /byrd/tools -p [root@LVS-GS001 ~]# cd /byrd/tools/ [root@LVS-GS001 tools]# wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz [root@LVS-GS001 tools]# tar zxf ipvsadm-1.24.tar.gz [root@LVS-GS001 tools]# cd ipvsadm-1.24 [root@LVS-GS001 ipvsadm-1.24]# make && make install [root@LVS-GS001 ipvsadm-1.24]# echo $? 0 [root@LVS-GS001 ipvsadm-1.24]# ipvsadm IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn [root@LVS-GS001 ipvsadm-1.24]# lsmod | grep ip_vs ip_vs 125092 0 libcrc32c 1246 1 ip_vs ipv6 318183 142 ip_vs,ip6t_REJECT,nf_conntrack_ipv6,nf_defrag_ipv6 [root@LVS-GS001 ipvsadm-1.24]# ifconfig eth0:0 1.1.1.99/32 up #/配置一个vip [root@LVS-GS001 ipvsadm-1.24]# ipvsadm --set 30 5 60 #--set tcp tcpfin udp [root@LVS-GS001 ipvsadm-1.24]# ipvsadm -A -t 1.1.1.99:80 -s wrr -p 20 #ipvsadm --help [root@LVS-GS001 ipvsadm-1.24]# ipvsadm -a -t 1.1.1.99:80 -r 1.1.1.11:80 -g -w 1 |
REALSERVER 实操:
0 1 2 3 4 |
[root@Lamp ~]# ifconfig lo:11 1.1.1.99/32 up [root@Lamp ~]# echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore [root@Lamp ~]# echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce [root@Lamp ~]# echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore [root@Lamp ~]# echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce |
错误解决:
0 1 2 |
make[1]: *** [libipvs.o] Error 1 make[1]: Leaving directory `/byrd/tools/ipvsadm-1.26/libipvs' make: *** [libs] Error 2 |
0 1 |
ln -s /usr/src/kernels/`uname -r` /usr/src/linux #检查软连接是否配置正确。 yum install libnl libnl-devel |
0 1 |
ipvsadm.c:1383: warning: field width should have type ‘int’, but argument 2 has type ‘size_t’ make: *** [ipvsadm.o] Error 1 |
0 |
yum install popt-devel |
0 1 |
collect2: ld returned 1 exit status make: *** [ipvsadm] Error 1 |
0 |
yum install popt-static |
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!