Have the experience of server building know that if you do Java development, the combination of Tomcat and Apache has the following advantages: 1, using Apache to do load balancing and fault tolerance; 2,apache focus on static web analytics, Tomcat focus on Dynamic web analytics, This can increase server efficiency by 3, and the application can be upgraded seamlessly.
Recently used Ubuntu12.04 to do the server (the principle should not use the latest version and should use a stable version), read a lot about Apache and Tomcat integration of the book, and finally found that the contents of the book on the ubuntu12.04 for a little discrepancy. The following summary of experience for your reference:
Install Apache and Tomcat and install MOD_JK (sudo apt-get install libapache2-mod-jk) This is not to say, this is the premise.
First, AJP connector
TOMCAT6 provides a AJP connector implementation for the AJP protocol as a Java class, which is included in the Tomcat release version. First you should define the connector in $catalina_home/server.xml:
The code is as follows |
Copy Code |
<--Define a AJP1.3 Connector on port 8009--> <connector port= "8009" protocol= "AJP1.3" redirectport= "8443"/> |
Generally the annotation can be removed, not to add their own.
Ii. Preparation of Workers.properties documents
The Workers.properties file is used to define some variables that are connected to Tomcat, and you don't have to create it yourself, and you've created a/etc/libapache2-mod-jk/directory when you install the LIBAPACHE2-MOD-JK package. You can modify him directly:
The code is as follows |
Copy Code |
? $ sudo nano/etc/libapache2-mod-jk/workers.properties |
The following row is found to modify it:
The code is as follows |
Copy Code |
? worker.list=myworker worker.myworker.port=8009 Worker.myworker.host=localhost//If you are on a different server please modify it to the corresponding host IP Worker.myworker.type=ajp13 Worker.myworker.lbfactory=1 Worker.loadbalancer.type=lb Worker.loadbalancer.balance_workers=myworker |
Third, configure/etc/apache2/apache2.conf (here is recommended to the/etc/apache2/conf.d/directory to create mod_jk files, in which the content of this step is the same)
? #告诉JK到哪里去找workers. Properties
Jkworkersfile/etc/libapache2-mod-jk/workers.properties #重启apache后如果出现allow once prompts, please comment out this line
The code is as follows |
Copy Code |
#定义JK日志位置 Jklogfile/var/log/apache2/mod_jk.log
#设置JK日志的级别 (Debug/error/info) Jkloglevel Info
Set log format Jklogstampformat "[%a%b%d%h:%m:%s%Y]"
# JK Options Jkoption +forwardkeysize +forwarduricompat-forwarddirectories
#设置请求格式 Jkrequestlogformat "%w%V%T"
|
Configuration of Virtual Host
The code is as follows |
Copy Code |
$ sudo nano/etc/apache2/sites-available/default |
Add the following code at the end:
The code is as follows |
Copy Code |
? ..... </Directory>
Jkmount/*.jsp Myworker #把所以jsp页面请求都交给myworker处理 Jkunmount/*.php Myworker #所有的php页面请求都不交给myworker处理
</VirtualHost>
|
Five, should pay attention to:
Many books say that you want to add mod_jk.so to the Apache module directory, but if you apt-get install LIBAPACHE2-MOD-JK through sudo, you don't need it, and you automatically write LoadModule for it.