在CentOS6.5下配置安装LVS

先上一个图,在内网测试机上安装了一个虚拟机,已经安装好了CentOS

乖乖连wget都没有安装,先安装wget吧

sudo yum install wget

 

 

下载LVS

wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.26.tar.gz

解压

tar zxvf ipvsadm-1.26.tar.gz
cd ipvsadm-1.26

 

make && make install

 

make -C libipvs
make[1]: Entering directory `/root/ipvsadm-1.26/libipvs'
gcc -Wall -Wunused -Wstrict-prototypes -g -fPIC -DLIBIPVS_USE_NL  -DHAVE_NET_IP_VS_H -c -o libipvs.o libipvs.c
make[1]: gcc: Command not found
make[1]: *** [libipvs.o] Error 127
make[1]: Leaving directory `/root/ipvsadm-1.26/libipvs'
make: *** [libs] Error 2

 

出错了,原来是没有找到gcc 哪么安装gcc吧

yum install gcc

 

Complete! 安装成功再使用

make && make install

 

又出错了

libipvs.c:1051: error: ‘NL_OK’ undeclared (first use in this function)
libipvs.c: In function ‘ipvs_get_daemon’:
libipvs.c:1071: error: ‘NLM_F_DUMP’ undeclared (first use in this function)
libipvs.c:1072: error: too many arguments to function ‘ipvs_nl_send_message’
make[1]: *** [libipvs.o] Error 1
make[1]: Leaving directory `/root/ipvsadm-1.26/libipvs'
make: *** [libs] Error 2

 看看象是lib类型库的问题,安装以后库

yum install libnl*
make
ipvsadm.c:114:18: error: popt.h: No such file or directory
ipvsadm.c: In function ‘parse_options’:
ipvsadm.c:365: error: ‘poptContext’ undeclared (first use in this function)
ipvsadm.c:365: error: (Each undeclared identifier is reported only once
ipvsadm.c:365: error: for each function it appears in.)
ipvsadm.c:365: error: expected ‘;’ before ‘context’
ipvsadm.c:367: error: array type has incomplete element type
ipvsadm.c:368: error: ‘POPT_ARG_NONE’ undeclared (first use in this function)
ipvsadm.c:383: error: ‘POPT_ARG_STRING’ undeclared (first use in this function)
ipvsadm.c:394: error: ‘POPT_ARGFLAG_OPTIONAL’ undeclared (first use in this function)
ipvsadm.c:432: error: ‘context’ undeclared (first use in this function)
ipvsadm.c:432: warning: implicit declaration of function ‘poptGetContext’
ipvsadm.c:435: warning: implicit declaration of function ‘poptGetNextOpt’
ipvsadm.c:661: warning: implicit declaration of function ‘poptBadOption’
ipvsadm.c:661: error: ‘POPT_BADOPTION_NOALIAS’ undeclared (first use in this function)
ipvsadm.c:669: warning: implicit declaration of function ‘poptStrerror’
ipvsadm.c:670: warning: implicit declaration of function ‘poptFreeContext’
ipvsadm.c:677: warning: implicit declaration of function ‘poptGetArg’
ipvsadm.c:367: warning: unused variable ‘options_table’
make: *** [ipvsadm.o] Error 1

又出现了新问题,看起来像是popt类型库的问题

yum install popt*
make && make install

安装成功!

接下来安装 Keepalived

下载

wget http://www.keepalived.org/software/keepalived-1.2.4.tar.gz
tar zxvf keepalived-1.2.4.tar.gz
cd keepalived-1.2.4
 ./configrue
!!! OpenSSL is not properly installed on your system. !!!

原来是OpenSSL没有安装,哪么安装OpenSSL吧

yum install openssl-devel

再次 ./configure 成功

Keepalived configuration
------------------------
Keepalived version       : 1.2.4
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto  -lnl
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
IPVS use libnl           : Yes
Use VRRP Framework       : Yes
Use VRRP VMAC            : Yes
Use Debug flags          : No

开始安装Keepalived

make && make install

安装成功

make -C genhash install
make[1]: Entering directory `/root/keepalived-1.2.4/genhash'
install -d /usr/local/bin
install -m 755 ../bin/genhash /usr/local/bin/
install -d /usr/local/share/man/man1
install -m 644 ../doc/man/man1/genhash.1 /usr/local/share/man/man1
make[1]: Leaving directory `/root/keepalived-1.2.4/genhash'

开启路由转发

vi /etc/sysctl.conf

net.ipv4.ip_forward = 0

修改成

net.ipv4.ip_forward = 1

:wq保存

刷新一下系统变量,使配置值生效

sysctl -p
net.ipv4.ip_forward = 1

看到了输出变量为1

接下来

配置Real Server

由于我们的Real Server是windows2008主机

需要增加一个虚拟网卡

 

配置网卡地址为

192.168.1.14

子网掩码为

255.255.255.255

在windows 2008执行以下脚本

netsh interface ipv4 set interface "intranet" weakhostreceive=enabled
netsh interface ipv4 set interface "intranet" weakhostsend=enabled
netsh interface ipv4 set interface "loopback" weakhostreceive=enabled
netsh interface ipv4 set interface "loopback" weakhostsend=enabled

 

接下来我们用 ipvsadm 来配置负载机上的vip

先在负载机上增加一个vip的网卡

ifconfig eth0:0 192.168.1.14 broadcast 192.168.1.14 netmask 255.255.255.255 up

route add -host 192.168.1.14 dev eth0:0

ipvsadm -A -t 192.168.1.14 -s wrr

ipvsadm -a -t 192.168.1.14:80 -r 192.168.1.16:80 -g

ipvsadm -a -t 192.168.1.14:80 -r 192.168.1.17:80 -g

ok.. 明天继续配置

 

posted @ 2015-09-22 14:18  徐小朝  阅读(1117)  评论(0编辑  收藏  举报