Apache + JBoss multi-instance configuration + Load Balancing (mod_jk implementation)

Source: Internet
Author: User
Tags jboss server

Recently, we need to use the JBoss configuration item to configure the target server Load balancer (it is best to have multiple instances to ensure the concurrency). After a whole day of search and practice, the final success will be recorded here, for future reference by others.

System Environment:
Windows Server 2003
Software environment:
JDK 7 (update 55)
Vc9 (http://www.microsoft.com/download/en/details.aspx? Id = 5582)
Apache httpd 2.2.29 (http://www.apachelounge.com/download/additional)
JBoss-5.1.0.GA (http://jbossas.jboss.org/downloads)
Note: Try to use a specified version of the program, especially JBoss (version differences are too large). Otherwise, an unknown error may occur.

1. Install JDK and configure environment variables (omitted)
2. decompress the httpd server (initialize it)
Note: After decompressing the httpd package, you must manually modify some content in the conf/httpd. conf configuration file (such as servername and DocumentRoot)
3. decompress the JBoss server (not configured for the moment)
4. Configure the httpd server
1. Download mod_jk.so module (http://tomcat.apache.org/download-connectors.cgi), use the corresponding httpd server version file, I am using mod_jk-1.2.31-httpd-2.2.3.so (http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.31)
2. Add the mod_jk module to the httpd server and change the mod_jk-1.2.31-httpd-2.2.3.so to mod_jk.so. Put it in the modules folder.
3. Add the file mod_jk.conf In the conf folder (mainly load the mod_jk module and configure it ):
# Load mod_jk module# Specify the filename of the mod_jk libLoadModule jk_module modules/mod_jk.so# Where to find workers.propertiesJkWorkersFile conf/workers.properties# Where to put jk logsJkLogFile logs/mod_jk.log# Set the jk log level [debug/error/info]JkLogLevel info# Select the log formatJkLogStampFormat "[%a %b %d %H:%M:%S %Y]"# JkOptions indicates to send SSK KEY SIZEJkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories# JkRequestLogFormatJkRequestLogFormat "%w %V %T"# Mount your applicationsJkMount /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/*=loadbalancerJkMountFile 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 properlyJkShmFile logs/jk.shm# Add jkstatus for managing runtime data<Location /jkstatus/>JkMount statusOrder deny,allowDeny from allAllow from 127.0.0.1</Location>

4. Modify CONF/httpd. conf and add the following configuration at the bottom (that is, reference mod_jk.conf ):
#JBoss confInclude conf/mod_jk.conf

5. Add uriworkermap. properties in the conf folder (configure the access path for Server Load balancer, as mentioned in mod_jk.conf ):
/*=loadbalancer

6. Add workers. properties in the conf folder (server node configuration of Server Load balancer, as mentioned in mod_jk.conf ):
Note: worker. node1.port and worker. node2.port are the AJP ports of the server. the ports of the two nodes are 100 different because the Port Offset of multiple instances is set to 100 in the JBoss settings.
# Define list of workers that will be used for mapping requestsworker.list=loadbalancer,status# Load-balancing behaviourworker.loadbalancer.type=lbworker.loadbalancer.balance_workers=node1,node2worker.loadbalancer.sticky_session=1# Status worker for managing load balancerworker.status.type=status# Node1worker.node1.port=8009worker.node1.host=127.0.0.1worker.node1.type=ajp13worker.node1.lbfactor=1worker.node1.cachesize=10# Node2worker.node2.port=8109worker.node2.host=127.0.0.1worker.node2.type=ajp13worker.node2.lbfactor=1worker.node2.cachesize=10

5. configure a JBoss server with multiple instances
Because it is a multi-instance (multi-process, different ports), so we need to use two identical deployment applications, we first copy two copies of the server/All folder after the JBoss decompression, the two folders are server/node1 and server/node2 respectively.
The two folders are the deployment applications started by the two instances. The detailed configuration is as follows:
1. configuration similar to node1 and node2:
(1) modify the server/node1 (node2)/deploy/jbossweb. SAR/server. xml configuration file:
A. Replace $ {JBoss. Bind. Address} with $ {0.0.0.0} (for security reasons, JBoss binds the Server IP address and sets it to 0.0.0.0 to remove the binding restriction)
B. Set <engine name = "JBoss. web "defaulthost =" localhost "> changed to <engine name =" JBoss. for Web "defaulthost =" localhost "jvmroute =" node1 ">, modify node2 (indicating different nodes. The node name must be configured with the httpd server workers. the node names in the properties file are the same)
(2) modify the server/node1 (node2)/deploy/messaging/messaging-service.xml configuration file:
A. Set <attribute name = "serverpeerid" >$ {JBoss. messaging. the value 0 of serverpeerid: 0} </attribute> is changed to 1, and the corresponding position in node2 is changed to 2 (This number indicates the ID of the cluster, which cannot be repeated)
(3) Modify server/node1 (node2)/deployers/jbossweb. deployer/META-INF/war-deployers-jboss-beans.xml file:
A. unconfigure the following four sections and change false to true. The Modification result is used for session synchronization ):
<property name="useJK">true</property><property name="useSessionPassivation">true</property><property name="passivationMaxIdleTime">-1</property>  <property name="passivationMinIdleTime">-1</property>

(4) Modify server/node1 (node2)/CONF/Bootstrap/profile. xml configuration file (add class = "Java. io. file "to avoid errors during startup ):
<bean name="AttachmentStore" class="org.jboss.system.server.profileservice.repository.AbstractAttachmentStore"><constructor><parameter class="java.io.File"><inject bean="BootstrapProfileFactory" property="attachmentStoreRoot" /></parameter></constructor>...</bean>

2. Different node2 configurations:
(1) modify the server/node2/CONF/bindingservice. Beans/META-INF/bindings-jboss-beans.xml configuration file:
A. Set the offset of the port started by JBoss, from 0 to 100 (here is the reason for the AJP port interval 100 in the httpd server ):
<bean name="PortsDefaultBindings"  class="org.jboss.services.binding.impl.ServiceBindingSet">    <constructor>        ...        <parameter>100</parameter>        ...    </constructor></bean>

6. Description of session synchronization in the project:
1. The above JBoss has mentioned session synchronization and modified the configuration of the war-deployers-jboss-beans.xml;
2. modify the configuration of the project (take server/node1 (node2)/deploy/root. War as an example)
(1) modify the WEB-INF/Web. xml file, add <distributable/> (Be sure to pay attention to the order, the order of errors will report the error)
<web-app>  <display-name>Welcome to JBoss</display-name>  <description>     Welcome to JBoss  </description>  <distributable />  <servlet>    <servlet-name>Status Servlet</servlet-name>    <servlet-class>org.jboss.web.tomcat.service.StatusServlet</servlet-class>  </servlet>  <servlet-mapping>    <servlet-name>Status Servlet</servlet-name>    <url-pattern>/status</url-pattern>  </servlet-mapping></web-app>

(2) Add the WEB-INF configuration file under the jboss-web.xml folder (special configuration of JBoss, loaded together with Web. XML)
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd"><jboss-web>    <context-root>/</context-root>    <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></jboss-web>

VII. Test
1. Add the test folder under server/node1 (node2)/deploy/root. War and put it in the test JSP (the attachment is downloaded );
2. Start the Apache httpd server (by using commands or making Windows Services );
3. Start two JBoss instances:
(1) Add two bat batches under the bin folder of JBoss (start the configured node1 and node2 JBoss instances ):
Run-node1.bat, file content (right-click to edit with notepad ):
Run. Bat-C node1
Run-node2.bat, file content (right-click to edit with notepad ):
Run. Bat-C node2
(2) double-click each other to start two JBoss instances (the startup is slow and you need to wait for node1 to start node2 again)
4. Access the test page:
(1) Start browser 1 and access http: // localhost/test/index. jsp as follows:

(2) Start browser 2 and access http: // localhost/test/index. jsp, as shown below:

Note: Server Load balancer is available through sessionid.
VIII. Notes
1. Since each browser only has one session for each access, and no node changes are found in each session of each browser, session synchronization is not tested;
2. Many of the configurations mentioned above are not described in detail (such as the conf setting and a configuration file). If you need to explain them in detail, please search for them by yourself.

Attachment: test.zip

Apache + JBoss configuration of multiple instances + Load Balancing (mod_jk implementation)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.