{"id":1140,"date":"2012-08-27T15:48:03","date_gmt":"2012-08-27T07:48:03","guid":{"rendered":"http:\/\/rmohan.com\/?p=1140"},"modified":"2012-08-27T15:48:03","modified_gmt":"2012-08-27T07:48:03","slug":"centos-under-tomcat-and-apache-integration","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=1140","title":{"rendered":"centos under tomcat and apache integration"},"content":{"rendered":"<p>First need to install apache, installation steps, see its official website, and then install apache jk module<\/p>\n<p>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<br \/>1.2. Tar-xzvf tomcat-connectors-1.2.31-src.tar.gz<br \/>1.3. Cd tomcat-connectors-1.2.31-src\/native<br \/>1.4 .. \/ configure &#8211; with-apxs = \/ usr\/local\/apache2\/bin\/apxs # \/ usr\/local\/apache2 \/ your apache installation directory<br \/>1.5. Make<br \/>The 1.6. Cp apache-2.0\/mod_jk.so \/ usr\/local\/apache2\/modules\/mod_jk.so, and then restart apache<br \/>1.7 into the apache installation directory, cd \/ usr\/local\/apache2 \/<\/p>\n<p>2. Configuration mod_jk.conf<br \/>2.1. Cd conf, vi mod_jk.conf<br \/>2.2 to edit the following:<\/p>\n<p># Global config<br \/># Just configure log and load module<br \/># Load module<br \/>The LoadModule jk_module modules \/ mod_jk.so # said the import jk module<\/p>\n<p>JkLogFile logs \/ mod_jk.log # logs to save<br \/>JkLogStampFormat &#8220;[% a% b% d% H:% M:% S% Y]&#8221; # log timestamp format<br \/>JkRequestLogFormat &#8220;% w% V% U% T&#8221; # log records the contents of the<br \/>JkLogLevel warn<br \/>JkWorkersFile conf \/ workers.properties # worker configuration file is loaded<\/p>\n<p># All vhost should inherit this config<br \/>The virtual host JkMountCopy All # copy the configuration file<\/p>\n<p>2.3 JkRequestLogFormat parameter description:<\/p>\n<p>% B Bytes sent, excluding HTTP headers (CLF format)<br \/>% B Bytes sent, excluding HTTP headers<br \/>% H The request protocol<br \/>% M The request method<br \/>% P The canonical Port of the server serving the request<br \/>% Q The query string (prepended with a? If a query string exists, otherwise an empty string)<br \/>% R First line of request<br \/>% S Request HTTP status code<br \/>% T Request duration, elapsed time to handle request in seconds &#8216;.&#8217; Micro seconds<br \/>% U The URL path requested, not including any query string.<br \/>% V The canonical ServerName of the server serving the request<br \/>% V The server name according to the UseCanonicalName setting<br \/>% W Tomcat worker name<br \/>% R Session route name (available with 1.2.19 and up)<\/p>\n<p>3. Configuration workers.properties<\/p>\n<p>vi workers.properties<\/p>\n<p># Can access the work machine, status used to monitor the status of the jk a working machine can be understood as a tomcat instance<br \/>worker.list = balancer, master, status<\/p>\n<p># Type represents the type of work the machine, generally type = ajp13 and lb lb load balancing<br \/>worker.gmaster.port = 8009<br \/>worker.master.host = 10.3.1.22<br \/>worker.master.type = ajp13<br \/>worker.master.lbfactor = 1 # load balancing factor, if you want this machine carrying the load, can set value<br \/>\u00a0\u00a0\u00a0\u00a0<br \/># Define web app slave host<br \/>worker.slave.port = 9009<br \/>worker.slave.host = localhost<br \/>worker.slave.type = ajp13<br \/>worker.slave.lbfactor = 1<\/p>\n<p># Define web app balancer<br \/>worker.balancer.type = lb # load balancing<br \/>worker.balancer.balance_workers = master, lave # load balance work machine, this list of workers can not be placed worker.list<br \/>worker.balancer.sticky_session = True # session the request refers to the original tomcat<\/p>\n<p># Define status<br \/>worker.status.type = status # the specified monitoring work machine, you can not set<\/p>\n<p>4. Configuration uriworkermap.properties, and it used to match the tomcat which url is forwarded to<\/p>\n<p>4.1. Vi uriworkermap.properties<\/p>\n<p># Configure status pattern<br \/>\/ Jkstatus = status<\/p>\n<p># Configure balancer patterns<br \/># Just forword *. Jsp, *. Do and page serverlet<br \/>\/ Appname \/ *. Jsp = balancer<br \/>\/ Appname \/ *. Do = balance<br \/>\/ Appname \/ page = balance<br \/>\/ Appname \/ * \/ page = balance<br \/>\/ Appname \/ = balance<br \/>\/ Appname = balance<\/p>\n<p># Configure admin functionality, the backstage management program can only be matched to a working machine, because the Admin user less<br \/>\/ Appname \/ admin \/ *. Jsp = master<br \/>\/ Appname \/ admin \/ *. Do = master<br \/>\/ Appname \/ admin \/ *. Html = master<br \/>\/ Appname \/ admin \/ page = master<br \/>\/ Appname \/ admin \/ * \/ page = master<br \/>\/ Appname \/ admin \/ = master<\/p>\n<p>4.2. Matching priority instructions:<br \/>The most restrictive URI pattern is applied first. More precisely the URI patterns are sorted by<br \/>the number of &#8216;\/&#8217; characters in the pattern (highest number first), and rules with equal numbers<br \/>are sorted by their string length (longest first).<\/p>\n<p>If both distinctions still do not suffice, then the defining source of the rule is considered.<br \/>\u00a0Rules defined in uriworkermap.properties come first, before rules defined by JkMount (Apache)<br \/>and inside workers.properties using the mount attribute.<\/p>\n<p>All disabled rules are ignored. Exclusion rules are applied after all normal rules have been applied.<\/p>\n<p>There is no defined behaviour, for the following configuration conflict: using literally the same<br \/>URI pattern in the same defining source but with different worker targets.<\/p>\n<p>5. Configuration httpd.conf<\/p>\n<p>vi httpd.conf<\/p>\n<p>Include conf \/ mod_jk.conf loaded in the last<\/p>\n<p>6. Configuration httpd-vhosts.conf<\/p>\n<p>vi extra \/ httpd-vhosts.conf<\/p>\n<p>&lt;VirtualHost *:80&gt;<br \/>\u00a0\u00a0\u00a0\u00a0ServerName yourweb.com<br \/>\u00a0\u00a0\u00a0\u00a0ServerAdmin your email@mail.com<br \/>\u00a0\u00a0\u00a0\u00a0DocumentRoot &#8220;\/ usr\/local\/apache2\/your doc root&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0# Placed Alias block<br \/>\u00a0\u00a0\u00a0\u00a0RewriteEngine on<br \/>\u00a0\u00a0\u00a0\u00a0RewriteRule ^ \/ logging.php * yourapp \/ admin \/ [PT]<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0The load configuration JkMountFile conf \/ uriworkermap.properties # rules, only the virtual host effect<br \/>&lt;\/ VirtualHost&gt;<\/p>\n<p>PT passthrough, sent directly apache internal<br \/>R denotes redirect<br \/>Faster than the the jk match, RewriteRule processing the Rewrite Rules can see apache official website, it can modify many acts like a hook,<\/p>\n<p>7. Use apache Alias apache static file forwarding, static file requests tomcat, services provided directly by apache<br \/>This period on &lt;VirtualHost *:80&gt; &lt;\/ VirtualHost&gt; DocumentRoot general on the next line to<\/p>\n<p>Alias \/ yourapp \/ js \/ var \/ yourapp_static \/ js \/<br \/>&lt;Directory &#8220;\/var\/yourapp_static\/js&#8221;&gt;<br \/>\u00a0\u00a0\u00a0\u00a0Options Indexes MultiViews<br \/>\u00a0\u00a0\u00a0\u00a0AllowOverride None<br \/>\u00a0\u00a0\u00a0\u00a0Order allow, deny<br \/>\u00a0\u00a0\u00a0\u00a0Allow from all<br \/>&lt;\/ Directory&gt;<\/p>\n<p>You can also place multiple aliases block<\/p>\n<p>8. Configure tomcat<br \/>8.1 Configuring the the jvm memory of vi bin \/ catalina.sh add on top: JAVA_OPTS = &#8216;-Xms1000m-Xmx1000m&#8217;<br \/>8.2 configure ajp connector, configured in server.xml<br \/>\u00a0&lt;Connector protocol = &#8220;AJP\/1.3&#8221; port = &#8220;0&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.port = &#8220;8009&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.redirectPort = &#8220;8443&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.maxThreads = &#8220;256&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.maxSpareThreads = &#8220;97&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.minSpareThreads = &#8220;50&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.URIEncoding = &#8220;UTF-8&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0URIEncoding = &#8220;UTF-8&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.connectionTimeout = &#8220;20000&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.keepAliveTimeout = &#8220;1000&#8221;<br \/>\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0channelNioSocket.bufferSize = &#8220;16384&#8221; \/&gt;<\/p>\n<p>\u00a0\u00a0\u00a0\u00a0Using nio<br \/>8.3 production environment, you can turn off the http connector<\/p>\n<p>9. Configure the number of operating system file descriptor<\/p>\n<p>vi \/ etc \/ profile<\/p>\n<p>Add to ulimit-SHn 51200<br \/>After the save<br \/>\u00a0<br \/>source \/ etc \/ profile<\/p>\n<p>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<br \/>Parameter Description:<\/p>\n<p>-H set hard resource limits, once set can not be increased.<br \/>-S set the soft resource limit set to increase, but not more than the hard-resource settings.<br \/>-A shows all current limit information.<br \/>-C core file size units to blocks.<br \/>The maximum data size of the segment of the process of-d, in Kbytes.<br \/>-F process can create a maximum file blocks.<br \/>-L maximum to lock memory size in Kbytes units.<br \/>-M maximum memory size in Kbytes for.<br \/>-N can open the maximum number of file descriptors.<br \/>-P pipe buffer size in Kbytes units.<br \/>-S thread stack size in Kbytes units.<br \/>-T maximum CPU usage time, in seconds.<br \/>-U user maximum available number of processes.<br \/>-V process virtual memory available to Kbytes units.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>First need to install apache, installation steps, see its official website, and then install apache jk module<\/p>\n<p>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.gz1.2. Tar-xzvf tomcat-connectors-1.2.31-src.tar.gz1.3. Cd tomcat-connectors-1.2.31-src\/native1.4 .. \/ configure &#8211; with-apxs = \/ usr\/local\/apache2\/bin\/apxs # \/ usr\/local\/apache2 \/ your apache installation directory1.5. MakeThe 1.6. Cp apache-2.0\/mod_jk.so \/ usr\/local\/apache2\/modules\/mod_jk.so, and then restart apache1.7 into the apache installation directory, [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1140"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1140"}],"version-history":[{"count":2,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1140\/revisions"}],"predecessor-version":[{"id":1142,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/1140\/revisions\/1142"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}