LVS安装
ipvsadm配置过程中链接文件下无内核,先配置出内核
cdusr/src/kernel/
[root@bogonkernels]# rpm -qa|grep kernel
kernel-headers-2.6.18-194.el5
kernel-2.6.18-194.el5
[root@bogonkernels]# yum -y install kernel-devel
1)检查内核模块,看一下ip_vs 是否被加载
# lsmod |grep ip_vs
ip_vs 35009 0
如果没有显示,则说明没有加载,执行命令 modprobe ip_vs 就可以把ip_vs模块加载到内核
#modprobe ip_vs 然后再查看就有了。
2)安装ipvsadm
查看内核版本 #uname -r
2.6.32-573.1.1.el6.i686
先把目录/usr/src/kernels/2.6.32-573.1.1.el6.i686链接为/usr/src/linux,命令如下
ln -s/usr/src/kernels/2.6.32-573.1.1.el6.i686 /usr/src/linux
在usr/local/下解压ipvsadm的安装包
[root@localhost ~]# cd /usr/local/
[root@localhost local]# tar –zxvf ipvsadm-1.24.tar.gz
[root@localhost local]# cd ipvsadm-1.24
[root@localhost ipvsadm-1.24]# make
解压ipvsadm-1.24.tar.gz,执行"make;但是报错了,类似的错误信息大概如下
make -C libipvs
make[1]: Entering directory`/usr/src/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
In file included from libipvs.h:13,
from libipvs.c:23:
ip_vs.h:15:29: error: netlink/netlink.h: Nosuch file or directory
ip_vs.h:16:31: error: netlink/genl/genl.h: Nosuch file or directory
ip_vs.h:17:31: error: netlink/genl/ctrl.h: Nosuch file or directory
In file included from libipvs.h:13,
from libipvs.c:23:
ip_vs.h:520: error: array type has incompleteelement type
ip_vs.h:521: error: array type has incompleteelement type
libipvs.c:57: warning: implicit declaration offunction ‘nlmsg_alloc’
libipvs.c:57: warning: assignment makes pointerfrom integer without a cast
libipvs.c:61: warning: implicit declaration offunction ‘genlmsg_put’
libipvs.c:61: error: ‘NL_AUTO_PID’ undeclared(first use in this function)
libipvs.c:61: error: (Each undeclaredidentifier is reported only once
libipvs.c: In function ‘ipvs_add_service’:
libipvs.c:255: error: too many arguments tofunction ‘ipvs_nl_send_message’
libipvs.c: In function ‘ipvs_update_service’:
libipvs.c:276: error: too many arguments tofunction ‘ipvs_nl_send_message’
libipvs.c: In function ‘ipvs_del_service’:
libipvs.c:296: error: too many arguments tofunction ‘ipvs_nl_send_message’
libipvs.c: In function ‘ipvs_zero_service’:
libipvs.c:473: warning: assignment makespointer from integer without a cast
libipvs.c:483: error: too many arguments to function‘ipvs_nl_send_message’
libipvs.c: In function ‘ipvs_stop_daemon’:
libipvs.c:504: warning: assignment makespointer from integer without a cast
libipvs.c:514: error: too many arguments tofunction ‘ipvs_nl_send_message’
libipvs.c: At top level:
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 tofunction ‘ipvs_nl_send_message’
make[1]: *** [libipvs.o] Error 1
make[1]: Leaving directory`/usr/src/ipvsadm-1.26/libipvs'
make: *** [libs] Error 2
解决:[root@localhost ipvsadm-1.24]#yum install libnl* libpopt*
再次make,还是有报错
类似如 /usr/src/ipvsadm-1.26/ipvsadm.c:667: undefined reference to `poptStrerror'
/usr/src/ipvsadm-1.26/ipvsadm.c:667: undefinedreference to `poptBadOption'
/usr/src/ipvsadm-1.26/ipvsadm.c:670: undefinedreference to `poptFreeContext'
/usr/src/ipvsadm-1.26/ipvsadm.c:677: undefinedreference to `poptGetArg'
/usr/src/ipvsadm-1.26/ipvsadm.c:678: undefinedreference to `poptGetArg'
/usr/src/ipvsadm-1.26/ipvsadm.c:679: undefinedreference to `poptGetArg'
/usr/src/ipvsadm-1.26/ipvsadm.c:690: undefinedreference to `poptGetArg'
/usr/src/ipvsadm-1.26/ipvsadm.c:693: undefinedreference to `poptFreeContext'
collect2: ld returned 1 exit status
make: *** [ipvsadm] Error 1
解决:[root@localhost ipvsadm-1.24]# yuminstall popt-static (ftp://ftp.muug.mb.ca/mirror/centos/6.3/os/x86_64/Packages/popt-static-1.13-7.el6.x86_64.rpm)
再次
[root@localhost ipvsadm-1.24]# make
通过,然后
[root@localhost ipvsadm-1.24]# makeinstll
完成安装
安装 配置keepalived
./configure会出现OPENSSL错误,
所以首先
[root@localhost~]#yum install -y openssl openssl-devel
然后执行下面的命令:
[root@localhost~]# cd /usr/local
[root@localhostlocal]# tar –zxvf keepalived-1.2.18.tar.gz
[root@localhostlocal]# cd keepalived-1.2.18
[root@localhostkeepalived-1.2.18]# ./configure
[root@localhostkeepalived-1.2.18]# make
[root@localhostkeepalived-1.2.18]# make install
完成安装
配置keepalived
# cp/usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/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/
(1)在DR1上配置keepalived:
最简单的方法:先在本地记事本中,手工创建keepalived.conf。上传到/etc/keepalived/keepalived.conf中,替换原有即可!
!Configuration File for keepalived
global_defs{
notification_email {
acassen@firewall.loc #设置报警邮件地址,可以设置多个,每行1个,
failover@firewall.loc #需开启邮件报警及本机的Sendmail服务。
sysadmin@firewall.loc
}
notification_email_fromAlexandre.Cassen@firewall.loc
smtp_server 192.168.200.1 #设置SMTPServer地址;
smtp_connect_timeout 30
router_id LVS_DEVEL
}
########VRRP Instance########
vrrp_instanceVI_1 {
state MASTER #指定Keepalived的角色,MASTER为主机服务器,BACKUP为备用服务器
interface eth0 #BACKUP为备用服务器
virtual_router_id 51
priority 100 #定义优先级,数字越大,优先级越高,主DR必须大于备用DR。
advert_int 1
authentication {
auth_type PASS #设置验证类型,主要有PASS和AH两种
auth_pass 1111 #设置验证密码
}
virtual_ipaddress {
192.168.0.200 #设置主DR的虚拟IP地址(virtualIP),可多设,但必须每行1个
}
}
########Virtual Server########
virtual_server192.168.0.200 80 { #注意IP地址与端口号之间用空格隔开
delay_loop 6 #设置健康检查时间,单位是秒
lb_algo rr #设置负载调度算法,默认为rr,即轮询算法,最优秀是wlc算法
lb_kind DR #设置LVS实现LB机制,有NAT、TUNN和DR三个模式可选
nat_mask 255.255.255.0
persistence_timeout 50 #会话保持时间,单位为秒
protocol TCP #指定转发协议类型,有TCP和UDP两种
real_server 192.168.0.181 80 {
weight 1 #配置节点权值,数字越大权值越高
TCP_CHECK {
connect_timeout 3 #表示3秒无响应,则超时
nb_get_retry 3 #表示重试次数
delay_before_retry 3 #表示重试间隔
}
}
real_server 192.168.0.141 80 { #配置服务器节点,即Real Server2的public IP
weight 3 #配置节点权值,数字越大权值越高
TCP_CHECK {
connect_timeout 3 #表示3秒无响应,则超时
nb_get_retry 3 #表示重试次数
delay_before_retry 3 #表示重试间隔
}
}
}//启动哈keepalived、设置keepalived服务自动启动、检查是否生效,如下图所示:
(2)在DR2上配置keepalived:
先将上面记事本中的keepalived.conf配置文件,仅仅修改2处,如下图所示:
No.1处:把“stateMASTER”修改为“stateBACKUP” #即备用服务器;
No.2处:把“priority 100”修改为“priority 90” #优先级为90。
修改好后,复制到DR2的/etc/keepalived/keepalived.conf中,保存即可!
//启动哈keepalived、设置keepalived服务自动启动、检查是否生效,如下图所示:
参考文章:http://beyondhdf.blog.51cto.com/229452/1331874
http://www.07net01.com/linux/ipvsadm_keepalivedanzhuangcuowujiejue_73067_1361863388.html
http://rensanning.iteye.com/blog/2202718