I. Preparations
Install JDK 1.5 or later, Jboss 4.2.3, apache 2.2.x, mod_jk.so
Configure the JAVA_HOME, JBOSS_HOME, and APACHE_HOME Environment Variables
Mod_jk is the plug-in for connecting apache server to Jboss.
Ii. Configuration
Assume that jboss is installed on both servers. The IP addresses are 192.168.1.100 and 192.168.1.101 respectively.
To clarify the configuration steps, we use the configuration directory $ JBOSS_HOME/server/default instead of directly using the configuration directory $ JBOSS_HOME/server/all. Because the default configuration does not support clusters, you must first copy some dependency packages and configuration files configured for all to the defaut configuration directory.
2.1 copy the dependency packages and configuration files for the cluster
Set jbossha under $ JBOSS_HOME/all/lib. jar, jgroups. jar and jboss-cache-jdk50.jar copy to $ JBOSS_HOME/default/lib directory, copy the cluster-service.xml and jboss-web.cluster.sar folders in the $ JBOSS_HOME/server/all/deploy directory to the $ JBOSS_HOME/server/default/deploy directory. the same operation is performed on another server.
Jbossha. jar is used to load org. jboss. ha. framework. server. ClusterPartition,
Jgroups. jar is used to support the underlying communication of Jboss clusters.
The jboss-cache-jdk50.jar is used to load org. jboss. cache. aop. TreeCacheAop
2.2 modify the configuration file
Open $ JBOSS_HOME/server/default/deploy/jboss-web.deployer/server. xml, set <Engine name = "jboss. web "defaultHost =" localhost "> changed to <Engine name =" jboss. web "defaultHost =" localhost "jvmRoute =" node1 ">. here, jvmRoute is used for the Apache server to identify the node name (the name can be left blank, as long as it is followed by the following configuration file workers. properties ). Similarly, change the server. xml file of another server (note: the node name cannot be repeated.
Open $ JBOSS_HOME/server/default/deploy/jboss-web.deployer/ROOT. war/WEB-INF/web. xml and add the <distributable/> tag at the end of <web-app>
Open $ JBOSS_HOME/server/default/deploy/jboss-web.deployer/META-INF/jboss-service.xml and change false in <attribute name = "UseJK"> false </attribute> to true. this will adopt the sticky sesson policy, that is, each session will be processed by a specific jboss.
Configure a Java Web application project. Add a WEB-INF in the jboss-web.xml folder of the Java Web application project with the following content:
01
<? Xml version = "1.0" encoding = "UTF-8"?>
02
<! DOCTYPE jboss-web PUBLIC
03
"-// JBoss // DTD Web Application 4.2 // EN"
04
Http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd>
05
<Jboss-web>
06
<Replication-config>
07
<Replication-trigger> SET_AND_NON_PRIMITIVE_GET </replication-trigger>
08
<Replication-granularity> SESSION </replication-granularity>
09
<Replication-field-batch-mode> true </replication-field-batch-mode>
10
</Replication-config>
11
<Context-root>/jspdemo </context-root> <! -- Replace your Java Web Application name here -->
12
</Jboss-web>
Configure Apache server
A) Open $ APACHE_HOME/conf/httpd. conf and add the following configuration at the end:
01
# Load the mod_jk.so Module
02
LoadModule jk_module modules/mod_jk.so
03
04
#
05
# Configure the mod_jk.so Module
06
#
07
JkWorkersFile conf/workers. properties
08
# Specify which requests are handled by jboss
09
JkMountFile conf/uriworkermap. properties
10
# Mod_jk plug-in logs
11
JkLogFile logs/mod_jk.log
12
# Mod_jk Log Level
13
JkLogLevel warn
B) Create the $ APACHE_HOME/conf/workers. properties file with the following content:
01
# Define list of workers that will be used
02
# For mapping requests
03
Worker. list = loadbalancer, status
04
# Define Node1
05
# Modify the host as your host IP or DNS name and your AJP 1.3 port
06
Worker. node1.port = 6009
07
Worker. node1.host = 127.0.0.1
08
Worker. node1.type = ajp13
09
Worker. node1.lbfactor = 1
10
Worker. node1.socket _ timeout = 60
11
Worker. node1.connection _ pool_timeout = 60
12
Worker. node1.ping _ mode =
13
Worker. node1.ping _ timeout = 20000
14
Worker. node1.connect _ timeout = 20000
15
16
# Define Node2
17
# Modify the host as your host IP or DNS name and your AJP 1.3 port
18
Worker. node2.port = 7009
19
Worker. node2.host = 127.0.0.1
20
Worker. node2.type = ajp13
21
Worker. node2.lbfactor = 1
22
Worker. node2.socket _ timeout = 60
23
Worker. node2.connection _ pool_timeout = 60
24
Worker. node2.ping _ mode =
25
Worker. node2.ping _ timeout = 20000
26
Worker. node2.connect _ timeout = 20000
27
28
# Load-balancing behaviour
29
Worker. loadbalancer. type = lb
30
Worker. loadbalancer. balance_workers = node1, node2
31
Worker. loadbalancer. sticky_session = true
32
Worker. loadbalancer. sticky_session_force = false
33
34
# Status worker for managing load balancer
35
Worker. status. type = status
C) Create the $ APACHE_HOME/conf/uriworkermap. properties file with the following content:
01
# All requests are forwarded to the Server Load balancer (mod_jk.so ).
02
/* = Loadbalancer
03
04
# You can declare that requests to some static resources do not need to be handed over to jboss for processing. In this case, you need to copy these static resources (such as gif, jpg, css, and other files)
05
# Deployment directory of the Apache server
06
#! /*. Gif = loadbalancer
07
#! /*. Jpg = loadbalancer
08
#! /*. Png = loadbalancer
09
#! /*. Css = loadbalancer
10
#! /*. Js = loadbalancer
11
#! /*. Htm = loadbalancer
12
#! /*. Html = loadbalancer
D) Copy mod_jk.so to $ APACHE_HOME/modules.
Iii. Test
Deploy the same Java Web project on two Jboss servers (for example, record the JSP page access times through session cache ). Start Apache and test Jboss.
Patriot blog