集群LVS+GFS+ISCSI+TOMCAT

 LVS是中国人发起的项目,真是意外呀!大家可以看http://www.douzhe.com/linuxtips/1665.html
我是从最初的HA(高可用性)开始的,别人的例子是用VMWARE,可以做试验但不能实际应用,我又没有光纤卡的Share Storage,于是就选用ISCSI,成功后又发现ISCSI+EXT3不能用于LVS,倒最后发现GFS可用,我最终成功配成可实际应用的LVS,前后断断续续花了四个月,走了很多弯路。我花了三天时间写下这篇文章,希望对大家有用。
这里要感谢linuxfans.org、linuxsir.com、chinaunix.com以及其它很多网站,很多资料都是从他们的论坛上找到的。参考文档及下载点
a.http://www.gyrate.org/misc/gfs.txt
b.http://www.redhat.com/docs/manuals/enterprise/RHEL-3-Manual/cluster-suite/index.html
http://www.redhat.com/docs/manuals/csgfs/admin-guide/index.html
c.ftp://ftp.redhat.com/pub/redhat/linux/updates/enterprise/3ES/en/RHGFS/SRPMS
d.http://distro.ibiblio.org/pub/linux/distributions/caoslinux/centos/3.1/contrib/i386/RPMS/
                 LVS结构图:              eth0=10.3.1.101            eth0:1=10.3.1.254                Load Balance                   Router              eth1=192.168.1.71            eth1:1=192.168.1.1                  |         |                  |         |                Real1      Real2       eth0=192.168.1.68  eth0=192.168.1.67            (eth0 gateway=192.168.1.1)       eth1=192.168.0.1---eth1=192.168.0.2                  (双机互联线)                       |                       |                      GFS                     ISCSI                Share storage              eth0=192.168.1.124
1.Setup ISCSI Server
Server: PIII 1.4,512M, Dell 1650,Redhat 9,IP=192.168.1.124
从http://iscsitarget.sourceforge.net/下载ISCSI TARGET的Source code
(http://sourceforge.net/project/showfiles.php?group_id=108475&package_id=117141)
我选了iscsitarget-0.3.8.tar.gz,要求kernel 2.4.29
从kernel.org下载kernel 2.4.29,解开编译重启后编译安装iscsitarget-0.3.8:
#make KERNELSRC=/usr/src/linux-2.4.29
#make KERNELSRC=/usr/src/linux-2.4.29 install
#cp ietd.conf /etc
#vi /etc/ietd.conf

# Example iscsi target configuration## Everything until the first target definition belongs# to the global configuration.# Right now this is only the user configuration used# during discovery sessions:# Users, who can access this target# (no users means anyone can access the target)User iscsiuser 1234567890abcTarget iqn.2005-04.com.my:storage.disk2.sys1.iraw1        User iscsiuser 1234567890abc        Lun 0 /dev/sda5 fileio        Alias iraw1Target iqn.2005-04.com.my:storage.disk2.sys1.iraw2        User iscsiuser 1234567890abc        Lun 1 /dev/sda6 fileio        Alias iraw2Target iqn.2005-04.com.my:storage.disk2.sys2.idisk        User iscsiuser 1234567890abc        Lun 2 /dev/sda3 fileio        Alias idiskTarget iqn.2005-04.com.my:storage.disk2.sys2.icca        User iscsiuser 1234567890abc        Lun 3 /dev/sda7 fileio        Alias icca

说明:password 长度必须不小于12个字符, Alias是别名, 不知为何这个别名在Client端显示不出来.
分区:我只有一个SCSI盘,所以:

/dev/sda3: Share storage,容量越大越好/dev/sda5: raw1, 建Cluster要的rawdevice, 我给了900M/dev/sda6: raw2, 建Cluster要的rawdevice, 我给了900M/dev/sda7: cca, 建GFS要的,我给了64M(/dev/sda4是Extended分区,在其中建了sda5,6,7)

#Reboot,用service iscsi-target start启ISCSI server(我觉得比建议的好,可以
用service iscsi-target status看状态)
2.Setup ISCSI Client(on two real server)
Server: PIII 1.4,512M, Dell 1650,Redhat AS3U4(用AS3U5更好),2.4.21-27.EL
#vi /etc/iscsi.conf

