Detailed configuration of apache + tomcat clusters in linux

Source: Internet
Author: User

 

Environment:

Operating System: CentOS 5.1

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

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

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

 

Configuration:

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

#./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

PATH = $ JAVA_HOME/bin: $ PATH

CATALINA_HOME =/usr/local/tomcat

Export JAVA_HOME classpath path CATALINA_HOME

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

Source/etc/profile

Test whether the configuration is successful:

Java-version

 

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:

Set

<! -- You shoshould set jvmRoute to support load-balancing via AJP ie:

<Engine name = "Standalone" defaultHost = "localhost" jvmRoute = "jvm1">

-->

<Engine name = "Catalina" defaultHost = "localhost">

Change

 

<! -- You shoshould set jvmRoute to support load-balancing via AJP ie:

-->

<Engine name = "Standalone" defaultHost = "localhost" jvmRoute = "tomcatX">

<! --

<Engine name = "Catalina" defaultHost = "localhost">

-->

Note:

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

The second tomcat server sets jvmRoute = "tomcat2"

 

Set

<! --

<Cluster className = "org. apache. catalina. ha. tcp. SimpleTcpCluster"/>

-->

Change the comment

<Cluster className = "org. apache. catalina. ha. tcp. SimpleTcpCluster"/>

* ** Detailed cluster configuration ***

<Cluster className = "org. apache. catalina. ha. tcp. SimpleTcpCluster"

ChannelSendOptions = "8">

 

<Manager className = "org. apache. catalina. ha. session. DeltaManager"

ExpireSessionsOnShutdown = "false"

NotifyListenersOnReplication = "true"/>

 

<Channel className = "org. apache. catalina. tribes. group. GroupChannel">

<Membership className = "org. apache. catalina. tribes. membership. McastService"

Address = "228.0.0.4"

Port = "45564"

Frequency = "500"

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

<Cycler className = "org. apache. catalina. tribes. transport. nio. NioReceiver"

Address = "auto"

Port = "4000"

AutoBind = "100"

SelectorTimeout = "5000"

MaxThreads = "6"/>

 

<Sender className = "org. apache. catalina. tribes. transport. ReplicationTransmitter">

<Transport className = "org. apache. catalina. tribes. transport. nio. PooledParallelSender"/>

</Sender>

<Interceptor className = "org. apache. catalina. tribes. group. interceptors. TcpFailureDetector"/>

<Interceptor className = "org. apache. catalina. tribes. group. interceptors. MessageDispatch15Interceptor"/>

</Channel>

 

<Valve className = "org. apache. catalina. ha. tcp. ReplicationValve"

Filter = ""/>

<Valve className = "org. apache. catalina. ha. session. JvmRouteBinderValve"/>

 

<Deployer className = "org. apache. catalina. ha. deploy. FarmWarDeployer"

TempDir = "/tmp/war-temp /"

DeployDir = "/tmp/war-deploy /"

WatchDir = "/tmp/war-listen /"

WatchEnabled = "false"/>

 

<ClusterListener className = "org. apache. catalina. ha. session. JvmRouteSessionIDBinderListener"/>

<ClusterListener className = "org. apache. catalina. ha. session. ClusterSessionListener"/>

</Cluster>

 

Configure the web. xml of the application:

In each webapps, modify the configuration file web. xml file to add elements <distributable/>

Add the following content to the <web-app> element of the web. xml file:

<! -- This application will copy the Session with the cluster server -->

<Distributable/>

The specific modification is as follows:

Before modification:

<? Xml version = "1.0" encoding = "ISO-8859-1"?>

<Web-app xmlns = "[url] http://java.sun.com/xml/ns/javaee#/url]"

Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

Xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee [url] http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd#/url]"

Version = "2.5">

</Web-app>

After modification:

<? Xml version = "1.0" encoding = "ISO-8859-1"?>

<Web-app xmlns = "[url] http://java.sun.com/xml/ns/javaee#/url]"

Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"

Xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee [url] http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd#/url]"

Version = "2.5">

<! -- This application will copy the Session with the cluster server -->

<Distributable/>

</Web-app> www.2cto.com

Configure the ajp Server Load balancer function of apache:

Make sure that the comment of the following Module is removed

LoadModule proxy_module modules/mod_proxy.so

LoadModule proxy_connect_module modules/mod_proxy_connect.so

LoadModule proxy_ftp_module modules/mod_proxy_ftp.so

LoadModule proxy_http_module modules/mod_proxy_http.so

LoadModule proxy_ajp_module modules/mod_proxy_ajp.so

LoadModule proxy_balancer_module modules/mod_proxy_balancer.so

LoadModule status_module modules/mod_status.so

Add the following content:

# Proxypass Config

Include conf/extra/httpd-modproxy.conf

Create File httpd-modproxy.conf input content:

<Location/server-status>

SetHandler server-status

Order Deny, Allow

Deny from all

Allow from all

</Location>

<Location/balancer-manager>

SetHandler balancer-manager

Order Deny, Allow

Deny from all

Allow from all

</Location>

ProxyRequests Off

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

 

<Proxy balancer: // tomcatcluster>

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

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

</Proxy>

Note:

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: // 192.168.232.4/balancer-manager [/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: // 192.168.232.4/[/url ].

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

 

Reference:

Http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html

Http://tomcat.apache.org/tomcat-6.0-doc/balancer-howto.html

Http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/mod/mod_proxy.html

Http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/mod/mod_proxy_balancer.html

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