一开始粗心大意没有注意到“LVS操作手册”。fullnat模式下在配置keepalived的时候,与dr、nat、tun是有很大的区别的。
这里根据自身实战的经验和lvs操作手册中的步骤,重新用自己的语言整理下:
注意不要安装libnl libnl-devel,否则有报错,如果没遇到报错也无所谓
在完成fullnat内核编译之后,我们就可以配置keepalived了:
一、安装keepalived、ipvsadm
必须要用tools压缩包中的来安装,不要用其他开源版本
1.1 keepalived
cd tools/keepalived; ./configure --with-kernel-dir="/lib/modules/`uname -r`/build"; make; make install;
cp -a bin/genhash /usr/local/bin/ cp -a bin/keepalived /sbin/ cp -a keepalived/etc/init.d/keepalived.init /etc/init.d/keepalived cp -a keepalived/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf cp -a keepalived/etc/init.d/keepalived.sysconfig /etc/sysconfig/keepalived
1.2 ipvsadm
cd tools/ipvsadm; make; make install;
二、系统自身参数配置
1、
打开irqbalance # service irqbalance start # chkconfig --level 2345 irqbalance on
2、
路径:/etc/sysctl.conf # configure for lvs net.ipv4.conf.all.arp_ignore = 1 net.ipv4.conf.all.arp_announce = 2 net.core.netdev_max_backlog = 500000
三、keepalived配置文件
3.1 使用主备模式部署
global部分
global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL }
local address部分
#这部分官方推荐用多个ip地址,本次试验就用服务器自身地址,如果需要用到多个地址,需要在rc.local中添加绑ip的命令。 local_address_group laddr_g1 { 192.168.122.101 #这里可以用本机的ip }
virtual server group部分
#看到这里需要将vip和vport都声明,这就是一个区别。 virtual_server_group shanks1 { 192.168.122.123 80 }
vrrp_sunc_group部分
vrrp_sync_group lvs_1 { group { VI_1 } notify_master /home/work/public/opbin/script/change_hostname_to_master.sh notify_backup /home/work/public/opbin/script/change_hostname_to_backup.sh smtp_alert }
vrrp instance 部分
vrrp_instance VI_1 { state BACKUP #主备都是backup interface eth0 virtual_router_id 156 priority 100 #备机上设置成10 advert_int 1 nopreempt FALSE #设置成切换不抢占 authentication { auth_type PASS auth_pass wocao } virtual_ipaddress { 192.168.122.123 } }
virtual server部分
virtual_server 192.168.122.123 80 { delay_loop 6 lb_algo rr lb_kind FNAT protocol TCP syn_proxy laddr_group_name laddr_g1 #local address group real_server 172.16.122.123 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
最终的配置文件
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL } local_address_group laddr_g1 { 192.168.122.101 } virtual_server_group shanks1 { 192.168.122.123 80 } vrrp_sync_group lvs_1 { group { VI_1 } notify_master /home/work/public/opbin/script/change_hostname_to_master.sh notify_backup /home/work/public/opbin/script/change_hostname_to_backup.sh smtp_alert } vrrp_instance VI_1 { state BACKUP interface eth0 virtual_router_id 156 priority 100 #备机上设置成10 advert_int 1 nopreempt FALSE authentication { auth_type PASS auth_pass wocao } virtual_ipaddress { 192.168.122.123 } } virtual_server 192.168.122.123 80 { delay_loop 6 lb_algo rr lb_kind FNAT protocol TCP syn_proxy laddr_group_name laddr_g1 #local address group real_server 172.16.122.123 80 { weight 100 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
3.2 使用集群模式部署
global部分
global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL }
local address部分
#这部分官方推荐用多个ip地址,本次试验就用服务器自身地址,如果需要用到多个地址,需要在rc.local中添加绑ip的命令。 local_address_group laddr_g1 { 192.168.122.101 #这里可以用本机ip }
virtual server group部分
#看到这里需要将vip和vport都声明,这就是一个区别。 virtual_server_group shanks1 { 192.168.122.123 80 }
virtual server部分
virtual_server 192.168.122.123 80 { delay_loop 6 lb_algo rr lb_kind FNAT protocol TCP syn_proxy laddr_group_name laddr_g1 #local address group alpha omega #我一般是把这个注释掉,不让它去自动的del虚ip。 quorum 1 hysteresis 0 quorum_up " ip addr add 10.255.255.123/32 dev lo;" #add #quorum_up " ip addr add 10.255.255.123/32 dev lo; ip addr add 10.255.255.124/32 dev lo;" quorum_down "ip addr del 10.255.255.123/32 dev lo;" #del vip 我一般是把这个注释掉,不让它去自动的del虚ip。 real_server 172.16.122.123 80 { weight 1 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
最终的配置文件
! Configuration File for keepalived global_defs { notification_email { [email protected] } notification_email_from [email protected] smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL } local_address_group laddr_g1 { 192.168.122.101 } virtual_server_group shanks1 { 192.168.122.123 80 } virtual_server 192.168.122.123 80 { delay_loop 6 lb_algo rr lb_kind FNAT protocol TCP syn_proxy laddr_group_name laddr_g1 #local address group alpha #omega quorum 1 hysteresis 0 quorum_up " ip addr add 10.255.255.123/32 dev lo;" #add #quorum_down "ip addr del 10.255.255.123/32 dev lo;" #del vip real_server 172.16.122.123 80 { weight 100 TCP_CHECK { connect_timeout 3 nb_get_retry 3 delay_before_retry 3 connect_port 80 } } }
最后启动keepalived。关于zebra、ospf后续补充
遇到的报错:
1、#在安装完keepalived之后,安装ipvsadm的时候,遇到了如下的报错: [root@lvs ipvsadm]# make make: *** Norule to make target `../keepalived/keepalived/libipvs-2.6/libipvs.a', needed by`ipvsadm'. Stop. [root@lvsipvsadm]# ll ../keepalived/keepalived/libipvs-2.6/libipvs.a ls: cannotaccess ../keepalived/keepalived/libipvs-2.6/libipvs.a: No such file ordirectory 解决办法: 这是由于使用http://shanks.blog.51cto.com/3899909/1387489这种方式打包的内核rpm,安装时候没有装kernel-devel导致的,装下就好了。
2、在make ipvsadm的时候遇到了如下的报错: /usr/local/src/tools/keepalived/keepalived/libipvs-2.6/libipvs.c:496: undefined reference to `nlmsg_free' ../keepalived/keepalived/libipvs-2.6/libipvs.a(libipvs.o): In function `ipvs_update_dest': /usr/local/src/tools/keepalived/keepalived/libipvs-2.6/libipvs.c:467: undefined reference to `nlmsg_free' ../keepalived/keepalived/libipvs-2.6/libipvs.a(libipvs.o):/usr/local/src/tools/keepalived/keepalived/libipvs-2.6/libipvs.c:437: more undefined references to `nlmsg_free' follow collect2: ld returned 1 exit status make: *** [ipvsadm] Error 1 解决办法: 这是由于服务器上安装了libnl,卸载libnl、libnl-devel之后,重新编译keepalived和ipvsadm即可。