搭建环境
三台电脑:一台装apache,做为loadbalancer,另二台装jboss,分别做为node1,node2
 
配置负载均衡节点:
操作系统centos5.0用yum自带安装httpd,查看版本号用httpd -version命令,版本为Apache/2.2.3,配置文件在/etc/httpd/conf/httpd.conf
下载mod_jk.so,拷贝到,/etc/httpd/modules
添加可执行权限:#chmod +x /etc/httpd/modules/mod_jk.so
添加配置文件mod_jk.conf,同时将路径加到httpd.conf中,用Include conf/mod_jk.conf
内容如下:
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile conf/workers.properties
# Where to put jk logs
JkLogFile logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel info
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y]"
# JkOptions indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
# Mount your applications
#jkMount /application/* loadbalancer
jkMount /* loadbalancer
# You can use external file for mount points.
# It will be checked for updates each 60 seconds.
# The format of the file is: /url=worker
# /examples/*=loadbalancer
JkMountFile conf/uriworkermap.properties
# Add shared memory.
# This directive is present with 1.2.10 and
# later versions of mod_jk, and is needed for
# for load balancing to work properly
JkShmFile logs/jk.shm
# Add jkstatus for managing runtime data

JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1

添加workers.properties文件,内容如下:
# Define list of workers that will be used
# for mapping requests
worker.list=loadbalancer,status
# Define Node1
# modify the host as your host IP or DNS name.
worker.node1.port=8009
worker.node1.host=192.168.0.13
worker.node1.type=ajp13
worker.node1.lbfactor=1
# Define Node2
# modify the host as your host IP or DNS name.
worker.node2.port=8009
worker.node2.host= 192.168.0.14
worker.node2.type=ajp13
worker.node2.lbfactor=1
# Define Node3
# modify the host as your host IP or DNS name.
#worker.node3.port=8009
#worker.node3.host= 192.168.0.15
#worker.node3.type=ajp13
#worker.node3.lbfactor=1
# Load-balancing .
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=0
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status
 
注意:参数的意义。
worker.node1.host、worker.node2.host和worker.node3.host要改成jboss集群各机器的实际IP.
如果有更多的节点,顺序定义更多的node段,并在worker.loadbalancer.balance_workers后全部列出.
lbfactor是负载分配权重,值越大分配的负载越多.
Jboss提出 粘着session( sticky session)概念。使用粘着session后,来自同一IP的请求将被发送到同一个Jboss节点,从而保证session使用的连续性。如果应用中没有使用session,则可以使用非粘着session的jboss集群。这样,负载分布更为合理。设置方法是编辑worker.loadbalancer.sticky_session。设置为1使用粘着session,设置为0不使用粘着session。
 
配置集群服务器结点:
一、安装JDK
1.检查JDK版本
#rpm -qa|grep gcj
移除低版本的jdk,
#yum -y remove java-1.4.2-gcj-compat
记录下移除的相关依赖包为如下:
Dependency Removed: antlr.i386 0:2.7.6-4jpp.2 bsf.i386 0:2.3.0-11jpp.1 bsh.i386 0:1.3.0-9jpp.1 eclipse-ecj.i386 1:3.2.1-19.el5.centos gjdoc.i386 0:0.7.7-12.el5 hsqldb.i386 1:1.8.0.9-1jpp.2 jakarta-commons-codec.i386 0:1.3-7jpp.2 jakarta-commons-httpclient.i386 1:3.0-7jpp.1 jakarta-commons-logging.i386 0:1.0.4-6jpp.1 java-1.4.2-gcj-compat-devel.i386 0:1.4.2.0-40jpp.115 java-1.4.2-gcj-compat-javadoc.i386 0:1.4.2.0-40jpp.115 java-1.4.2-gcj-compat-src.i386 0:1.4.2.0-40jpp.115 junit.i386 0:3.8.2-3jpp.1 ldapjdk.i386 0:4.18-2jpp.3.el5 openoffice.org-calc.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-core.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-draw.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-graphicfilter.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-impress.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-langpack-zh_CN.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-langpack-zh_TW.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-math.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-writer.i386 1:2.3.0-6.5.4.el5_2 openoffice.org-xsltfilter.i386 1:2.3.0-6.5.4.el5_2 tomcat5-jsp-2.0-api.i386 0:5.5.23-0jpp.7.el5_2.1 tomcat5-servlet-2.4-api.i386 0:5.5.23-0jpp.7.el5_2.1 xalan-j2.i386 0:2.7.0-6jpp.1 xerces-j2.i386 0:2.7.1-7jpp.2 xml-commons-apis.i386 0:1.3.02-0.b2.7jpp.10 xml-commons-resolver.i386 0:1.1-1jpp.12 xmlrpc.i386 0:2.0.1-3jpp.1
下载:jdk-6u12-linux-i586-rpm.bin二进制文件,增加该文件为可执行权限
#chmod +x jdk-6u12-linux-i586-rpm.bin
直接执行安装jdk
./jdk-6u12-linux-i586-rpm.bin
设置Java路径。
vi /etc/profile,同时也编辑~/.bashrc在结尾增加:
JAVA_HOME=/usr/java/jdk1.5.0_12
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=.:$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH
用JDK代替Redhat Linux AS4预装的gcj
cd /usr/bin
ln -s -f /usr/java/jdk1.5.0_12/bin/java
ln -s -f /usr/java/jdk1.5.0_12/bin/javac
下载jems-installer-1.2.0.GA用图形化界面来安装jboss具体安装详细过程见
[url]http://jijian91.com/blog20071010/jboss-cluster.html[/url]

图形方式

在x windows的终端窗口下,执行java –jar jems-installer-1.2.0.GA.jar,出现Jboss安装图形界面。
选择“中文”。
下一步。
同意协议。
安装路径设置为/usr/local/jboss,下一步。
选择”all”,下一步。
选择”advance”,把Name由default改为all.其余直接按下一步。
输入Admin密码,下一步。
等待安装结束,完成。

命令行方式

java -jar jems-installer-1.2.0.GA.jar -installGroup all installpath=/usr/local/jboss
mv /usr/local/jboss/server/default /usr/local/jboss/server/all
 
修改配置。本例中,提供服务的监听端口是8888,请根据实际情况修改。
vi /usr/local/jboss/server/all/deploy/jbossweb-tomcat55.sar/server.xml
找到 .
注意,jvmRoute是节点号,要与在apache的workers.properties中的定义相对应.
vi /usr/local/jboss/server/all/deploy/jbossweb-tomcat55.sar/META-INF/jboss-service.xml
找到UseJK,改为 true .

配置jboss自动启动

cp /usr/local/jboss/jboss_init_redhat.sh /etc/init.d/jboss
chmod 777 /etc/init.d/jboss
ln –s /etc/init.d/jboss /etc/rc3.d/S80jboss
ln –s /etc/init.d/jboss /etc/rc3.d/K20jboss
ln –s /etc/init.d/jboss /etc/rc4.d/S80jboss
ln –s /etc/init.d/jboss /etc/rc4.d/K20jboss
ln –s /etc/init.d/jboss /etc/rc5.d/S80jboss
ln –s /etc/init.d/jboss /etc/rc5.d/K20jboss
vi /etc/init.d/jboss
将JBOSS_HOME一行改为JBOSS_HOME=${JBOSS_HOME:-”/usr/local/jboss”}
将JBOSS_USER一行改为JBOSS_USER=${JBOSS_USER:-”root”}
将JAVAPTH一行改为JAVAPTH=${JAVAPTH:-”/usr/java/jdk1.5.0_12″}
将JBOSS_CONF一行改为JBOSS_CONF=${JBOSS_CONF:-”all”}
将JBOSSSH一行改为JBOSSSH=${JBOSSSH:-”$JBOSS_HOME/bin/run.sh -c $JBOSS_CONF”}
将. $JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &改为. $JBOSS_CMD_START >${JBOSS_CONSOLE} &
将$SUBIT “$JBOSS_CMD_START >${JBOSS_CONSOLE} 2>&1 &”改为$SUBIT “$JBOSS_CMD_START >${JBOSS_CONSOLE} &”