Tomcat6 and Apache2 integration and mod_bandwidth and mod_limitipconn module installation Configuration

Source: Internet
Author: User

The integration of Tomcat and Apache has the following advantages:

1. Use Apache for load balancing and fault tolerance;

2. Apache focuses on static Web page parsing and tomcat focuses on dynamic web page parsing, which can improve server efficiency;

3. Applications can be upgraded seamlessly.

First install Apache and Tomcat and install the mod_jk (SUDO apt-getinstall libapache2-mod-jk ).

I. AJP Connector

Tomcat 6 provides the AJP Connector implementation for the AJP protocol as a Java class, which is included in the Tomcat release version. First, you should define the connector in $ catalina_home/server. xml:

<-- Define an AJP1.3 Connector on port 8009 -->

<Connector port = "8009" protocol = "AJP1.3" redirectPort = "8443"/>

Generally, you can remove the comments and add them without them.

2. Compile the workers. properties File

Workers. the properties file is used to define some variables that are connected to Tomcat, you do not need to create it yourself, you have created a file in the/etc/libapache2-mod-jk/directory when installing the libapache2-mod-jk package, you can modify it directly:

$ Sudo nano/etc/libapache2-mod-jk/workers. properties

Modify the corresponding row as follows:

Worker. list = myworker

Worker. myworker. port = 8009

Worker. myworker. host = localhost // if you are on another server, change it to the corresponding host ip address.

Worker. myworker. type = ajp13

Worker. myworker. lbfactory = 1

Worker. loadbalancer. type = lb

Worker. loadbalancer. balance_workers = myworker

3. Configure/etc/apache2/apache2.conf. (We recommend that you create the mod_jk file in the/etc/apache2/CONF. d/directory, and write the same content in this step)

# Tell JK where to find workers. properties

JkWorkersFile/etc/libapache2-mod-jk/workers. properties # After restarting apache, if the allow once prompt appears, comment out this line.

# Define JK log location

Jklogfile/var/log/apache2/mod_jk.log

# Set the jk log level (debug/error/INFO)

Jkloglevel info

Set log format

Jklogstampformat "[% A % B % d % H: % m: % S % Y]"

# JK options

Jkoptions + forwardkeysize + forwarduricompat-forwarddirectories

# Set Request format

Jkrequestlogformat "% w % v % t"

4. Configure Virtual Hosts

$ Sudo nano/etc/apache2/sites-available/Default

Add the following code at the end:

.....

</Directory>

Jkmount/*. jsp myworker # submit all JSP page requests to myworker for processing.

Jkunmount/*. php myworker # All PHP page requests are not handled by myworker.

</Virtualhost>

Create a test in the Tomcat application directory/var/lib/tomcat6/webapps/root. JSP, start Apache and tomcat, and use a browser to access http: // localhost/test. JSP, you should be able to see the correct page.
 
Example of test. jsp
Hello! The time is <% = new java. util. Date () %>

The integration is successful.

 

Install and configure the apache module mod_limitipconn

Download wget http://dominia.org/djao/limit/mod_limitipconn-0.24.tar.bz2

Tar xvf mod_limitipconn-0.24.tar.bz2

To compile and install the extension module for Apache, you need the apxs tool to install apxs.

Apt-Get install apache2-dev

Edit the "makefile" file. The modification content is as follows:

Apxs = apxs

Changed:

Apxs =/usr/bin/apxs2

Save and continue the installation:

Make & make install

Create limitipconn. conf in/etc/apache2/mod-available /.

Enter content as needed:

<Ifmodule mod_limitipconn.c>

# Here, the root directory is restricted, that is, all restrictions, which can be modified as needed

<Location/>

# Maximum number of connections per IP Address

Maxconnperip 3

# Indicates that the image directory is unrestricted.

Noiplimit image /*

</Location>

</IfModule>

Install and configure the apache module mod_bandwidth

Wget http://ivn.cl/files/source/mod_bw-0.9.tgz

Tar-xvf mod_bw-0.9.tgz

/Usr/bin/apxs2-a-c mod_b1_c

Cp./lib/mod_bw.so/usr/lib/apache2/modules/

Create a new file: bw. load in the/etc/apache2/mod-available/folder.

Enter the following content:

BandWidthModule On
LoadModule bw_module/usr/lib/apache2/modules/mod_bw.so

Create a new file: bw. conf in the/etc/apache2/conf. d/folder.

Enter the following content:

<IfModule mod_b1_c>

BandwidthModule On

ForceBandWidthModule On

# Restrict the user's download speed to 50 K per second. Here, all settings are set. This module setting can also be installed in virtual host or directory.

Bandwidth all 51200

MinBandwidth all-1

</IfModule>

Activation module:

A2enmod bw

Restart service apache2 restart

For detailed configuration, see:

Bandwidth Module module, Module description documentation, click to view the mod_bw-0. Documentation 9.0

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.