November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

Categories

November 2024
M T W T F S S
 123
45678910
11121314151617
18192021222324
252627282930  

centos under tomcat and apache integration

First need to install apache, installation steps, see its official website, and then install apache jk module

1.1. Wget http://mirror.bjtu.edu.cn/apache//tomcat/tomcat-connectors/jk/source/jk-1.2.31/tomcat-connectors-1.2.31-src.tar.gz
1.2. Tar-xzvf tomcat-connectors-1.2.31-src.tar.gz
1.3. Cd tomcat-connectors-1.2.31-src/native
1.4 .. / configure – with-apxs = / usr/local/apache2/bin/apxs # / usr/local/apache2 / your apache installation directory
1.5. Make
The 1.6. Cp apache-2.0/mod_jk.so / usr/local/apache2/modules/mod_jk.so, and then restart apache
1.7 into the apache installation directory, cd / usr/local/apache2 /

2. Configuration mod_jk.conf
2.1. Cd conf, vi mod_jk.conf
2.2 to edit the following:

# Global config
# Just configure log and load module
# Load module
The LoadModule jk_module modules / mod_jk.so # said the import jk module

JkLogFile logs / mod_jk.log # logs to save
JkLogStampFormat “[% a% b% d% H:% M:% S% Y]” # log timestamp format
JkRequestLogFormat “% w% V% U% T” # log records the contents of the
JkLogLevel warn
JkWorkersFile conf / workers.properties # worker configuration file is loaded

# All vhost should inherit this config
The virtual host JkMountCopy All # copy the configuration file

2.3 JkRequestLogFormat parameter description:

% B Bytes sent, excluding HTTP headers (CLF format)
% B Bytes sent, excluding HTTP headers
% H The request protocol
% M The request method
% P The canonical Port of the server serving the request
% Q The query string (prepended with a? If a query string exists, otherwise an empty string)
% R First line of request
% S Request HTTP status code
% T Request duration, elapsed time to handle request in seconds ‘.’ Micro seconds
% U The URL path requested, not including any query string.
% V The canonical ServerName of the server serving the request
% V The server name according to the UseCanonicalName setting
% W Tomcat worker name
% R Session route name (available with 1.2.19 and up)

3. Configuration workers.properties

vi workers.properties

# Can access the work machine, status used to monitor the status of the jk a working machine can be understood as a tomcat instance
worker.list = balancer, master, status

# Type represents the type of work the machine, generally type = ajp13 and lb lb load balancing
worker.gmaster.port = 8009
worker.master.host = 10.3.1.22
worker.master.type = ajp13
worker.master.lbfactor = 1 # load balancing factor, if you want this machine carrying the load, can set value
    
# Define web app slave host
worker.slave.port = 9009
worker.slave.host = localhost
worker.slave.type = ajp13
worker.slave.lbfactor = 1

# Define web app balancer
worker.balancer.type = lb # load balancing
worker.balancer.balance_workers = master, lave # load balance work machine, this list of workers can not be placed worker.list
worker.balancer.sticky_session = True # session the request refers to the original tomcat

# Define status
worker.status.type = status # the specified monitoring work machine, you can not set

4. Configuration uriworkermap.properties, and it used to match the tomcat which url is forwarded to

4.1. Vi uriworkermap.properties

# Configure status pattern
/ Jkstatus = status

# Configure balancer patterns
# Just forword *. Jsp, *. Do and page serverlet
/ Appname / *. Jsp = balancer
/ Appname / *. Do = balance
/ Appname / page = balance
/ Appname / * / page = balance
/ Appname / = balance
/ Appname = balance

# Configure admin functionality, the backstage management program can only be matched to a working machine, because the Admin user less
/ Appname / admin / *. Jsp = master
/ Appname / admin / *. Do = master
/ Appname / admin / *. Html = master
/ Appname / admin / page = master
/ Appname / admin / * / page = master
/ Appname / admin / = master

4.2. Matching priority instructions:
The most restrictive URI pattern is applied first. More precisely the URI patterns are sorted by
the number of ‘/’ characters in the pattern (highest number first), and rules with equal numbers
are sorted by their string length (longest first).

If both distinctions still do not suffice, then the defining source of the rule is considered.
 Rules defined in uriworkermap.properties come first, before rules defined by JkMount (Apache)
and inside workers.properties using the mount attribute.

All disabled rules are ignored. Exclusion rules are applied after all normal rules have been applied.

There is no defined behaviour, for the following configuration conflict: using literally the same
URI pattern in the same defining source but with different worker targets.

5. Configuration httpd.conf

vi httpd.conf

Include conf / mod_jk.conf loaded in the last

6. Configuration httpd-vhosts.conf

vi extra / httpd-vhosts.conf

<VirtualHost *:80>
    ServerName yourweb.com
    ServerAdmin your email@mail.com
    DocumentRoot “/ usr/local/apache2/your doc root”
        # Placed Alias block
    RewriteEngine on
    RewriteRule ^ / logging.php * yourapp / admin / [PT]

    The load configuration JkMountFile conf / uriworkermap.properties # rules, only the virtual host effect
</ VirtualHost>

PT passthrough, sent directly apache internal
R denotes redirect
Faster than the the jk match, RewriteRule processing the Rewrite Rules can see apache official website, it can modify many acts like a hook,

7. Use apache Alias apache static file forwarding, static file requests tomcat, services provided directly by apache
This period on <VirtualHost *:80> </ VirtualHost> DocumentRoot general on the next line to

Alias / yourapp / js / var / yourapp_static / js /
<Directory “/var/yourapp_static/js”>
    Options Indexes MultiViews
    AllowOverride None
    Order allow, deny
    Allow from all
</ Directory>

You can also place multiple aliases block

8. Configure tomcat
8.1 Configuring the the jvm memory of vi bin / catalina.sh add on top: JAVA_OPTS = ‘-Xms1000m-Xmx1000m’
8.2 configure ajp connector, configured in server.xml
 <Connector protocol = “AJP/1.3” port = “0”
        channelNioSocket.port = “8009”
        channelNioSocket.redirectPort = “8443”
        channelNioSocket.maxThreads = “256”
        channelNioSocket.maxSpareThreads = “97”
        channelNioSocket.minSpareThreads = “50”
        channelNioSocket.URIEncoding = “UTF-8”
        URIEncoding = “UTF-8”
        channelNioSocket.connectionTimeout = “20000”
        channelNioSocket.keepAliveTimeout = “1000”
        channelNioSocket.bufferSize = “16384” />

    Using nio
8.3 production environment, you can turn off the http connector

9. Configure the number of operating system file descriptor

vi / etc / profile

Add to ulimit-SHn 51200
After the save
 
source / etc / profile

The # general system file descriptor is 1024, you can use ulimit-a view, when a large number of tcp connections, file descriptors might not be enough
Parameter Description:

-H set hard resource limits, once set can not be increased.
-S set the soft resource limit set to increase, but not more than the hard-resource settings.
-A shows all current limit information.
-C core file size units to blocks.
The maximum data size of the segment of the process of-d, in Kbytes.
-F process can create a maximum file blocks.
-L maximum to lock memory size in Kbytes units.
-M maximum memory size in Kbytes for.
-N can open the maximum number of file descriptors.
-P pipe buffer size in Kbytes units.
-S thread stack size in Kbytes units.
-T maximum CPU usage time, in seconds.
-U user maximum available number of processes.
-V process virtual memory available to Kbytes units.

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>