Configure apache2.2.10 Load Balancing + mod_jk-1.2.28 + atat6 cluster (Linux)

Source: Internet
Author: User

1. install Apache

 

Apache2.2.11 installation and configuration

1. Decompress Apache and read the install file in the httpd directory.

# Tar-zxvf httpd-2.2.11.tar.gz

You can move the obtained folder to the installation directory/usr/local.

# Cd httpd-2.2.11

#./Configure

#./Configure -- prefix =/usr/local/apache2 -- enable-mod-shared = all

# Make

# Make install

# Cd/usr/local/apache2/bin

#./Apachectl start

 

Enter http: // localhost/in the address bar. If the it works welcome page is displayed, the request is successful.

Reference: http://httpd.apache.org/docs/2.2/install.html

 

2 configure Apache/CONF/HTTP. conf

 

My projects are stored in/usr/local/apache2/htdocs (the default directory of Apache)

Add :( make Apache not access the WEB-INF directory)

 

<Directory "/usr/local/apache2/htdocs/WEB-INF">

Order allow, deny

</Directory>

 

Enable the annotation configuration language to set the default Chinese character.

Include CONF/extra/httpd-languages.conf

 

Add: Japanese is supported.

Defaultlanguage ja-JP

Adddefacharcharset UTF-8

 

 

2. Install jk_mod and integrate Apache and tomcat.

1. Copy the downloaded binary mod_jk-1.2.28-httpd-2.2.x.so to the modules directory of Apache.

: Http://apache.mirror.phpchina.com/tomcat/tomcat-connectors/jk/binaries/linux/jk-1.2.28/

 

2. Create two new files, mod_jk.conf and workers. properties, in the conf directory of Apache,

The content of mod_jk.conf is the JK configuration file, including the loading module and log information, as well as the designated parser and directory. Workers. properties is the Tomcat wokers configuration file.

 

3. Add the following content to mod_jk.conf (the mod_jk.conf file is convenient for management, and you do not need to write the configuration in httpd. conf)

 

# Load JK module. The name must correspond

Loadmodule jk_module modules/mod_jk-1.2.28-httpd-2.2.x.so

# Load the newly created workers. properties File

Jkworkersfile CONF/workers. Properties

 

# Jk log file

Jklogfile logs/mod_jk.log

 

# Jk log level. The parameters include [debug/error/info]

Jkshmfile logs/mod_jk.shm

Jkloglevel info

 

# Jk log data format

Jklogstampformat "[% A % B % d % H: % m: % S % Y]"

 

# Some configuration options of JK: Indicate to send SSL key size,

Jkoptions + forwardkeysize + forwarduricompat-forwarddirectories

# JK request log format

Jkrequestlogformat "% w % v % t"

 

# Submit the JSP do Servlet File to Tomcat for processing

