Apache and Tomcat integration experience

xiaoxiao2021-03-06  23

Apache and Tomcat integration experience

Author Cleverpig

First, technical preparation:

Tomcat is Sun and Apache to develop JSP Server, support servlet and JSP, Tomcat itself can be used as a web server, when processing a static page, Tomcat is not as fast as Apache, is as configurable, strong. Apache is powerful and efficient as the most popular web server, but does not support JSP and servlets, so usually to integrate them, let Apache processes static pages, and hand over the dynamic page to Tomcat handling, Advantage. Apache can transfer the request to Tomcat by using the URL by loading the integrated module and settings in Apache.

To make Apache and Tomcat work, there must be a connector to link them. Connector has an important impact on performance, the convenience of configuration. Currently, there is rough JK1.x, JK2, and Mod_Webapp three Connector can be used. JK is relatively wide, JK2 is an improvement in JK1.x, which is relatively new. These three Connector configuration methods are large.

Second, the software is prepared:

1. Server 1 features:

Run the front end of the apache, directly facing the Web Client (Various browsers).

2. Software environment on server 1:

Operating system: Redhat AdvanceEnterpriseServer3, the system is installed by default, but it seems that the function is incomplete.

IP address: 192.168.1.114

3. Software required on server 1:

Apache

2.0.52

Sourcecodes: apache httpd-2.0.52.tar.gz can be downloaded from http://www.apache.org.

JK2Connector (version is

2.2.0

.4) Sourcecodes: jakarta-tomcat-connectors-jk2-src-current.tar.gz can be downloaded from http://www.apache.org/dist/jakarta/tomcat-connectors/jk2/.

4. Server 2 features:

Run Tomcat, process the web client of the server 1 forward, and send the response page to the Apache on the server 1, which has enabled Apache to forward this to the Web Client.

5. Software environment on server 2:

Operating system: MICORSOFT Windows2003 Server.

IP address: 192.168.1.111

6. Software required on server 2:

Binary installer with Tomcat (version 4.1): You can download from http://www.apache.org/dist/jakarta/tomcat-4/, I am using Tomcat4.1.

The Java development package (version 1.4): You can download it from http://www.sun.com. I installed J2DK1.4.

Third, install Tomcat:

Before installing Tomcat, you will install J2DK and set Java_Home and put $ java_home / bin into the path.

Since the Java development kit and Tomcat 4.1 are installed under Windows, the entire installation process is relatively simple, and it is not much.

Fourth, configure Tomcat:

According to some articles about Apache and Tomcat integration, and my own experience, the configuration Tomcat requires the following two steps: 1. Modify the JK2.Properties file in the Tomcat / Conf directory, the modified file content is as follows:

## This file may be overriden at runtime. Make sure tomcat is stock

## w edit the file.

## Comments Will Be _lost_

## documentation of the format in jkmain javadoc.

# Set the desired handler list

# Handler.list = Apr, Request, Channeljni

Handler.list = ChannelSocket, Request

#

# Override The Default Port for the SocketChannel

# channelsocket.port = 8019

Channelsocket.port = 8009

# Default:

# channelunix.file = $ {jkhome} /work/jk2.socket

# Just to Check if The config is working

# Shm.file = $ {jkhome} /work/jk2.shm

# In Order To Enable Jni Use Any Channeljni Directive

# channeljni.disabled = 0

# And one of the backing directives:

# apr.jnimodeso = / opt / apache2 / modules / mod_jk2.so

# I set to inprocess the mod_jk2 will register native itself

# This will enable the starting of the tomcat from mod_jk2

# apr.jnimodeso = inprocess

Clearly the purpose is to define the port of Tomcat and Apache communications, I am set to 8009.

2. Modify the server.xml file under Tomcat / Conf directory to add a virtual host:

It should be, it is necessary to establish this virtual host, otherwise Tomcat will not / webApps / root / page.

Five, the sun is coming! - Install Apache:

1. First installation JK2Connector:

Since the RedHat AdvanceEnterprise Server is installed by default, this Apache is lacking, the important part required for the integration of the work is -Mod_jk2.so library file, but to get this library file to compile JK2Connector source code.