DiscoveryAddress=192.168.1.124OutgoingUsername=iscsiuserOutgoingPassword=1234567890abcUsername=iscsiuserPassword=1234567890abcLoginTimeout=15IncomingUsername=iscsiuserIncomingPassword=1234567890abcSendAsyncTest=yes

#service iscsi restart
#iscsi-ls -l
..., 精简如下:
/dev/sdb:iraw2
/dev/sdc:iraw1
/dev/sdd:idisk
/dev/sde:icca
注意: 在real server中ISCSI device的顺序很重要,两个real server中一定要一样,如不一样
   就改ISCSI Server中的设置,多试几次
3.Install Redhat Cluster suite
先下载Cluster Suite的ISO, AS3的我是从ChinaUnix.net找到的下载点, 安装clumanager和
redhat-config-cluster。没有Cluster Suite的ISO也没关系,从
ftp://ftp.redhat.com/pub/redhat/linux/updates/enterprise/3ES/en/RHCS/SRPMS/下载
clumanager-1.2.xx.src.rpm,redhat-config-cluster-1.0.x.src.rpm,编译后安装,应该更好:
#rpm -Uvh clumanager-1.2.26.1-1.src.rpm
#rpmbuild -bs /usr/src/redhat/SPECS/clumanager.spec
#rpmbuild --rebuild --target i686 /usr/src/redhat/SRPMS/clumanager-1.2.26.1-1.src.rpm
还有redhat-config-cluster-1.0.x.src.rpm,也装好
4.Setup Cluster as HA module
详细步骤我就不写了,网上有很多文章,我也是看了别人的文章学会的,不过人家是用VMWARE,
而我是用真的机子+ISCSI,raw device就是/dev/sdb,/dev/sdc, 然后就
mount /dev/sdd /u01, mkfs.ext3 /u01 ......
设好后会发现ISCSI有问题:同时只能有一个Client联接写盘,如果
两个Client同时联ISCSI的Share Storge,一个Client写,另一个Client是看不到的,而且此时文
件系统已经破坏了,Client重联ISCSI时会发现文件是坏的,用fsck也修复不了。
ISCSI真的是鸡肋吗?
 NO!从GOOGLE上我终于查到ISCSI只有用Cluster File System才能真正用于Share Storage!
而Redhat买下的GFS就是一个!
5.Setup GFS on ISCSI
GFS只有Fedora Core4才自带了,而GFS又一定要用到Cluster Suite产生的/etc/cluster.xml文件,
我没见FC4有Cluster Suite,真不知Redhat给FC4带GFS干嘛,馋人吗?
好,闲话少说,下载:c处的GFS-6.0.2.20-2.src.rpm,按a处的gfs.txt编译安装,不过关于
cluster.ccs,fence.ccs,nodes.ccs的设置没说,看b的文档,我总算弄出来了,都存在
/root/cluster下,存在别的地方也行,不过我不知道有没有错,我没有光纤卡,文档又没讲ISCSI
的例子,不过GFS能启动的。
#cat cluster.ccs

cluster {        name = "Cluster_1"        lock_gulm {            servers = ["cluster1", "cluster2"]            heartbeat_rate = 0.9            allowed_misses = 10        }}

注:name就是Cluster Suite设置的Cluster name, servers就是Cluster member的Hostname,别忘
了加进/etc/hosts;allowed_misses我开始设为1,结果跑二天GFS就会死掉,改为10就没死过了。
#cat fence.ccs

fence_devices{        admin {              agent = "fence_manual"        }}

#cat nodes.ccs