Jkmount/servlet/* ajp13

Jkmount/*. jsp ajp13

Jkmount/*. Do ajp13

# Jkmount indicates that Tomcat is used for parsing, while jkunmount indicates that the opposite is true.

 

# Generally, JSP and Servlet programs can be processed by Tomcat, and static file images are still processed by Apache.

 

# Jkautoalias/usr/local/apache2/htdocs *

# All static files in this folder are automatically processed by Apache.

 

Jkmount/servlet/* ajp13

#/Test/servlet/all files are also handed over to Tomcat for processing

 

4. Edit the httpd. conf file of Apache and load the jk_mod.conf file in:

Include CONF/mod_jk.conf

 

5. Edit the workers. properties file and add the following content:

Workers. tomcat_home =/usr/local/tomcat/

Workers. java_home =/usr/Java/JDK/

PS =/

Worker. List = ajp13

Worker. ajp13.port = 8009

Worker. ajp13.host = localhost

Worker. ajp13.type = ajp13

Worker. ajp13.lbfactor = 1

# Configuration reference see http://tomcat.apache.org/connectors-doc/reference/workers.html

 

 

7. Restart Apache for testing

#./Apachectl restart

Open the browser and access the JSP file through the following two addresses respectively. If normal resolution is available, the integration is successful. According to the configuration of Apache and tomcat, test points to the same directory.

Http: // localhost/

Http: // localhost: 8080/

 

In this way, Apache and tomcat are sorted out with jk_mod.

 

3. Configure workers. Properties

 

Worker. list = controller, myworker1, myworker2, myworker3 <br/> worker. myworker1.port = 8009 <br/> worker. myworker1.host = 192.168.0.10 <br/> worker. myworker1.type = ajp13 <br/> worker. myworker1.lbfactor = 1 <br/> worker. list = myworker2 <br/> worker. myworker2.port = 8010 <br/> worker. myworker2.host = 192.168.0.10 <br/> worker. myworker2.type = ajp13 <br/> worker. myworker2.lbfactor = 1 <br/> worker. list = myworker3 <br/> worker. myworker3.port = 8011 <br/> worker. myworker3.host = 192.168.0.10 <br/> worker. myworker3.type = ajp13 <br/> worker. myworker3.lbfactor = 1 <br/> worker. controller. type = LB <br/> worker. controller. balanced_workers = myworker1, myworker2, myworker3 <br/> worker. controller. sticky_session = 1 

 

4. Configure mod_jk

Loadmodule jk_module modules/mod_jk-1.2.28-httpd-2.2.X.so <br/> jkworkersfile CONF/workers. properties <br/> jklogfile logs/mod_jk.log <br/> jkshmfile logs/mod_jk.shm <br/> jklogstampformat "[% A % B % d % H: % m: % S % Y] "<br/> jkrequestlogformat" % w % v % t "<br/> # jkmount /*. JSP myworker1 <br/> # jkmount /*. do myworker1 <br/> # jkautoalias/usr/local/apache2/htdocs * <br/> # jkmount/servlet/* myworker1 <br/> jkmount/* Controller 

 

5. Install Multiple Tomcat servers. The server. xml configuration is as follows:

 

<? XML version = '1. 0' encoding = 'utf-8'?> <Br/> <! -- <Br/> licensed to the Apache Software Foundation (ASF) under one or more <br/> contributor license agreements. see the notice file distributed with <br/> This work for additional information regarding copyright ownership. <br/> the ASF licenses this file to you under the Apache license, version 2.0 <br/> (the "License "); you may not use this file except T in compliance with <br/> the license. you May obtain a copy of the license at </P> <p> http://www.apache.org/licenses/LICENSE-2.0 </P> <p> unless required by applicable law or agreed to in writing, software <br/> distributed under the license is distributed on an "as is" basis, <br/> without warranties or conditions of any kind, either express or implied. <br/> see the license for the specific language governing permissions and <br/> limitatio NS under the license. <br/> --> <br/> <! -- Note: A "server" is not itself a "container", so you may not <br/> define subcomponents such as "valves" at this level. <br/> documentation at/docs/config/server.html <br/> --> <br/> <server port = "8005" shutdown = "shutdown"> <br/> <! -- APR library loader. documentation At/docs/apr.html --> <br/> <listener classname = "org. apache. catalina. core. aprlifecyclelistener "sslengine =" on "/> <br/> <! -- Initialize Jasper prior to webapps are loaded. documentation At/docs/jasper-howto.html --> <br/> <listener classname = "org. apache. catalina. core. jasperlistener "/> <br/> <! -- JMX support for the Tomcat server. documentation At/docs/non-existent.html --> <br/> <listener classname = "org. apache. catalina. mbeans. serverlifecyclelistener "/> <br/> <listener classname =" org. apache. catalina. mbeans. globalresourceslifecyclelistener "/> <br/> <! -- Global JNDI resources <br/> documentation at/docs/jndi-resources-howto.html <br/> --> <br/> <globalnamingresources> <br/> <! -- Editable user database that can also be used by <br/> userdatabaserealm to authenticate users <br/> --> <br/> <Resource Name = "userdatabase" auth = "Container" <br/> type = "org. apache. catalina. userdatabase "<br/> description =" user database that can be updated and saved "<br/> factory =" org. apache. catalina. users. memoryuserdatabasefactory "<br/> pathname =" CONF/tomcat-users.xml "/> <br/> </globalnamingr Esources> <br/> <! -- A "service" is a collection of one or more "connectors" that share <br/> A single "Container" Note: A "service" is not itself a "container ", <br/> so you may not define subcomponents such as "valves" at this level. <br/> documentation at/docs/config/service.html <br/> --> <br/> <service name = "Catalina"> </P> <p> <! -- The connectors can use a shared executor, you can define one or more named thread pools --> <br/> <! -- <Br/> <executor name = "tomcatthreadpool" nameprefix = "Catalina-Exec-" <br/> maxthreads = "150" minsparethreads = "4"/> <br/> --> </P> <p> <! -- A "connector" represents an endpoint by which requests are already ed <br/> and responses are returned. documentation at: <br/> java http connector:/docs/config/http.html (blocking & non-blocking) <br/> Java AJP Connector: /docs/config/ajp.html <br/> APR (HTTP/AJP) connector: /docs/apr.html <br/> define a non-ssl http/1.1 Connector on port 8080 <br/> --> <br/> <connector Port = "8080" protocol =" HT TP/1.1 "<br/> connectiontimeout =" 20000 "<br/> redirectport =" 8443 "/> <br/> <! -- A "connector" using the shared thread pool --> <br/> <! -- <Br/> <connector executor = "tomcatthreadpool" <br/> Port = "8080" protocol = "HTTP/1.1" <br/> connectiontimeout = "20000" <br/> redirectport = "8443"/> <br/> --> <br/> <! -- Define a ssl http/1.1 Connector on port 8443 <br/> this connector uses the JSSE configuration, when using Apr, the <br/> connector shocould be using the OpenSSL style configuration <br/> described in the APR documentation --> <br/> <! -- <Br/> <connector Port = "8443" protocol = "HTTP/1.1" sslenabled = "true" <br/> maxthreads = "150" Scheme = "HTTPS" secure = "True" <br/> clientauth = "false" sslprotocol = "TLS"/> <br/> --> <br/> <! -- Define an AJP 1.3 connector on port 8009 --> <br/> <connector Port = "8009" protocol = "AJP/1.3" redirectport = "8443"/> <br/> <! -- An engine represents the entry point (within Catalina) that processes <br/> every request. the engine implementation for Tomcat stand alone <br/> analyzes the HTTP headers encoded with the request, and passes them <br/> on to the appropriate host (virtual host ). <br/> documentation at/docs/config/engine.html --> <br/> <! -- You shoshould set jvmroute to support load-balancing via AJP ie: <br/> <engine name = "Catalina" defaulthost = "localhost" jvmroute = "jvm1"> <br/> --> <br/> <engine name = "standalone" defaulthost = "localhost" jvmroute = "controller"> <br/> <! -- For clustering, please take a look at documentation at: <br/>/docs/cluster-howto.html (simple how to) <br/>/docs/config/cluster.html (reference documentation) --> </P> <p> <cluster classname = "org. apache. catalina. ha. TCP. simpletcpcluster "<br/> channelsendoptions =" 6 "> <br/> <manager classname =" org. apache. catalina. ha. session. backupmanager "<br/> expiresessionsonshutdown =" false "<br/> policylisteners Onreplication = "true" <br/> mapsendoptions = "6"/> <br/> <! -- <Br/> <manager classname = "org. apache. catalina. ha. session. deltamanager "<br/> expiresessionsonshutdown =" false "<br/> yylistenersonreplication =" true "/> <br/> --> <br/> <channel classname =" org. apache. catalina. tribes. group. groupchannel "> <br/> <membership classname =" org. apache. catalina. tribes. membership. mcastservice "<br/> address =" 228.0.0.4 "<br/> Port =" 45564 "<br/> frequency =" 500 "<br/> dropti Me = "3000"/> <br/> <er classname = "org. apache. catalina. tribes. transport. NIO. nioreceiver "<br/> address =" Auto "<br/> Port =" 4006 "<br/> selectortimeout =" 100 "<br/> maxthreads =" 6 "/> <br/> <sender classname = "org. apache. catalina. tribes. transport. replicationtransmitter "> <br/> <transport classname =" org. apache. catalina. tribes. transport. NIO. pooledparallelsender "/> <br/> </sender> <br/> <interceptor Cl Assname = "org. apache. catalina. tribes. group. interceptors. tcpfailuredetector "/> <br/> <interceptor classname =" org. apache. catalina. tribes. group. interceptors. messagedispatch15interceptor "/> <br/> <interceptor classname =" org. apache. catalina. tribes. group. interceptors. throughputinterceptor "/> <br/> </channel> <br/> <valve classname =" org. apache. catalina. ha. TCP. replicationvalve "<br/> filter = ". */. GIF ;. */. JS ;. */. JPG ;. */. PNG ;. */. htm ;. */. HTML ;. */. CSS ;. */. txt; "/> <br/> <deployer classname =" org. apache. catalina. ha. deploy. farmwardeployer "<br/> tempdir ="/tmp/war-temp/"<br/> deploydir ="/tmp/war-deploy/"<br/> watchdir = "/ TMP/war-Listen/"<br/> watchenabled =" false "/> <br/> <clusterlistener classname =" org. apache. catalina. ha. session. clustersessionlistener "/> <br/> </cluster> <br/> <! -- The request dumper valve dumps useful debugging information about <br/> the request and response data stored Ed and sent by Tomcat. <br/> documentation at:/docs/config/valve.html --> <br/> <! -- <Br/> <valve classname = "org. Apache. Catalina. Valves. requestdumpervalve"/> <br/> --> <br/> <! -- This realm uses the userdatabase configured in the global JNDI <br/> resources under the key "userdatabase ". any edits <br/> that are already med against this userdatabase are immediately <br/> available for use by the realm. --> <br/> <realm classname = "org. apache. catalina. realm. userdatabaserealm "<br/> resourcename =" userdatabase "/> <br/> <! -- Define the default virtual host <br/> Note: XML Schema validation will not work with xerces 2.2. <br/> --> <br/> <post name = "localhost" appbase = "webapps" <br/> unpackwars = "true" autodeploy = "true" <br/> xmlvalidation = "false" xmlnamespaceaware = "false"> <br/> <! -- Singlesignon valve, share authentication between Web applications <br/> documentation at:/docs/config/valve.html --> <br/> <! -- <Br/> <valve classname = "org. Apache. Catalina. authenticator. singlesignon"/> <br/> --> <br/> <! -- Access log processes all example. <br/> documentation at:/docs/config/valve.html --> <br/> <! -- <Br/> <valve classname = "org. apache. catalina. valves. accesslogvalve "directory =" logs "<br/> prefix =" localhost_access_log. "suffix = ". TXT "pattern =" common "resolvehosts =" false "/> <br/> --> <br/> </post> <br/> </engine> <br/> </service> <br/> </Server> <br/> 

 

6. Notes

 

(1) In tomcat

 

<Engine name = "standalone" defaulthost = "localhost" jvmroute = "controller">

 

Yes standalone jvmroute is the Server Load balancer Controller

 

(2)

 

<Distributable/> or set at your must be added in the web. xml file of the project.<Context distributable="true" />

 

(3)

 

 

<Cycler classname = "org. Apache. Catalina. tribes. Transport. NiO. nioreceiver"

Address = "Auto"

Port = "4006"

Selectortimeout = "100"

Maxthreads = "6"/>

 

 

The port range is 4000-4100.

 

(4) ensure that sticky session mode is configured in the balance manager.

 

Worker. Controller. sticky_session = 1

 

(5) The worker. ajp13.port = port 8009 must correspond to the <connector Port = "8009" protocol = "AJP/1.3" redirectport = "8443"/>

 

(6) worker. myworker3.lbfactor = 1 is the probability coefficient of balanced allocation. A larger value indicates a larger number of occurrences.

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.