Apache+Tomcat+JK cluster deployment

When I have nothing to do, I use the company's projects for cluster learning. Although all the methods are found online, it still wastes a lot of my energy, but when I finally see the results, I am still a little happy.

 

The software used includes:

Apache-http-2.2.5

mod_jk.so

tomcat 7

 

1. First configure tomcat

The configuration content is mainly to modify the conf/server.xml under tomcat.

If it is deployed on the same machine, the port that tomcat listens on needs to be modified so that tomcat can start successfully.

change to
<Connector connectionTimeout="20000" port="8082" protocol="HTTP/1.1" redirectPort="8443"/>
<Connector port="8109" protocol="AJP/1.3" redirectPort="8143"/> (both Every port has to be changed, 8109 is connected by mod_jk.so, 8143 is forwarded, I just changed 8143 to the same, so it didn't work at that time).
<Server port="8105" shutdown="SHUTDOWN">

 

 

Open the cluster tag under <Engine>

Start tomcat to see if an error is reported (start your own project normally, I have no test code here, I use the company project directly).

 

2. Configure Apache

Put mod_jk.so in the modules folder under Apache.

Add a new file mod_jk.conf in conf

 The content is:

# Load mod_jk module
LoadModule jk_module modules/mod_jk.so #Load
workers in the cluster
JkWorkersFile conf/workers.properties #Specify
jk's log output file
JkLogFile logs/mod_jk.log #Specify
log level
JkLogLevel warn #Specify
those requests to tomcat for processing , "controller" is the load distribution controller name specified in workers.propertise
JkMount /*.jsp controller
JkMount /* controller

 And create a new file workers.properties

Content is
#server
worker.list = controller
#========tomcat1========
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1
#========tomcat2========
worker.tomcat2.port=8109
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1
#========tomcat3========
#worker.tomcat3.port=13009
#worker.tomcat3.host=192.168.0.80 //在我的虚拟机中的,可以算远程的吧
#worker.tomcat3.type=ajp13
#worker.tomcat3.lbfactor = 1

#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balance_workers=tomcat1,tomcat2
worker.controller.sticky_session=false
worker.controller.sticky_session_force=1
#worker.controller.sticky_session=1

 Edit the file httpd.conf

 Add the last line of the file

include "E:\Program Files\Apache-Http-Server\conf\mod_jk.conf"

 Or you can directly put the contents of the above two files here.

 

3. In order to achieve session sharing

To modify the web.xml in your own project, you only need to add the <distributable/> node to the <web-app/> node . I didn't write this at first, and then tomcat reported an error when requesting.

 

Well, the above is some of my summary.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326756379&siteId=291194637