nodes {   cluster1 {      ip_interfaces {         hsi0 = "192.168.0.1"      }      fence {         human {            admin {               ipaddr = "192.168.0.1"            }         }      }   }   cluster2 {      ip_interfaces {         hsi0 = "192.168.0.2"      }      fence {         human {            admin {               ipaddr = "192.168.0.2"            }         }      }   }}

注:ip就是心跳线的ip
这三个文件建在/root/cluster下,先建立Cluster Configuration System:
a.#vi /etc/gfs/pool0.cfg
poolname pool0
minor 1 subpools 1
subpool 0 8 1 gfs_data
pooldevice 0 0 /dev/sde1
b.#pool_assemble -a pool0
c.#ccs_tool create /root/cluster /dev/pool/pool0
d.#vi /etc/sysconfig/gfs
CCS_ARCHIVE="/dev/pool/pool0"

再Creating a Pool Volume,就是我们要的共享磁盘啦,
a.#vi /etc/gfs/pool1.cfg
poolname pool1
minor 2 subpools 1
subpool 0 128 1 gfs_data
pooldevice 0 0 /dev/sdd1
b.#pool_assemble -a pool1
c.#gfs_mkfs -p lock_gulm -t Cluster_1:gfs1 -j 8 /dev/pool/pool1
d.#mount -t gfs -o noatime /dev/pool/pool1 /u01
下面是个GFS的启动脚本,注意real1和real2必须同时启动lock_gulmd进程,第一台lock_gulmd
会成为Server并等Client的lock_gulmd,几十秒后没有响应会fail,GFS启动失败。Redhat建议
GFS盘不要写进/etc/fstab。
#cat gfstart.sh

