Chinaunix首页 | 论坛 | 博客

  • 博客访问: 916214
  • 博文数量: 226
  • 博客积分: 10077
  • 博客等级: 上将
  • 技术积分: 2708
  • 用 户 组: 普通用户
  • 注册时间: 2008-05-25 14:36
文章分类

全部博文(226)

文章存档

2010年(15)

2009年(82)

2008年(129)

我的朋友

分类: LINUX

2009-09-11 15:47:43

作者: 龙如俊  想了解更多的知识请关注作者的博客: http://longrujun.name/blogs
为一扩展项目,提供基于特定Url字符集及Session persistence 进行的L7交换负载均衡.通过该架构可非常灵活把各种协议及负载均衡方式有机结合,支持High Availability和负载均衡技术.其体系结构及框架如下图所示


l7image-1e.gif



l7image-2e.gif










1、  编译安装

1.1> apr和apr-util安装
apr:
# tar jxvf apr-1.3.3.tar.bz2
#cd apr-1.3.3
# ./configure --prefix=/usr--libdir=/usr/lib
#make
#make install

apr-util:
# tar jxvf apr-util-1.3.4.tar.bz2
# cd apr-util-1.3.4
# ./configure --prefix=/usr --libdir=/usr/lib--with-apr=/usr
#make
#make install
1.2> log4cxx安装
# tar zxvf apache-log4cxx-0.10.0.tar.gz
# cd apache-log4cxx-0.10.0
# ./configure --prefix=/usr --libdir=/usr/lib
#make
#make install
     1.3>libnet安装
         #tar-zxvf libnet.tar.gz
#cd libnet
#./configure
#make
#makeinstall
     1.4>Heartbeat安装
                  #tarjxvf Heartbeat-STABLE-2-1-STABLE-2.1.4.tar.bz2
#cd Heartbeat-STABLE-2-1-STABLE-2.1.4
#./ConfigureMeconfigure --disable-swig --disable-snmp-subagent
#make
#makeinstall
#cpdoc/ha.cf doc/haresources doc/authkeys /etc/ha.d/
#cpldirectord/ldirectord.cf /etc/ha.d/
#groupadd-g 694 haclient
#useradd-u 694 -g haclient hacluster
1.5>ultramonkey-l7安装
# tar zxvf ultramonkey-l7-2.0.0-1.tar.gz
       #cd ultramonkey-l7-2.0.0-1
         #./configure
        #make
         #makeinstall


2、  配置
2.1>ha.cf
#cat ha.cf |grep -v "#"
logfile/Data/logs/ha-log
logfacility     local0
keepalive2
deadtime30
warntime10
initdead50
ucasteth0 124.42.78.14
auto_failbackon
node    e.csdn.net
node    d.csdn.net
ping124.42.78.14
ping_groupgroup1 124.42.78.14 124.42.78.15
respawnroot /usr/lib/heartbeat/ipfail
apiauthipfail gid=root uid=root

2.2>authkeys
#cat authkeys |grep -v "#"
auth2
2sha1 Hey!

2.3>haresources
catharesources |grep -v "#"
e.csdn.net      124.42.78.16/32/eth0:0    l7vsd

#ln -s /usr/sbin/l7vsd /etc/ha.d/resource.d/
#ln -s /usr/sbin/l7directord /etc/ha.d/resource.d/

2.4>l7directord
#cat l7directord.cf |grep -v "#"

checktimeout=4
checkinterval=5
autoreload=yes
logfile="/Data/logs/l7directord.log"
quiescent=no

virtual=124.42.78.16:80
        real=124.42.78.12:80 masq 1
        real=124.42.78.13:80 masq 1
        module=cinsert --cookie-name 'L7'--cookie-expire 5
        scheduler=wrr
        protocol=tcp
        maxconn=2000
#scheduler,should be only lc, rr or wrr

3、  单点测试
3.1>启动服务
#/etc/init.d/heartbeatstart
StartingHigh-Availability services:
                                                          [  OK  ]
等l7vsd起来后启动l7directord服务
#/etc/init.d/l7directord start
Startingl7directord                                       [  OK  ]
3.2>检查相关状态
#ip address list
         eth0: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:50:56:ae:37:ef brdff:ff:ff:ff:ff:ff
    inet 124.42.78.15/26 brd 124.42.78.63 scopeglobal eth0
