Configure apache2.2.10 Server Load balancer + tomcat6 cluster (Linux)

Source: Internet
Author: User

1. Install JDK properly under liunx.

Not tired

 

2. Configure the server Load balancer server apache2.2.10
1. Download apache2.2.10 and install related components.
Http://www.sunfreeware.com/indexintel10.htmldownload httpd-2.2.10.tar.gz
Installation Method:
Decompression: tar-zxvf httpd-2.2.10.tar.gz

. /Configure -- prefix =/usr/local/apache2 -- enable-auth-Anon -- enable-auth-dBm -- enable-Cache -- enable-disk-Cache -- enable-expires -- enable- file-Cache -- enable-headers -- enable-info -- enable-logio -- enable-Mem-Cache -- enable-proxy -- enable-Rewrite -- enable-SSL -- With-SSL =/usr /local/OpenSSL-enable-unique-id -- enable-UserTrack -- enable-vhost-alias -- enable-mod-shared = most

Make

Make install

 

Modify the Apache configuration file as needed
Find the # servername http://www.example.com/set servername under it as follows
Servername http://www.mysite.com/
Base http://www.mysite.com/for your site name, can also be replaced by IP
Find DocumentRoot "/usr/local/Apache/htdocs"
Set the root directory of your Web server as shown in Figure
DocumentRoot "/myweb"
Change directoryindex index.html. var
Directoryindex index.html index. php index.htm
Run the following command to start the Web Server:
#/Usr/local/apache2/bin/apachectl start
Check whether your site is working properly with http://www.mysite.com/IP available
Stop the service with #/usr/local/apache2/bin/apachectl stop

2. view the modules compiled into Apache:
# Cd/usr/local/apache2/bin
#./Apachectl-l
Compiled in modules:
Core. c
Prefork. c
Http_core.c
Mod_so.c

3. Modify the/usr/local/apache2/CONF/httpd. conf file.

Remove the comments of the following module (actually 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

And add
<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
Proxypass/temp http: // 10.8.1.8: 8080/temp/
# Proxypassreverse/balancer: // tomcatcluster/
Proxypassreverse/CCAs balancer: // tomcatcluster/CCAs/
Proxypassreverse/clpay balancer: // tomcatcluster/clpay/

<Proxy balancer: // tomcatcluster>
Balancermember http: // 10.8.1.8: 8080 loadfactor = 1
Balancermember http: // 10.8.1.8: 8081 Smax = 1 loadfactor = 1
# Less powerful server, don't send as your requests there
Balancermember http: // 10.8.1.8: 8082 Smax = 1 loadfactor = 2
</Proxy>

 

Proxypass is the proxy forwarding URL, which forwards all access/requests to the cluster balancer: // tomcatcluster
Balancermember is a member of the cluster, that is, cluster server a or server B. The Server Load balancer forwards requests to balancermember according to the Server Load balancer rules.

After configuration, start the apahce server and access localhost to view the results returned by applications on the cluster server. Congratulations! The Server Load balancer and cluster have been configured successfully.
Access localhost/balancer-manager to Display Server Load balancer information.

4. Go to the/usr/local/apache2/bin directory and run
#./Apachectl-T
Syntax OK is displayed, indicating that the configuration is correct.
5. Start/Close/restart Apache
Start Apache
#./Apachectl start

Disable Apache
#./Apachectl stop
Input: http: // 10.8.1.8: 8080 show it's work! Test page

3. install and configure the tomcat6 Cluster
1. Download apache-tomcat-6.0.18.tar.gz (http://archive.apache.org/dist/t... omcat-6.0.18.tar.gz)
2.install apache-tomcat-6.0.18.tar.gz

Install it in the/usr/Apache/tomcat directory
# Gzip-D apache-tomcat-6.0.18.tar.gz

3. Solve the Problem of displaying the verification code in Solaris (in case of this error)
Add-djava. AWT. Headless = true/to line 266/278 of/usr/Apache/tomcat/bin/Catalina. Sh/

4. Start the Tomcat server to test whether it is normal.
# Cd/usr/Apache/tomcat/bin/
#./Startup. Sh

5. Modify Tomcat's CONF/server. xml <engine> (configured when ARP is used)
Remove the comment <engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat1">
Jvmroute is the Tomcat route label, which distinguishes two Tomcat hosts, then the second is changed
<Engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat2">
Add <engine name = "Catalina" defaulthost = "localhost">
6. Modify Tomcat's CONF/server. xml <connector> (configured when ARP is used)
Remove comments <connector Port = "8009" enablelookups = "false" redirectport = "8443" DEBUG = "0" protocol = "AJP/1.3"/>
7. Modify Tomcat's CONF/server. xml <cluster>
<! --
<Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>
-->
<Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"
Channelsendoptions = "6">

<Manager classname = "org. Apache. Catalina. Ha. session. backupmanager"
Expiresessionsonshutdown = "false"
Notifylistenersonreplication = "true"
Mapsendoptions = "6"/>
<! --
<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 = "5000"
Selectortimeout = "100"
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"/>
<Interceptor classname = "org. Apache. Catalina. tribes. Group. interceptors. throughputinterceptor"/>
</Channel>

<Valve classname = "org. Apache. Catalina. Ha. tcp. replicationvalve"
Filter = ". */. GIF ;. */. JS ;. */. JPG ;. */. PNG ;. */. htm ;. */. HTML ;. */. CSS ;. */. txt; "/>

<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. clustersessionlistener"/>
</Cluster>

8. 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 = "UTF-8"?>
<Web-app xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
Version = "2.5">
</Web-app>
After modification:
<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app xmlns = "http://java.sun.com/xml/ns/javaee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
Version = "2.5">
<! -- This application will copy the session with the cluster server -->
<Distributable/>
</Web-app>

 

4. Test Page code:

<% @ Page contenttype = "text/html; charset = GBK" %>
<% @ Page import = "Java. util. *" %>
<HTML> <Body>
<%
System. Out. println ("sessionid:" + session. GETID ());
%>
Server info:
<%
Out. println (request. getservername () + ":" + request. getserverport () + "<br>"); %>
<%
Out. println ("<br> ID" + session. GETID () + "<br>"); // if a new session attribute is set
String dataname = request. getparameter ("dataname ");
If (dataname! = NULL & dataname. Length ()> 0 ){
String datavalue = request. getparameter ("datavalue ");
Session. setattribute (dataname, datavalue );
}
Out. Print ("<B> session List </B> <br> ");
Enumeration E = session. getattributenames ();
While (E. hasmoreelements ()){
String name = (string) E. nextelement ();
String value = session. getattribute (name). tostring ();
Out. println (name + "=" + value + "<br> ");
System. Out. println (name + "=" + value );
}
%>
<Form action = "test. jsp" method = "Post">
Name: <input type = text size = 20 name = "dataname">
<Br>
Value: <input type = text size = 20 name = "datavalue">
<Br>
<Input type = submit>
</Form>
</Body>
</Html>
You will find that your session is copied! It is not as troublesome to configure jk_conf in tomcat5!

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.