For Web application cluster learning, I started from tomcat5.5. Below are some of my practical operations and experiences.
Section 1 Environment
Server Load balancer
*
Operating System: Windows XP
IP Address: 192.168.1.200
Apache: apache_2.2.13-win32-x86-openssl-0.9.8k.msi
Mod_jk: mod_jk-1.2.28-httpd-2.2.3.so (for Windows)
Cluster Environment tomcat1
*
Operating System: SuSE linuxe Server 10
IP Address: 192.168.1.114
Tomcat: APACHE-Tomcat-5.5.28
Cluster Environment tomcat2
*
Operating System: SuSE linuxe Server 10
IP Address: 192.168.1.113
Tomcat: APACHE-Tomcat-5.5.28
Part 2 Server Load balancer Configuration
Step 1: install Apache. The installation directory is C:/apache2.2.
Step 2: copy the mod_jk-1.2.28-httpd-2.2.3.so file to the % apache_home %/modules directory
Step 3: modify the configuration file % apache_home %/CONF/httpd. conf
Add the following line at the end of the file % apache_home %/CONF/httpd. conf: Include CONF/mod_jk.conf
# Zhangzk <br/> include conf/mod_jk.conf
Step 4: Create the file mod_jk.conf under the directory % apache_home %/CONF.
# Load mod_jk module <br/> loadmodule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so <br/> # specify workers. properties file path <br/> jkworkersfile CONF/workers. properties <br/> # specify which requests are sent to Tomcat for processing <br/> # "controller" is in workers. the name of the Server Load balancer controller specified in propertise <br/> jkmount /*. JSP Controller
Step 5: Create the workers. properties file in the directory % apache_home %/CONF.
# Server <br/> worker. list = controller </P> <p >#========= worker AT1 =======< br/> worker. tomcat1.port = 8009 <br/> worker. tomcat1.host = 192.168.1.114 <br/> worker. tomcat1.type = ajp13 <br/> worker. tomcat1.lbfactor = 1 </P> <p >#========= tomcat2 =======< br/> worker. tomcat2.port = 8009 <br/> worker. tomcat2.host = 192.168.1.113 <br/> worker. tomcat2.type = ajp13 <br/> worker. tomcat2.lbfactor = 1 </P> <p >#========= controller, Server Load balancer controller =======< br/> worker. controller. type = LB <br/> worker. controller. balanced_workers = worker at1, tomcat2 <br/> worker. controller. sticky_session = 1
Now the Server Load balancer has been configured.
Start tomcat1 and tomcat2 respectively. Apache can distribute *. jsp requests to tomcat1 and tomcat2.
Part 3 tomcat cluster configuration
Step 1: remove the notes for cluster configuration nodes in the % tomcat_home %/CONF/server. xml file
The following section of the file
<! -- <Br/> <Cluster className = "org. apache. catalina. cluster. tcp. simpleTcpCluster "<br/> managerClassName =" org. apache. catalina. cluster. session. deltaManager "<br/> expireSessionsOnShutdown =" false "<br/> useDirtyFlag =" true "<br/> yylistenersonreplication =" true "> <br/> ...... <br/> </Cluster> <br/> -->
Modify it to the following format (... indicates that a code segment is not displayed in the middle)
<Cluster className = "org. apache. catalina. cluster. tcp. simpleTcpCluster "<br/> managerClassName =" org. apache. catalina. cluster. session. deltaManager "<br/> expireSessionsOnShutdown =" false "<br/> useDirtyFlag =" true "<br/> yylistenersonreplication =" true "> <br/> ...... <br/> </Cluster>
The above changes must be handled in both the Cluster Environment tomcat1 and tomcat2.
Step 2: Change the following code in the % tomcat_home %/CONF/server. xml file.
>>> Cluster Environment tomcat1
<Engine name = "Catalina" defaulthost = "localhost">
Change
<Engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat1">
>>> Cluster Environment atat2
<Engine name = "Catalina" defaulthost = "localhost">
Change
<Engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat2">
Step 3:
Add the following code to the Web-info/Web. xml of the Web application to be deployed in Tomcat:
<Distributable/>
After completing the preceding three steps, Tomcat cluster configuration is complete.
When you operate the session. setAttribute (arg1, arg2) method in a WEB application, you can complete Session replication.
Part 1 considerations
The following code snippet in a common Web application can be used to change the attributes of a Session.
Object o = request. getsession (true ). getattribute (login_user_info_key); <br/> userinfo UI = (userinfo) O; <br/> UI. setaccesspagecount (UI. getaccesspagecount () + 1); <br/>
However, in the cluster deployment environment, Session replication cannot be completed, and the following code snippets must be used.
Object o = request. getsession (true ). getattribute (login_user_info_key); <br/> userinfo UI = (userinfo) O; <br/> UI. setaccesspagecount (UI. getaccesspagecount () + 1); <br/> request. getsession (). setattribute (login_user_info_key, UI );