inet124.42.78.16/32 brd 124.42.78.16 scope global eth0:0

# ps -eaf |grepl7directord
root      1802 1676  0 13:23 pts/1    00:00:00 tail -f /Data/logs/l7directord.log
root      2578    1  0 14:00 ?        00:00:00 /usr/bin/perl --/etc/ha.d/resource.d/l7directord start

# ps -eaf |grep l7vsd
root      2185    1 98 13:50 ?        00:12:47/usr/sbin/l7vsd ?Cb

#3.3>相关log状态
#tail -10/Data/logs/l7directod.log

[Mon Oct  6 09:26:16 2008|l7directord] Starting LinuxDirector v2.0.0-1 as daemon
[Mon Oct  6 09:26:17 2008|l7directord] Added virtualserver: 124.42.78.16:80 cinsert --cookie-name L7
[Mon Oct  6 09:26:17 2008|l7directord] Added realserver: 124.42.78.12:80 (  x 124.42.78.16:80cinsert --cookie-name L7 ) (Weight set to 1)
[Mon Oct  6 09:26:18 2008|l7directord] Added realserver: 124.42.78.13:80 (  x124.42.78.16:80 cinsert --cookie-name L7 ) (Weight set to 1)

#tail -100/Data/logs/ha-log
heartbeat[2362]:2008/10/05_13:59:24 info: **************************
heartbeat[2362]:2008/10/05_13:59:24 info: Configuration validated. Starting heartbeat 2.1.4
heartbeat[2363]:2008/10/05_13:59:24 info: heartbeat: version 2.1.4
heartbeat[2363]:2008/10/05_13:59:25 info: Heartbeat generation: 1222818862
heartbeat[2363]:2008/10/05_13:59:25 info: glib: UDP Broadcast heartbeat started on port 694(694) interface eth0
heartbeat[2363]:2008/10/05_13:59:25 info: glib: UDP Broadcast heartbeat closed on port 694interface eth0 - Status: 1
heartbeat[2363]:2008/10/05_13:59:25 info: glib: ucast: write socket priority set toIPTOS_LOWDELAY on eth0
heartbeat[2363]:2008/10/05_13:59:26 info: glib: ucast: bound send socket to device: eth0
heartbeat[2363]:2008/10/05_13:59:26 info: glib: ucast: bound receive socket to device: eth0
heartbeat[2363]:2008/10/05_13:59:26 info: glib: ucast: started on port 694 interface eth0 to124.42.78.11
heartbeat[2363]:2008/10/05_13:59:26 info: glib: ping heartbeat started.
heartbeat[2363]:2008/10/05_13:59:26 info: glib: ping group heartbeat started.
heartbeat[2363]:2008/10/05_13:59:27 info: G_main_add_TriggerHandler: Added signal manualhandler
heartbeat[2363]:2008/10/05_13:59:27 info: G_main_add_TriggerHandler: Added signal manualhandler
heartbeat[2363]: 2008/10/05_13:59:27info: G_main_add_SignalHandler: Added signal handler for signal 17
heartbeat[2363]:2008/10/05_13:59:27 info: Local status now set to: 'up'
heartbeat[2363]:2008/10/05_13:59:28 info: Link 124.42.78.11:124.42.78.11 up.
heartbeat[2363]: 2008/10/05_13:59:28info: Status update for node 124.42.78.11: status ping
heartbeat[2363]:2008/10/05_13:59:28 info: Link e.csdn.net:eth0 up.
heartbeat[2363]:2008/10/05_13:59:28 info: Link group1:group1 up.
heartbeat[2363]:2008/10/05_13:59:28 info: Status update for node group1: status ping
heartbeat[2363]:2008/10/05_14:00:28 WARN: node a.csdn.net: is dead
heartbeat[2363]:2008/10/05_14:00:28 info: Comm_now_up(): updating status to active
heartbeat[2363]:2008/10/05_14:00:28 info: Local status now set to: 'active'
heartbeat[2363]:2008/10/05_14:00:28 info: Starting child client"/usr/lib/heartbeat/ipfail" (0,0)
heartbeat[2363]:2008/10/05_14:00:28 WARN: No STONITH device configured.
heartbeat[2363]:2008/10/05_14:00:28 WARN: Shared disks are not protected.
heartbeat[2363]:2008/10/05_14:00:28 info: Resources being acquired from a.csdn.net.
heartbeat[2381]:2008/10/05_14:00:28 info: Starting "/usr/lib/heartbeat/ipfail" as uid0  gid 0 (pid 2381)
harc[2382]:     2008/10/05_14:00:29 info: Running/etc/ha.d/rc.d/status status
mach_down[2410]:        2008/10/05_14:00:32 info:/usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
heartbeat[2383]:2008/10/05_14:00:32 info: Local Resource acquisition completed.
heartbeat[2363]:2008/10/05_14:00:32 info: mach_down takeover complete.
heartbeat[2363]:2008/10/05_14:00:32 info: Initial resource acquisition complete (mach_down)
mach_down[2410]:        2008/10/05_14:00:32 info: mach_downtakeover complete for node a.csdn.net.
harc[2471]:     2008/10/05_14:00:34 info: Running/etc/ha.d/rc.d/ip-request-resp ip-request-resp
ip-request-resp[2471]:  2008/10/05_14:00:34 received ip-request-resplvs-dr.sh OK yes
ResourceManager[2493]:  2008/10/05_14:00:36 info: Acquiring resourcegroup: e.csdn.net lvs-dr.sh l7directord
ResourceManager[2493]:  2008/10/05_14:00:38 info: Running/etc/ha.d/resource.d/lvs-dr.sh  start
ResourceManager[2493]:  2008/10/05_14:00:41 info: Running/etc/ha.d/resource.d/l7directord  start
heartbeat[2363]:2008/10/05_14:00:42 info: Local Resource acquisition completed. (none)
heartbeat[2363]:2008/10/05_14:00:42 info: local resource transition completed.
heartbeat[2643]:2008/10/05_14:00:52 info: Version 2 support: false
heartbeat[2643]:2008/10/05_14:00:52 WARN: Logging daemon is disabled --enabling logging daemonis recommended
heartbeat[2643]:2008/10/05_14:00:52 info: **************************
         3.4>L7负载均衡状态
