Server Load balancer-Summary after self-query data experiment

Source: Internet
Author: User

Core Tip: Goal: To use Apache and tomcat to configure a Web site that can be applied, to meet the following requirements: 1. Use Apache as the httpserver and connect multiple Tomcat application instances, and load balancing. 2. Set the Session Timeout time for the system, including Apache and tomcat 3. List of blocked files for the system, including

Objectives:
To use Apache and tomcat to configure a Web site that can be applied, you must meet the following requirements:
1. Apache is used as an httpserver. Multiple Tomcat Application Instances are connected to the Server Load balancer instance.
2. Set the Session Timeout time for the system, including Apache and tomcat.
3. List of blocked files for the system, including Apache and tomcat
Note: In this example, an Apache and two Tomcat servers are installed on the same machine.

I. preparations:
Installation Program (ensure that JDK or later is installed)
Apahce 2.2.8 download: apache_2.2.8-win32-x86-no_ssl.msi
Tomcat6.0.14 download: apache-tomcat-6.0.14.zip extract directly.

Ii. Installation Process
Installation Directory of apahce: D: \ apache.
Tomcat Directory: decompress it to (D: \ Tomcat Cluster Server. They are cat1 and cat2, respectively.
The installation process is not described in detail.

Iii. Configuration
1. Apache configuration
1.1 httpd. conf configuration
Modify Apache configuration file D: \ apache \ conf \ httpd. conf
Remove the comments of the following modules. mod_jk.so is not used to link Apache and tomcat,
Apache has integrated mod_jk.so since 2.x. Just remove the comments of the following lines,
It is equivalent to the previously cumbersome configuration with mod_jk.so. Here we mainly use the proxy method, which is so simple.

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

Find <ifmodule dir_module> </ifmodule> and add index. jsp
<Ifmodule dir_module>
Directoryindex index.html index. jsp
</Ifmodule>

1.1.1. Add at the bottom

Proxyrequests off
<Proxy balancer: // cluster>
Balancermember AJP: // 127.0.0.1: 8009 loadfactor = 1 route = Route 1
Balancermember AJP: // 127.0.0.1: 9009 loadfactor = 1 route = tomcat2
</Proxy>

The above four balancermember members are the Tomcat cluster we configured. It will be explained later.

1.2 httpd-vhosts.conf settings
Next, set the VM. The Apache Virtual Host settings are as follows:
First you need to modify CONF/httpd. conf to find (# include CONF/extra/httpd-vhosts.conf)
Remove comments.

# Virtual Hosts
Include CONF/extra/httpd-vhosts.conf
Add at the bottom of the file (extra/httpd-vhosts.conf)

<Virtualhost *: 80>
Serveradmin weijie@126.com
Servername localhost
Serveralias localhost
Proxypass/balancer: // cluster/stickysession = JSESSIONID nofailover = on
Proxypassreverse/balancer: // cluster/
</Virtualhost>

Set the domain name and path based on your own situation.
Then set the Tomcat Virtual Host

2. Configure Tomcat
2.1. Disable Server Configuration
We need to run four different Tomcat servers on one machine. We need to modify the closing ports of different Tomcat servers to avoid port occupation.
Tomcat6.0 uses the default value, which is not modified. The other three modifications. Find the server in server. xml under tomcat1 \ conf, tomcat2 \ conf, and tomcat6.03 \ conf:
<Server port = "8005" shutdown = "shutdown">
Change
<Server port = "8009" shutdown = "shutdown">
XXXX indicates different ports here: My tomcat uses and respectively.

2.2. Configure the engine
Comment out the original configuration and remove the following sentence. And Mark jvmroute = "cmdat1 ".
<Engine name = "standalone" defaulthost = "localhost" jvmroute = "tomcat1">

My configuration is changed to the following:
<Engine name = "Catalina" defaulthost = "localhost" jvmroute = "tomcat1">

The following is the original configuration.

<! -- <Engine name = "Catalina" defaulthost = "localhost"> -->

Other configurations (tomcat2) must be the same. Note: The jvmroute configuration should not be the same.

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

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

My configuration is changed to the following:
<Engine name = "Catalina" defaulthost = "localhost" jvmroute = "tomcat2">

2.3. Configure Connector
The original default configuration.
<! -- Define an AJP 1.3 connector on port 8009 -->

<Connector Port = "8009" protocol = "AJP/1.3" redirectport = "8443"/>

This is the key to connecting Apache and tomcat. Apache at the front end communicates with Tomcat through the AJP protocol to achieve load balancing. You can also use the HTTP protocol. Note how they connect and communicate. The red part above (Port = "8009") is the connection interface.
Change the <ctor Port = "XXX"/> ports of the other three Tomcat servers

<Proxy balancer: // cluster>

# Corresponds to Route 1, and route corresponds to <engine jvmroute = "Route 1">.

Balancermember AJP: // 127.0.0.1: 8009 loadfactor = 1 route = Route 1

# Corresponds to Tomcat 2, and route corresponds to <engine jvmroute = "tomcat2">.

Balancermember AJP: // 127.0.0.1: 9009 loadfactor = 1 route = tomcat2

</Proxy>

Port: 9009. The AJP port of Tomcat 2 is port: 9001. Port: 9003 on the ajp port of tomcat6.03 must be consistent with the above. At the same time, you must change the redirectport value to unique to ensure that the four Tomcat servers are different.

. Configure cluster (each Tomcat must be modified to share the cluster session)
The original configuration.

<Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>

Modify to the following code: <er Port = "XX"/> port must also be unique.

<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 = "5001"

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>


By now, Server Load balancer has been implemented ======================================== ========================================================== ========================================================== ===
This setting is mainly used for Tomcat clusters.

I simply enable this (remove comments) for my configuration, without the above detailed Configuration:
<Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>

Note: You can also name the specified directory address by yourself without modifying the files in server. xml.
# Cat route AT1/CONF/Catalina/localhost/root. xml

<Context Path = "/" docbase = "/www/moveage.org/www/htdocs" reloadable = "false" crosscontext = "true">

</Context>

4. Start the service and test the built-in example of Tomcat
1. Test Apache and tomcat collaboration.
Add the following test code under index. jsp under \ webapps \ Root in each Tomcat: (X indicates that the output of different Tomcat servers is different. Delete index.html to avoid affecting the test result. Add. Between </table> </body> at the end.
<%

System. Out. println ("tomcat6.0x deal with request ");

%>

Then, visit http: // 127.0.0.1.
Then access
Http: // 127.0.0.1: 8080, http: // 127.0.0.1: 9080, http: // 127.0.0.1: 8081, http: // 127.0.0.1: 9002: // 127.0.0.1 is the same.
This indicates that Apache and tomcat are successfully integrated!

To copy sessions, modify web. XML in the Application

For example, the WEB-INF directory of the webapps Directory web. xml file

Add tags

<Distributable/>

You can add it directly before </Web-app>.

This step is required for Tomcat cluster creation. Otherwise, your session will not work properly.

2. Test the balancer.
When using http: // 127.0.0.1 for multiple accesses, some stress testing tools must be used to test the real effect. Microsoft Web application stress tool can be used for simple stress testing, otherwise, you will not be able to achieve this by constantly refreshing. You will only have output results on a tomcat console. You can use a stress testing tool to simulate simultaneous access by a large number of users. You will find that the four Tomcat consoles have output control information, indicating that the balancer works properly.

Appendix: My Apache + Tomcat configuration information

Add httpd. conf at the end:

Proxyrequests off

<Proxy balancer: // Tomcat>

Balancermember AJP: // 127.0.0.1: 8009 Smax = 2 loadfactor = 1 route = route at1

Balancermember AJP: // 127.0.0.1: 9009 Smax = 2 loadfactor = 2 route = tomcat2

</Proxy>

Httpd-vhost.conf file configuration

<Virtualhost *: 80>
<Directory/www/moveage.org/www/htdocs>

Options followsymlinks

AllowOverride none

Order deny, allow

Allow from all

</Directory>
Proxypass/*. html!

Proxypass/*. htm!

Proxypass/balancer: // tomcat/lbmethod = byrequests stickysession = JSESSIONID nofailover = on timeout = 5 maxattempts = 3

Proxypassreverse/balancer: // tomcat/

# Proxypass/AJP: /127.0.0.1: 8009/

<Ifmodule dir_module>

Directoryindex index.html index. jsp

</Ifmodule>
Serveradmin swm@moveage.org

DocumentRoot/www/moveage.org/www/htdocs

Servername box.moveage.org

Serveralias bao.moveage.org

Errorlog/www/moveage.org/logs/error_log

Customlog "|/usr/local/cronolog/sbin/cronolog/www/moveage.org/logs/access_log.policy?m=d" combined

</Virtualhost>

Modify the server. xml file of different Tomcat servers

<Connector Port = "8009" protocol = "AJP/1.3" redirectport = "8443" uriencoding = "UTF-8"/>

<Connector Port = "9009" protocol = "AJP/1.3" redirectport = "8443" uriencoding = "UTF-8"/>

<Engine name = "Catalina" defaulthost = "localhost" jvmroute = "tomcat1">

<Engine name = "Catalina" defaulthost = "localhost" jvmroute = "tomcat2">

Enable

<Cluster classname = "org. Apache. Catalina. Ha. tcp. simpletcpcluster"/>

Start session replication

WEB-INF Directory web. xml file in the webapps directory

Add tags

<Distributable/>

Add directly before </Web-app>

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.