But when I solve jakarta-tomcat-connectors-jk2-src-current.tar.gz, enter Jakarta-Tomcat-Connectors-JK2-

2.0.4

-src / jk / native2, error occurred while executing ./configure 1:

[root @ SMS JK] # cd native2 /

[root @ SMS native2] # ls

Aclocal.m4 build.txt Common Install.txt Scripts

APR Build.xml Configure JNI Server

Autom4te.cache changes.html configure.in makefile.in status.txt

BuildConf.sh changes.txt incrude readme.txt Tomcat

[root @ SMS native2] # ./configure

Checking build system type ... i686-redhat-linux-gnu

Checking Host System Type ... i686-redhat-linux-gnu

Checking Target System Type ... i686-redhat-linux-gnu

...

Checking for mkdir ... / bin / mkdir

No apxs given

No apxs2 given

Checking checking for apache13 ... not provided

Checking checking for apache20 ... not provided

Checking Checking for Iis ...... Not provided

Checking Checking for iplanet ...... Not provided

Checking for Tomcat33 Location ... not provided

Checking for Tomcat40 Location ... Not provided

Checking for tomcat41 location ... not provided

Configure: Error: Cannot Find Any Web Server

The configuration is incorrectly interrupted, which seems to be requested by APXS or APXS2. What is APXS or APXS2? So I heLP:

[root @ SMS native2] # ./configure --help

...

--with-apxs = file location of apxs for apache 1.3

--with-apxs2 = file location of apxs for apache 2.0

...

Really need to provide the path to the apxs file, look up with the locate command:

[root @ SMS httpd] # locate APSX

[root @ SMS httpd] # There is no APSX file in the system. This can be embarrassing me. Why do Redhat not complete in the release of an enterprise version! Things that are often easy to use have hidden defects, this is really a famous saying! No way, I have to install one.

2. Install Apache

2.0.52

:

Follow the trilog of the installer under Linux: ./ Configure, make, make install. This process is for general Linux enthusiasts, IT's Easy. . Japache

2.0.52

The installed in the / usr / local / apache directory and that APXS file is also automatically placed / usr / local / apache2 / bin / apxs.

3. Compilation again and install JK2Connector:

Note You must specify the path to the apxs file when configure! Otherwise, install Apache

2.0.52

.

[root @ SMS native2] # ./configure --with-apxs2 = / usr / local / apache2 / bin / apxs

...

[root @ SMS native2] # Make

...

After Make is completed, in / home / liudan / jakarta-tomcat-connectors-jk2-

2.0.4

A lot of files and a USR directory are generated in the -src / jk / build / jk2 / apache2 directory. But I have a mistake when I am Make Install, I have to be installed manually. L

Take a look at what is the USR directory:

[root @ SMS Apache2] # ls usr / local / apache2 / modules /

MOD_JK2.A MOD_JK2.LA MOD_JK2.SO

Oh! MOD_JK2.SO I have to find is here, copy it to the Modules directory of Apache.

[root @ SMS Apache2] # CP usr / local / apache2 / modules / * / usr / local / apache2 / modules /

4. summary:

This apache

2.0.52

It is installed with JK2Connector.

Sixth, Dial Cloud See Day - Configure Apache:

Apache's configuration file is placed in the / usr / local / apache / conf directory. Apache's entire configuration consists of two files established or modified.

1. Create Workers2.properties:

# Only at beginnin. in Production UNcomment IT OUT

[Logger.Apache2]

Level = Debug

[SHM]

FILE = / usr / local / apache / logs / shm.file

SIZE = 1048576

# Example Socket Channel, Override Port and Host.

[Channel.socket: 192.168.1.111: 8009]

Port = 8009

Host = 192.168.1.111

The purpose of establishing this file in the / usr / local / apache / conf directory is the same as the JK.Properties file when configuring Tomcat, telling Apache how to connect Tomcat.

2. Modify httpd.conf files, add loadModule and add a virtual host.

...

LoadModule JK2_Module "/usr/local/apache2/modules/mod_jk2.so"

...

NamevirtualHost *: 80