#l7vsadm

Layer-7Virtual Server version 2.0.0-1
ProtLocalAddress:Port ProtoMod Scheduler
  -> RemoteAddress:Port           Forward Weight ActiveConn InactConn
TCP124.42.78.16:http cinsert wrr
  -> 124.42.78.12:http            Masq    1     1          49        
  -> 124.42.78.13:http            Masq    1     1          22        
停止后端R1服务,R2正常
#l7vsadm
Layer-7Virtual Server version 2.0.0-1
ProtLocalAddress:Port ProtoMod Scheduler
  -> RemoteAddress:Port           Forward Weight ActiveConn InactConn
TCP124.42.78.16:http cinsert wrr
  -> 124.42.78.13:http            Masq    1     1          23   
L7单点状态正常



Step4.配置备用
4.1>基本安装如上所述-略
4.2>拷贝
#scp -P55522 ha.cf authkeys haresources [email=root@124.42.78.14:/etc/ha.d/]root@124.42.78.14:/etc/ha.d/[/email]
scp -P55522 conf/l7directord.cf [email=root@124.42.78.14:/etc/ha.d/conf]root@124.42.78.14:/etc/ha.d/conf[/email]
配置ha.cf及haresources
ha.cf如下
#cat ha.cf |grep -v "#"
logfile/Data/logs/ha-log
logfacility     local0
keepalive2
deadtime30
warntime10
initdead50
ucasteth0 124.42.78.15
auto_failbackon
node    e.csdn.net
node    d.csdn.net
ping124.42.78.15
ping_groupgroup1 124.42.78.15 124.42.78.14
respawnroot /usr/lib/heartbeat/ipfail
apiauthipfail gid=root uid=root

haresources内容如下
# cat haresources |grep -v "#"
d.csdn.net      124.42.78.16/32/eth0:0    l7vsd


#ln -s /usr/sbin/l7vsd /etc/ha.d/resource.d/
#ln -s /usr/sbin/l7directord /etc/ha.d/resource.d/


启动服务
#/etc/init.d/heartbeatstart
StartingHigh-Availability services:
                                                          [  OK  ]
等l7vsd起来后启动l7directord服务
#/etc/init.d/l7directord start
Startingl7directord                                       [  OK  ]

测试



附:参考文档
1>   
2>   
阅读(2359) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~