Detailed configuration of apache + tomcat clusters in linux

Source: Internet
Author: User
Environment: The operating system is CentOS5.1Apache2. X Server: IP address; installation path:/usr/local/apache; Tomcat6 server: IP address; installation path:/usr/local/tomcat; Tomcat6 server: IP address 192 ....



Operating system: CentOS 5.1

Apache2.X server: IP address; installation path:/usr/local/apache;

Tomcat6 server: IP address; installation path:/usr/local/tomcat;

Tomcat6 server: IP address; installation path:/usr/local/tomcat;



Apache installation:

#. /Configure -- prefix =/usr/local/apache -- enable-modules = so -- enable-mods-shared = all -- enable-proxy-connect -- enable-proxy- ftp -- enable-proxy-http -- enable-proxy-ajp -- enable-proxy-balancer -- enable-rewrite

Note: enable-proxy, enable-proxy-http, enable-proxy-connect, enable-proxy-ajp, and enable-proxy-balancer are required to activate the tomcat cluster, the proxy-ajp and proxy-balancer must depend on the proxy. for custom compilation, mod_status must be compiled in addition to the preceding modules. Enable-proxy-ftp can not be compiled.

# Make; make install


Create an Apache startup item:

# Cp support/apachectl/etc/rc. d/init. d/httpd

# Vi/etc/rc. d/init. d/httpd

Add the following content: (including)

# Startup script for the Apache Web Server

# Chkconfig: 2345 85 15

# Description: Apache is a World Wide Web server. It is used to server

# HTML files and CGI.

# Processname: httpd

# Pidfile:/usr/local/apache/log/httpd. pid

# Config:/usr/local/apache/conf/httpd. conf

Add service items

# Chkconfig -- add httpd

# Chmod 755/etc/rc. d/init. d/httpd

# Chkconfig -- level 345 httpd on


JDK installation:

# Chmod a + x jdk-6u4-linux-i586-rpm.bin



JAVA environment variable settings:

# Vi/etc/profile

Add the following content at the end of the file:

JAVA_HOME =/usr/java/jdk1.6.0 _ 04

CLASSPATH =.: $ JAVA_HOME/lib/tools. jar: $ JAVA_HOME/lib/dt. jar


CATALINA_HOME =/usr/local/tomcat

Export JAVA_HOME classpath path CATALINA_HOME

Run the following command to make the environment variable take effect:


Test whether the configuration is successful:



Tomcat installation:

# Wget [url] URLs

# Tar zxvf apache-tomcat-6.0.16.tar.gz

# Mv apache-tomcat-6.0.16/usr/local/tomcat


Tomcat random start:

# Vi/etc/rc. local

Add the following content:

/Usr/local/tomcat/bin/startup. sh


Tomcat6 configuration file server. xml:





For the first tomcat server, set jvmRoute = "cmdat1"

The second tomcat server sets jvmRoute = "tomcat2"



Change the comment

* ** Detailed cluster configuration ***

ChannelSendOptions = "8">


ExpireSessionsOnShutdown = "false"

NotifyListenersOnReplication = "true"/>


Address = ""

Port = "45564"

Frequency = "500"

DropTime = "3000" type = "codeph" text = "codeph"/>

Address = "auto"

Port = "4000"

AutoBind = "100"

SelectorTimeout = "5000"

MaxThreads = "6"/>



Filter = ""/>


TempDir = "/tmp/war-temp /"

DeployDir = "/tmp/war-deploy /"

WatchDir = "/tmp/war-listen /"

WatchEnabled = "false"/>



Configure the web. xml of the application:

In each webapps, modify the configuration file web. xml file to add elements.

In the web. xml file Add the following content to the element:

The specific modification is as follows:

Before modification:

Xmlns: xsi = ""

Xsi: schemaLocation = " [url]]"

Version = "2.5">

After modification:

Xmlns: xsi = ""

Xsi: schemaLocation = " [url]]"

Version = "2.5">

Configure the ajp server load balancer function of apache:

Make sure that the comment of the following Module is removed

LoadModule proxy_module modules/

LoadModule proxy_connect_module modules/

LoadModule proxy_ftp_module modules/

LoadModule proxy_http_module modules/

LoadModule proxy_ajp_module modules/

LoadModule proxy_balancer_module modules/

LoadModule status_module modules/

Add the following content:

# Proxypass Config

Include conf/extra/httpd-modproxy.conf

Create file httpd-modproxy.conf input content:

SetHandler server-status

Order Deny, Allow

Deny from all

Allow from all

SetHandler balancer-manager

Order Deny, Allow

Deny from all

Allow from all

ProxyRequests Off

ProxyPass/balancer: // tomcatcluster stickysession = jsessionid nofailover = On


BalancerMember [url] http: // 8080 [/url] loadfactor = 1

BalancerMember [url] http: // 8080 [/url] loadfactor = 2


ProxyRequests Off indicates that reverse proxy is enabled and must be enabled;

ProxyPass is the proxy forwarding Url, which forwards all access/requests to the cluster balancer: // tomcatcluster. here, all access/requests are forwarded to the cluster balancer: // The/test directory of tomcatcluster;

BalancerMember is a member of the cluster, that is, the cluster server 1 or 2. the server load balancer will forward requests to BalancerMember according to the balancing rules;


Debug the server load balancer cluster system:

Access the apache server's web service: [url] http: // [/url]

If the server load balancer information is displayed, it indicates that the server load balancer is successful. you can access the tomcat application by visiting [url] http: //[/url ].

* ** You must first start the Tomcat service and then start the Apache service! ***







Related Article

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: 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.