#!/bin/shdepmod -amodprobe poolmodprobe lock_gulmmodprobe gfssleep 5service iscsi startsleep 20service rawdevices restartpool_assemble -a pool0pool_assemble -a pool1service ccsd startservice lock_gulmd startmount -t gfs /dev/pool/pool1 /s02 -o noatimeservice gfs status
6. Setup Linux LVS
LVS是章文嵩博士发起和领导的优秀的集群解决方案,许多商业的集群产品,比如RedHat的Piranha,Turbolinux公司的Turbo Cluster等,都是基于LVS的核心代码的。
我的系统是Redhat AS3U4,就用Piranha了。从rhel-3-u5-rhcs-i386.iso安装piranha-0.7.10-2.i386.rpm,ipvsadm-1.21-9.ipvs108.i386.rpm (http://distro.ibiblio.org/pub/linux/distributions/caoslinux/centos/3.1/contrib/i386/RPMS/) 装完后service httpd start & service piranha-gui start,就可以从http://xx.xx.xx.xx:3636管理或设置了,当然了,手工改/etc/sysconfig/ha/lvs.cf也一样。
#cat /etc/sysconfig/ha/lvs.cf

serial_no = 80primary = 10.3.1.101service = lvsrsh_command = sshbackup_active = 0backup = 0.0.0.0heartbeat = 1heartbeat_port = 1050keepalive = 6deadtime = 18network = natnat_router = 192.168.1.1 eth1:1nat_nmask = 255.255.255.0reservation_conflict_action = preemptdebug_level = NONEvirtual lvs1 {     active = 1     address = 10.3.1.254 eth0:1     vip_nmask = 255.255.255.0     fwmark = 100     port = 80     persistent = 60     pmask = 255.255.255.255     send = "GET / HTTP/1.0\r\n\r\n"     expect = "HTTP"     load_monitor = ruptime     scheduler = wlc     protocol = tcp     timeout = 6     reentry = 15     quiesce_server = 1     server Real1 {         address = 192.168.1.68         active = 1         weight = 1     }     server Real2 {         address = 192.168.1.67         active = 1         weight = 1     }}virtual lvs2 {     active = 1     address = 10.3.1.254 eth0:1     vip_nmask = 255.255.255.0     port = 21     send = "\n"     use_regex = 0     load_monitor = ruptime     scheduler = wlc     protocol = tcp     timeout = 6     reentry = 15     quiesce_server = 0     server ftp1 {         address = 192.168.1.68         active = 1         weight = 1     }     server ftp2 {         address = 192.168.1.67         active = 1         weight = 1     }}

设置完后service pulse start, 别忘了把相关的client加进/etc/hosts
#iptables -t mangle -A PREROUTING -p tcp -d 10.3.1.254/32 --dport 80 -j MARK --set-mark 100
#iptables -t mangle -A PREROUTING -p tcp -d 10.3.1.254/32 --dport 443 -j MARK --set-mark 100
#iptables -A POSTROUTING -t nat -p tcp -s 10.3.1.0/24 --sport 20 -j MASQUERADE
运行以上三行命令并存入/etc/rc.d/rc.local,用ipvsadm看状态:
#ipvsadm

IP Virtual Server version 1.0.8 (size=65536)Prot LocalAddress:Port Scheduler Flags  -> RemoteAddress:Port           Forward Weight ActiveConn InActConnTCP  10.3.1.254:ftp wlc  -> cluster2:ftp                  Masq    1      0          0  -> cluster1:ftp                  Masq    1      0          0FWM  100 wlc persistent 60  -> cluster1:0                    Masq    1      0          0  -> cluster2:0                    Masq    1      0          0

注意:a.Firewall Mark可以不要,我反正是加了,文档说有https的话加上,值我选了100,
b.Virtual IP别加进/etc/hosts,我上过当,80端口时有时无的,
c.eth0:1,eth1:1是piranha产生的,别自己手工设置,我干过这画蛇添足的事,网上有
些帖子没说清,最后是看Redhat的文档才弄清楚的。
d.The LVS router can monitor the load on the various real servers by using
either rup or ruptime. If you select rup from the drop-down menu, each real
server must run the rstatd service. If you select ruptime, each real server
must run the rwhod service.Redhat的原话,就是如选rup的监控模式real server上
都要运行rstatd进程,如选ruptime就要运行rwhod进程。
e.Real Server同Router相联的网卡的Gateway必须是Router的那块网卡的VIP,举本例:
Router的eth1同两个real server的eth0相联,如VIP eth1:1=192.168.1.1,则real
server 的eth0的Gateway=192.168.1.1

echo "1" > /proc/sys/net/ipv4/ip_forward
q:在两台real server上分别
#vi /usr/local/tomcat/conf/tomcat-users.xml
加下面一行,允许页面管理:

r:在两台real server上分别
#service httpd restart
#/usr/local/tomcat/bin/startup.sh
s:打开http://1092.168.1.68:8080和http://1092.168.1.67:8080,选Tomcat Manager,用
manager/tomcat登录,虚拟目录/myjsp和/local应该Start了
在两台机子上分别打开网页http://10.3.1.254,选WEB Local,可以看到一台显示:
"test page on real server 1",另一台为"test page on real server 2",同时在Router上
ipvsadm可以看到每个real server的联接数
8.设置FTP服务
#vi /etc/vsftpd/vsftp.conf,在两台real server上分别加入以下几行:

anon_root=/u01/ftprootlocal_root=/u01/ftprootsetproctitle_enable=YES

#service vsftpd start
现在LVM+GFS+ISCSI+TOMCAT就设置好了,我们可以用Apache Jmeter来测试LVM的性能,两台机子上分别运行jmeter,都指向10.3.1.254/myjsp/testoracle.jsp,各200个threads同时运行,在Router上用ipvsadm可以监控,Oracle Server的性能可要好,否则大量的http进程会hang在real server上,ipvsadm也会显示有个real server失去了。测试时real server的CPU idle会降到70%,而Router的CPU idle几乎不动。
                                                      文章引用自:大行的BLOG

你可能感兴趣的:(tomcat)