论坛首页 Java企业应用论坛

Jboss 4.2.3GA 集群配置指南

浏览 5888 次
精华帖 (0) :: 良好帖 (1) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2009-02-18   最后修改:2009-02-18

<!----><!----> <!---->

说明:本配置仅限于jboss的web server在windows环境下的集群,不涉及jboss cache,ejbs,jndi等内容,jboss版本为4.2.3GA .主要参考文档《JBoss Application Server 5 Clustering Guide》(附件中).

1、环境准备:

a. 安装JDK 1.5 ,并配置环境变量;

b. 安装jboss 4.2.3.GA,下载地址:http://www.jboss.org/jbossas/downloads/ ;

c. 安装apache_2.2.10 ,下载地址:http://httpd.apache.org/ ;

d.下载apache mod_jk , 地址为:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/ ;

2、负载均衡配置:

a. 将下载的apache mod_jk重命名为mod_jk.so,复制到APACHE_HOME/modules/中,修改 APACHE_HOME/conf/httpd.conf  ,在文件末添加:


# Include mod_jk's specific configuration file
Include conf/mod-jk.conf

 

 
b. 在APACHE_HOME/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
# 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
<Location /jkstatus/>
JkMount status
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>

c. 在 在APACHE_HOME/conf/目录创建新文件uriworkermap.properties,置为空,这个文件主要是做url 路由的,基本格式为/url=worker_name;


d. 在 在APACHE_HOME/conf/目录创建新文件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=node1.mydomain.com
worker.node1.type=ajp13
worker.node1.lbfactor=1
worker.node1.cachesize=10
# Define Node2
# modify the host as your host IP or DNS name
worker.node2.port=8009
worker.node2.host= node2.mydomain.com
worker.node2.type=ajp13
worker.node2.lbfactor=1
worker.node2.cachesize=10
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2
worker.loadbalancer.sticky_session=1
#worker.list=loadbalancer
# Status worker for managing load balancer
worker.status.type=status

 

上面的文件中配置了两个节点,name分别为node1,node2,指定两个节点的IP,并在worker.loadbalancer.balance_workers中指定所有的node列表,worker.loadbalancer.sticky_session设置是否启用“粘着的”Session,sticky session是指来自同一IP的请求将被发送到同一个Jboss节点,sticky session设为0的话同一session的不同请求会被负载均衡分发到不同的jboss节点上。


3、JBoss节点配置:


a . 修改JBOSS_HOME/server/all/deploy/jboss-web.deployer/server.xml文件,将Engine 修改如下:


<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
...
</Engine>

 

 

node1和node2分别对应相应ip的jboss;


b. 修改 JBOSS_HOME/server/all/deploy/ jboss-web.deployer /META-INF/jbossservice.xml,找到<attribute name="UseJK">该为:


<attribute name="UseJK">true</attribute>

 

至此,jboss集群环境已经基本配置完成,启动先启动apache,然后启动jboss,可测试,启动jboss时需指定run.bat -c all ,default配置是不支持集群的。

4、Session同步


a. 编辑JBOSS_HOME/server/all/deploy/jbossweb-cluster.sar/META-INF/jboss-service.xml,找到<attribute name="ClusterConfig">,有udp和tcp两种方式,任选一种即可,将bind_addr改为本机ip,<tcpping initial_hosts 值设为:node1 IP[7810],node2 IP[7810] ;


b. 修改应用程序的web.xml文件,如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
	<distributable />
 ... 
</web-app>


c. 在web-inf中添加jboss-web.xml文件,内容如下:


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC
    "-//JBoss//DTD Web Application 4.2//EN"
    "http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
	<replication-config>
		<replication-trigger>SET_AND_NON_PRIMITIVE_GET</replication-trigger>
			<replication-granularity>SESSION</replication-granularity>
			<replication-field-batch-mode>true</replication-field-batch-mode>
	</replication-config>
	<context-root>/</context-root>
</jboss-web>
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics