Environment: The operating system is CentOS5.1Apache2. 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 ....
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
Change
Note:
For the first tomcat server, set jvmRoute = "cmdat1"
The second tomcat server sets jvmRoute = "tomcat2"
Set
Change the comment
* ** Detailed cluster configuration ***
ChannelSendOptions = "8">
ExpireSessionsOnShutdown = "false"
NotifyListenersOnReplication = "true"/>
Address = "228.0.0.4"
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 = "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">
After modification:
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">
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:
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: // 192.168.232.5: 8080 [/url] loadfactor = 1
BalancerMember [url] http: // 192.168.232.6: 8080 [/url] loadfactor = 2
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