我也来发个LVS集群的文档
时间:2005-06-12 来源:pinle
原帖地址,http://bbs.chinaunix.net/forum/viewtopic.php?t=547795&start=0&sid=3779162ae4a40762637e4c93ee8cebac
这个东东用处满到的.
希望对各位DDMM有点帮助,没有帮助你也不要拍砖
安装环境:RedHat AS 3.x , LVS , Linux-HA HeartBeat, Ldirectord
主要特点:Load Balancer和 Backup Load Balancer也可以作为Real Server加入群中,以节省资源。其他Real Server可以任意添加,也可以没有
原文可以访问我的个人网站:http://www.funbsd.net
作者:FunBSD
最后更新:2005年5月18日
目录
Preface
IPVS
HeatBeat
Ldirectord
Patch
Scripts
Reference
#######################################
# Preface
#######################################
系统结构如图:
400)this.width=400;if(this.height>450)this.height=450 }" border="0" />
各层的作用:
代码: |
Load Balancer(负载均衡器): Load Balancer是整个集群系统的前端,负责把客户请求转发到Real Server上。 Backup是备份Load Balancer,当Load Balancer不可用时接替它,成为实际的Load Balancer。 Load Balancer通过Ldirectord监测各Real Server的健康状况。在Real Server不可用时把它从群中剔除,恢复时重新加入。 Server Array(服务器群): Server Array是一组运行实际应用服务的机器,比如WEB, Mail, FTP, DNS, Media等等。 在实际应用中,Load Balancer和Backup也可以兼任Real Server的角色。 Shared Storage(共享存储): Shared Storage为所有Real Server提供共享存储空间和一致的数据内容。这一部分在这里不涉及 |
各服务器IP分配:
代码: |
Virtual IP: 192.168.136.10 Load Balancer: 192.168.136.11 Backup: 192.168.136.12 Real Server 1: 192.168.136.101 Real Server 2: 192.168.136.102 Real Server 3: 192.168.136.103 |
#######################################
# IPVS
#######################################
IPVS是LVS集群系统的核心软件,它的主要作用是:
安装在Load Balancer上,把发往Virtual IP的请求转发到Real Server上。
IPVS安装主要包括三方面:
在Load Banlancer上安装IPVS内核补丁
在Load Banlancer上安装IPVS管理软件
在Real Server上安装ARP hidden内核补丁
关于如何编译内核请参考其他文档,这里使用从UltraMonkey下载的已编译好的内核。
在Load Banlancer、Backup和Real Server上使用同一内核,IPVS和ARP hidden都已编译在这个内核里:
代码: |
wget http://www.ultramonkey.org/download/2.0.1/rh.el.3.0/RPMS/mkinitrd-3.5.13-1.um.1.i386.rpm wget http://www.ultramonkey.org/download/2.0.1/rh.el.3.0/RPMS/kernel-2.4.21-27.0.2.EL.um.1.i686.rpm #wget http://www.ultramonkey.org/download/2.0.1/rh.el.3.0/RPMS/kernel-smp-2.4.21-27.0.2.EL.um.1.i686.rpm rpm -Fhv mkinitrd-3.5.13-1.um.1.i386.rpm rpm -Fhv kernel-2.4.21-27.0.2.EL.um.1.i686.rpm |
在Load Banlancer和Backup上安装IPVS管理软件:
代码: |
wget http://www.linuxvirtualserver.org/software/kernel-2.4/ipvs-1.0.10.tar.gz tar zxf ipvs-1.0.10.tar.gz cd ipvs-1.0.10/ipvs/ipvsadm make install chkconfig --del ipvsadm |
配置IPVS(/etc/sysconfig/ipvsadm),添加Real Server:
代码: |
-A -t 192.168.136.10:80 -s rr -a -t 192.168.136.10:80 -r 192.168.136.11:80 -i -a -t 192.168.136.10:80 -r 192.168.136.12:80 -i -a -t 192.168.136.10:80 -r 192.168.136.101:80 -i -a -t 192.168.136.10:80 -r 192.168.136.102:80 -i -a -t 192.168.136.10:80 -r 192.168.136.103:80 -i |
相关链接:
Kernel:http://www.kernel.org/
IPVS和IPVSadm:http://www.linuxvirtualserver.org/software/ipvs.html
ARP hidden:http://www.ssi.bg/~ja/#hidden
注意事项:
1. Kernel,IPVS,IPVSadm,ARP hidden之间的版本必须对应。
2. 自己编译内核时,从http://www.kernel.org/下载标准内核源文件,不要使用发行版的内核源文件。
3. Kernel 2.4.28和2.6.10及以上版本已内置IPVS,有些Linux发行版也在其内核里编译了IPVS。
4. ARP hidden可以用arp_ignore/arp_announce或者arptables_jf代替
#######################################
# HeatBeat
#######################################
HeartBeat是Linux-HA的高可用性集群软件,它的主要作用是:
安装在Load Balancer和Backup上,运行于active/standby模式。
当Load Balancer失效时,Backup自动激活,成为实际的Load Balancer。
切换到active模式时,按顺序启动Virtual IP、IPVS和Ldirectord。
切换到standby模式时,按顺序关闭Ldirectord、IPVS和Virtual IP。
HeartBeat串口线连接测试方法:
在Load Balancer上:cat < /dev/ttyS0
在Backup上:echo hello > /dev/ttyS0
在VMWare上设置串口的时候一端做server,一端做client即可
修改主机名(/etc/hosts):
代码: |
127.0.0.1 localhost.localdomain localhost 192.168.136.11 loadbalancer 192.168.136.12 backup |
安装:
代码: |
groupadd -g 694 haclient useradd -u 694 -g haclient hacluster rpm -ivh /mnt/cdrom/RedHat/RPMS/glib2-devel-* wget http://www.packetfactory.net/libnet/dist/libnet.tar.gz tar zxf libnet.tar.gz cd libnet ./configure make make install wget http://www.linux-ha.org/download/heartbeat-1.99.4-tar.gz tar zxf heartbeat-1.99.4.tar.gz cd heartbeat-1.99.4 ./ConfigureMe configure --disable-swig --disable-snmp-subagent make make install cp doc/ha.cf doc/haresources doc/authkeys /etc/ha.d/ cp ldirectord/ldirectord.cf /etc/ha.d/ chkconfig --add heartbeat chkconfig --del ldirectord |
主配置文件(/etc/ha.d/ha.cf):
代码: |
#debugfile /var/log/ha-debug logfile /var/log/ha-log logfacility local0 keepalive 2 deadtime 30 warntime 10 initdead 120 udpport 694 baud 19200 serial /dev/ttyS0 mcast eth0 225.0.0.1 694 1 0 # 当主节点恢复后,是否自动切回 auto_failback on # stonith用来保证共享存储环境中的数据完整性 #stonith baytech /etc/ha.d/conf/stonith.baytech # watchdog能让系统在出现故障1分钟后重启该机器。这个功能可以帮助服务器在确实停止心跳后能够重新恢复心跳。 # 如果使用该特性,则在内核中装入"softdog"内核模块,用来生成实际的设备文件,输入"insmod softdog"加载模块。 # 输入"grep misc /proc/devices"(应为10),输入"cat /proc/misc | grep watchdog"(应为130)。 # 生成设备文件:"mknod /dev/watchdog c 10 130" 。 #watchdog /dev/watchdog node loadbalancer node backup # 默认heartbeat并不检测除本身之外的其他任何服务,也不检测网络状况。 # 所以当网络中断时,并不会进行Load Balancer和Backup之间的切换。 # 可以通过ipfail插件,设置'ping nodes'来解决这一问题。详细说明参考hearbeat文档。 #ping 192.168.136.1 172.16.0.1 ping_group group1 192.168.136.1 192.168.136.2 respawn root /usr/lib/heartbeat/ipfail apiauth ipfail gid=root uid=root # 其他一些插件可以在/usr/lib/heartbeat下找到 #apiauth ipfail uid=hacluster #apiauth ccm uid=hacluster #apiauth cms uid=hacluster #apiauth ping gid=haclient uid=alanr,root #apiauth default gid=haclient |
资源文件(/etc/ha.d/haresources):
代码: |
loadbalancer lvs IPaddr::192.168.136.10/24/eth0 ipvsadm ldirectord |
认证文件(/etc/ha.d/authkeys),选取一种认证方式,这个文件的权限必须是600:
代码: |
auth 1 1 crc #2 sha1 sha1_any_password #3 md5 md5_any_password |
相关链接:
Linux-HA:http://www.linux-ha.org
#######################################
# Ldirectord
#######################################
安装HeartBeat过程中,已经自动安装了Ldirectord,它的作用是:
监测Real Server,当Real Server失效时,把它从Load Balancer列表中删除,恢复时重新添加。
配置(/etc/ha.d/ldirectord.cf):
代码: |
# Global Directives checktimeout=3 checkinterval=1 fallback=127.0.0.1:80 autoreload=yes logfile="/var/log/ldirectord.log" quiescent=yes # A sample virual with a fallback that will override the gobal setting virtual=192.168.136.10:80 real=192.168.136.11:80 ipip real=192.168.136.12:80 ipip real=192.168.136.101:80 ipip real=192.168.136.102:80 ipip real=192.168.136.103:80 ipip fallback=127.0.0.1:80 gate service=http request="test.html" receive="Test Page" virtualhost=www.funbsd.net scheduler=rr #persistent=600 #netmask=255.255.255.255 protocol=tcp |
在每个Real Server的中添加监控页:
echo "Test Page" >> /var/www/html/test.html
#######################################
# Patch
#######################################
在启动集群系统之前,我们认为包括Load Balancer和Backup在内的所有服务器都是Real Server。
在服务器上添加以下脚本/etc/init.d/tunl,用来配置tunl端口,应用arp补丁:
代码: |
#!/bin/sh # chkconfig: 2345 70 10 # description: Config tunl port and apply arp patch VIP=192.168.136.10 . /etc/rc.d/init.d/functions case "$1" in start) echo "Tunl port starting" ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP up echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/all/hidden echo 1 > /proc/sys/net/ipv4/conf/tunl0/hidden ;; stop) echo "Tunl port closing" ifconfig tunl0 down echo 1 > /proc/sys/net/ipv4/ip_forward echo 0 > /proc/sys/net/ipv4/conf/all/hidden ;; *) echo "Usage: $0 {start|stop}" exit 1 esac |
如果有多个Virutal IP,可以使用tunl0:0,tunl0:1...。
代码: |
chmod 755 /etc/init.d/tunl chkconfig --add tunl |
在Load Balancer和Backup上,这个脚本的启动级必须先于heartbeat,关闭级必须后于heartbeat。
#######################################
# Scripts
#######################################
在HeartBeat资源文件(/etc/ha.d/haresources)中定义了实现集群所需的各个软件的启动脚本。
这些脚本必须放在/etc/init.d或者/etc/ha.d/resource.d目录里,启动顺序不能变:
代码: |
loadbalancer lvs IPaddr::192.168.136.10/24/eth0 ipvsadm ldirectord |
IPaddr的作用是启动Virutal IP,它是HeartBeart自带的一个脚本。
ipvsadm的作用是在启动的时候把所有Real Server加入群中。
ldirectord的作用是启动ldirectord监控程序。
lvs的作用是为启动Load Balancer做准备,关闭tunl端口,取消arp补丁:
代码: |
#!/bin/sh # chkconfig: 2345 90 10 # description: Preparing for Load Balancer and Real Server switching VIP=192.168.136.10 . /etc/rc.d/init.d/functions case "$1" in start) echo "Preparing for Load Balancer" ifconfig tunl0 down echo 1 > /proc/sys/net/ipv4/ip_forward echo 0 > /proc/sys/net/ipv4/conf/all/hidden ;; stop) echo "Preparing for Real Server" ifconfig tunl0 $VIP netmask 255.255.255.255 broadcast $VIP up echo 1 > /proc/sys/net/ipv4/ip_forward echo 1 > /proc/sys/net/ipv4/conf/all/hidden echo 1 > /proc/sys/net/ipv4/conf/tunl0/hidden ;; *) echo "Usage: lvs {start|stop}" exit 1 esac |
代码: |
chmod 755 /etc/ha.d/resource.d/lvs |
启动集群系统:
代码: |
/etc/init.d/heartbeat start |
#######################################
# Reference
#######################################
http://www.linuxvirtualserver.org/
http://www.linux-ha.org/
http://www.ultramonkey.org/
http://www.linuxts.com/modules/sections/index.php?op=viewarticle&artid=375
http://www.yesky.com/SoftChannel/72341302397632512/20040311/1776261.shtml
http://www-900.ibm.com/developerWorks/cn/linux/theme/special/index.shtml#cluster
相关阅读 更多 +
排行榜 更多 +