serveradMin Webmaster @ Demo

Servername 192.168.1.114

DirectoryIndex Index.jsp Index.html

JKuriSet Worker Ajp13: 192.168.111: 8009

LoadModule describes the path to the JK2 module, and the virtual host has established a Web service using the 80-port of 192.168.114, which communicates with Tomcat through the 8009 port of the JK2Connector connection Tomcat (address 192.168.111).

3. Start Apache Service:

Execute the Apachectl command in the / usr / local / apache / bin directory:

[root @ SMS bin] # ./apachectl start

(98) Address Already in Use: make_sock: could not bind to address

0.0.0

.0: 80

NO Listening Sockets Available, SHUTTING DOWN

Unable to open logs

Note HTTPD installed by the system default installation, as long as KILL is off, run ./apachectl start again.

If you encounter the following error, check if the LoadModule line in httpd.conf is a matter!

[root @ SMS bin] # ./apachectl start

SYNTAX Error Online 1053 of /usr/local/apache2/conf/httpd.conf:

Invalid Command 'jkuriset', Perhaps Mis-Spelled or Defined by a Module Not Included in The Server Configuration

Seven. Big ending - Access Apache!

If the browser appears below when accessing apache, check if the Apache and Tomcat's service start normal, whether the Apache and Tomcat configuration files are correct.

Internal Server Error

The Server Encountered An Internal Error Or Misconfiguration and Was Unable to Complete your request.

Please Contact the Server Administrator, Webmaster @ Demo and Inform The of the time the error Occurred, and anything you might Have Done tror.

More information about this error. Be be available in the server error log.

-------------------------------------------------- ------------------------------

Apache /

2.0.52

(UNIX) MOD_JK2 / 2.0.4 Server AT 192.168.1.114 Port 80

Of course, you can also look at the log and find the cause of the error:

[root @ SMS build] # vi / usr / local / apache2 / logs / error_log

[Jan 20 15:16:56 2005] Urienv.init () map to invalid worker / AJP13: 192.168.1.111: 8009 [THU Jan 20 15:16:56 2005] [Error] Urienv.init () Map to Invalid Worker / AJP13: 192.168.1.111: 8009

[THU Jan 20 15:16:56 2005] [Error] Urienv.init () map to invalid Worker / AJP13: 192.168.1.111: 8009

[THU Jan 20 15:16:56 2005] [Error] Urienv.init () map to invalid Worker / AJP13: 192.168.1.111: 8009

[THU Jan 20 15:16:56 2005] [Error] Urienv.init () map to invalid Worker / AJP13: 192.168.1.111: 8009

[THU Jan 20 15:16:56 2005] [NOTES] APACHE /

2.0.52

(UNIX) MOD_JK2 / 2.0.4 Configured - Resuming Normal Operations

[THU Jan 20 15:22:47 2005] [Error] MOD_JK2.Handle () no worker /index.jsp

[THU Jan 20 15:22:47 2005] [Error] MOD_JK2.Handle () No Worker for /favicon.ico

[THU Jan 20 15:22:51 2005] [Error] MOD_JK2.Handle () No Worker FOR /

[THU Jan 20 15:22:51 2005] [Error] MOD_JK2.Handle () No Worker for /favicon.ico

[THU Jan 20 15:22:53 2005] [Error] MOD_JK2.Handle () No Worker for /

[THU Jan 20 15:22:53 2005] [Error] MOD_JK2.Handle () No Worker for /

[THU Jan 20 15:22:55 2005] [Error] mod_jk2.handle () no worker

[THU Jan 20 15:22:56 2005] [Error] mod_jk2.handle () no worker

[THU Jan 20 15:23:18 2005] [Error] MOD_JK2.Handle () No Worker for /

[THU Jan 20 15:23:19 2005] [Error] mod_jk2.handle () No Worker for /

[THU Jan 20 15:23:22 2005] [Error] MOD_JK2.Handle () No Worker for /

[THU Jan 20 15:23:22 2005] [Error] MOD_JK2.Handle () No Worker for /Favicon.ico

~

转载请注明原文地址:https://www.9cbs.com/read-66515.html

New Post(0)