Environment
System: CentOS 7.3
apache:2.4.27
modjk:1.2.42
tomcat:8.5
jdk:1.8.92
apr:1.6.2
apr-util:1.6.0
Turn off all firewalls and selinux
Systemctlstop Firewalldserviceiptables Stopsetenforce0
First,Installing Apache
1. Installation Dependencies
Yum-y install wget gcc gcc-c++ncurses ncurses-devel cmake make Perl bison OpenSSL openssl-devel gcc* libxml2libxml2-devel Curl-devel libjpeg* libpng* freetype* pcre-devel bzip2-devellibmcrypt-devel libmhash libexpat1 Libexpat1-dev
2. Install Apr
Tar xzvf apr-1.6.2.tar.gz; cdapr-1.6.2;. /configure--prefix=/usr/local/aprmake && make Install
3. Installing Apr-util
Tar xzvf apr-util-1.6.0.tar.gz; Cdapr-util-1.6.0./configure--prefix=/usr/local/apr-util--with-apr=/usr/local/apr/ Make && make install
4. Installing apache2.4
Tar xzvf httpd-2.4.27.tar.gz; cdhttpd-2.4.27
Before compiling Apache to be extracted after the APR and Apr-util copy a point to Apache extracted from the source directory of the Srclib subdirectory one, or will error. Configure:error:BundledAPR requested but not found at./srclib/. Download and unpack the CORRESPONDINGAPR and Apr-util packages to./srclib/.
Cp-a apr-1.6.2httpd-2.4.27/srclib/aprcp-a apr-util-1.6.0httpd-2.4.27/srclib/apr-util./configure--prefix=/usr/ Local/apache--with-included-apr--enable-so--enable-deflate=shared--enable-expires=shared--enable-rewrite= Shared--enable-static-support--with-mpm=worker--disable-userdir--enable-proxy-balancer-- Enable-proxy-http--enable-proxy-connect--enable-proxy--enable-rewrite--enable-proxy-ajpmake && make Install
5. Install mod JK
Tar xzvftomcat-connectors-1.2.42-src.tar.gz; CD tomcat-connectors-1.2.42-src/native./configure--with-apxs=/usr/ Local/apache/bin/apxsmake && make Install
Second,Installing Tomcat
1. Installing the JDK
rpm-ivhjdk-8u92-linux-x64.rpm
2. Installing and configuring Tomcat
Tar xzvfapache-tomcat-8.5.15.tar.gz-c/usr/local/
Extract two tomcat, named Tomcat1 TOMCAT2
Because we're experimenting on the same machine, we're going to modify the second Tomcat HTTP and AJP ports to avoid port collisions. No longer described here.
Modify Server.xml following several places
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCAT1" >
Here you add a tomcat1, as a route for the next mod JK Forwarding, and the other for TOMCAT2
Define the program site root directory here
<valveclassname= "Org.apache.catalina.valves.AccessLogValve" directory= "Logs" prefix= "Localhost_access_log." suffix= ". txt" pattern= "common" resolvehosts= "false"/>
This defines the log and format
3. Start Tomcat
sh/usr/local/tomcat1/bin/catalina.sh startsh/usr/local/tomcat2/bin/catalina.sh Start
Test two tomcat for normal access, return 200 to normal, and browse for tests. Test it according to the port you have changed.
curl-i192.168.2.72:8080curl-i192.168.2.72:8180
Third,Configure Apache mod JK forwarding1. Find LoadModule Add in httpd.conf
LoadModule Jk_module modules/mod_jk.so
Open and add the following two lines to open the configuration of Vhost and MOD_JK
Include Conf/extra/httpd-vhosts.confinclude conf/mod_jk.conf
2. Create mod_jk.conf in Apache's conf directory
#cat mod_jk.conf
jkworkersfileconf/workers.propertiesjklogfile/usr/local/apache/logs/jk.logjkshmfile/usr/local/apache/logs/ Jk-runtime-statusjkloglevelerrorjklogstampformat "[%d%h:%m:%s]" Jkoptions+forwardkeysize +ForwardURICompat- Forwarddirectoriesjkrequestlogformat "%w%V%u%q%s%T"
3. Create a Workers.properties file
# Cat Workers.properties
worker.list=controller,tomcat1,tomcat2 # Tomcat1worker.tomcat1.port=8009worker.tomcat1.host=127.0.0.1worker.tomcat1.type=ajp13worker.tomcat1.lbfactor= 1worker.tomcat1.connection_pool_size=500worker.tomcat1.connection_pool_minsize=25worker.tomcat1.connection_ pool_timeout=300worker.tomcat1.socket_timeout=20 worker.tomcat2.port=8109worker.tomcat2.host= 127.0.0.1worker.tomcat2.type=ajp13worker.tomcat2.lbfactor=1worker.tomcat2.connection_pool_size= 500worker.tomcat2.connection_pool_minsize=25worker.tomcat2.connection_pool_timeout=300worker.tomcat2.socket_ Timeout=20 #========controllertomcat online =======worker.controller.type= lbworker.controller.balanced_workers=tomcat1,tomcat2worker.controller.sticky_session= 1worker.controller.connection_pool_size=1000worker.controller.connection_pool_minsize= 50worker.controller.connection_pool_timeout=300worker.controller.socket_timeout=20
4, Configuration httpd-vhosts.conf
<VirtualHost*:80> ServerName www.yy.com DocumentRoot "/WWW/1" errorlog "Logs/yy-error_log" customlog "Logs/yy-access_log" common JkMount /*.html* controller jkmount /*.tt* controller jkmount /*.index* controller <directory /> AllowOverride none Options -Indexes AllowOverride All Require all granted &nbsP; </directory></virtualhost>
[[email protected] www]# LS1 2[[email protected] www]# ls *1:1.tt index.html2:1.tt index.html
/WWW/1 and/WWW/2 are the root directories of TOMCAT1 and TOMCAT2 respectively. The same file name is placed inside, but the content is different. Then refresh the browser to see if the content will change, and if it will succeed on the main TD forward.
Jkmount/*.html* Controller
This is the definition of all. HTML requests are forwarded to Tomcat processing, here is the experiment, production should be moving too much content sent to Tomcat processing, such as JSP.
This article is from the "Dandelion Secret" blog, please be sure to keep this source http://yylinfan.blog.51cto.com/8670422/1953594
Apache Tomcat AJP MoD JK