apache-2.0.43和tomcat-4.1.12集成

Apache 2.0.48 / Tomcat 4.1.29 / mod_jk for Windows XP Pro


last update: 12/13/2003

Building an Apache HTTP + Tomcat environment is five major steps:

  1. install JDK
  2. install Apache
  3. install Tomcat
  4. install a connector, in this case JK
  5. configure and test

Since Tomcat is 100% Java, we'll use the binary install instead of having to deal with ant. My preference is to put things in locations on disk so that spaces are not part of the path name. Use whichever location suits your purposes, but there have been many posts on various mailing lists where path names with spaces caused mysterious, hard to diagnose problems. It's best to avoid them when possible. Aside from that, paths in this scenario don't have much effect as long as you can guarantee that they are consistent throughout the various configuration steps.

Assumptions

  1. Directory names, folder names, and any path names WILL NOT have spaces in them. Whenever possible, store things in places where the path names do not have spaces.
  2. Mod_jk is used as the Apache connector.
  3. You don't want multiple virtual hosts. If you want to have multiple virtual hosts, that is, more/other than http://localhost, check out my Virtual Hosting HOWTO. (coming soon)
  4. You want Tomcat and Apache installed as services, not as user-level applications.
  5. Your user account has administrator privileges. If it doesn't, find someone who does.

Install JDK

  1. go to Sun's Java download site and download J2SE for Windows: http://java.sun.com/j2se/1.4.2/download.html. I prefer the SDK version, and I prefer the Offline Installation version. Offline because then you can copy it to a shared folder or even burn it to a CD, and install it as many times as you like without needing an Interne connection. From here on out, I will assume that you've got the SDK version, and are using the Offline Installation version. When you finish downloading, you will have a file called j2sdk-1_4_2_01-windows-i586.exe.
  2. To install J2SDK, just execute the file you downloaded. Once the Installer is finished unpacking, you'll be presented with a standard license prompt. (screenshot) If you agree, choose the appropriate option and click Next.
  3. The installer will display a standard installation dialog. (screenshot) Click Next. This will install J2SE in C:/j2sdk1.4.2_01, which is fine.
  4. Register the browsers on your system, and click Install. (screenshot)
  5. After the install has finished, click Finish.

Build/Install Apache HTTP

  1. First and foremost, make sure you do not have a web server or other process already listening on port 80. Click Start->Administrative Tools->Services and scroll the right hand window pane until you can see the service named World Wide Web Publishing. Highlight that service, and click the Stop icon in the toolbar. (screenshot)
  2. While you have the Services applet open, choose the World Wide Web Publishing service again, and click on the Properties icon in the toolbar. In the next window, choose Manual where it says Startup type. Click OK, then close the Services applet. (screenshot)
  3. Download the Windows MSI Apache distribution from a mirror. You want version 2.0.48. The filename is apache_2.0.48-win32-x86-no_ssl.msi.
  4. Execute the MSI installer. You'll see a welcome screen. (screenshot)
  5. Click Next. Accept the terms of the license, and click Next again. The README file will be displayed. Read through it, and when finished, click Next.
  6. On the next screen, replace the default values with localhost for Network Domain and Server Name. For Email Address, use your email address or any other value you wish. Make sure to choose the option For All Users, on Port 80 as well. Click Next when ready. (screenshot)
  7. On the next screen, choose Typical and click Next.
  8. We are going to put Apache 2.0.48 in a directory called C:/ApacheGroup. Notice the lack of spaces in the path name. To do this, click the button that says Change and use the file dialog box to change to the C:/ drive, where you will create a new folder called ApacheGroup. When finished, your screen should look like this. If it does, click Next to continue to the next screen.
  9. You should be looking at the final screen before the install process begins. (screenshot) Click Install to begin the installation.
  10. When the installation is finished, a screen will be displayed. Click the Finish button. You should now have an Apache instance in C:/ApacheGroup/Apache2. Verify the installation by opening a web browser and browsing to http://localhost. If everything installed correctly, you will see an Apache Welcome page.
  11. Shutdown Apache until you can get the connector installed by right-clicking on the Apache monitor service in your taskbar (it's the tiny feather icon), and selecting Stop. (screenshot)

Build/Install Tomcat

  1. First, create a folder on your hard drive. Call it Tomcat, and put it in the C drive root, so that you end up with C:/Tomcat. NOTE: You can put Tomcat wherever you like, it is your choice. Wherever you put it, try to keep spaces or other unusual characters out of the pathname.
  2. Now, grab the Windows EXE distribution for Tomcat 4.1.29 from a mirror site. The filename is jakarta-tomcat-4.1.29.exe
  3. Once it is downloaded, execute the file.
  4. Agree to the license, and click Next. On the next screen, check the box marked NT Service. (screenshot) Click Next again.
  5. Next, change the directory where Tomcat will be installed. Change the default so that there are no spaces in the pathname. (screenshot)
  6. When the install completes, you'll be presented with a final screen that will let you test your installation. (screenshot) Make sure to use a decent password for the admin user. Click Next to verify and complete the installation.
  7. At this point, Tomcat should be running. Browse to http://localhost:8080 to be sure. If everything is ready, you'll see the Tomcat Welcome page. Verify the Tomcat examples are available at http://localhost:8080/examples.

Install the Connector

The two connectors (JK and JK2) are different; JK2 is a complete rewrite of the earlier JK/AJP13 protocol. We'll cover installing JK here. For JK2, check out my JK2 HOWTO (coming soon).
  1. Download the connector binary for Windows from a Jakarta mirror site. Scroll down to where it says Tomcat Web Server Connectors and then click on JK 1.2 Binary Releases. Click on the Win32 folder and download the file named mod_jk_1.2.5_2.0.47.dll.
  2. When the download is complete, copy the DLL file to C:/ApacheGroup/Apache2/modules. Rename the file to mod_jk.dll. This will leave you with C:/ApacheGroup/Apache2/modules/mod_jk.dll. The location on your system may be different...that's fine, the point is to put the JK DLL file in Apache's modules directory, wherever that may be.

Final Configuration

NOTE: these steps will allow access to the Tomcat examples via Apache on port 80. Successful use of the examples on port 80 shows that mod_jk is working correctly, since Tomcat is configured to run on port 8080 by default for HTTP requests.
  1. You're going to be making edits to a file called server.xml in Tomcat's conf directory. If you've used the installation locations suggested previously, the file you want is C:/Tomcat/Tomcat-4.1/conf/server.xml. This file is vital to Tomcat operation, so it is a good idea to make a copy before it gets modified.
  2. Now, let's edit server.xml in Tomcat's conf. Use any editor you'd like. For our purposes, we'll use Notepad.
  3. Look for a line that says "Server" and has a port of 8005. Add the following directly below:
    <Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" modJk="C:/ApacheGroup/Apache2/modules/mod_jk.dll" />
  4. In the Host container add the following Listener directive (yes, it looks very similar to the one above):
    <Listener className="org.apache.ajp.tomcat4.config.ApacheConfig" append="true" forwardAll="false" modJk="C:/ApacheGroup/Apache2/modules/mod_jk.dll" />
    Save your changes and exit the editor.
  5. Now, we need to make a small edit to Apache's httpd.conf. Edit httpd.conf in APACHE_HOME/conf. Don't worry about making a copy, the Apache team put one there for you already (it's called httpd-std.conf). Like editing server.xml, use any editor you'd like.
  6. Add a single line at the end of the file:
    Include "C:/Tomcat/Tomcat-4.1/conf/auto/mod_jk.conf"
    Note: the mod_jk.conf file gets created by Tomcat when Tomcat starts. It gets created every time Tomcat starts. So, if you have your server.xml configured, you can ignore httpd.conf (in most cases) except to add the Include directive for mod_jk.conf. You don't need to create or edit mod_jk.conf, Tomcat will do this for you. Click here for a sample mod_jk.conf file generated automatically by Tomcat on each startup.
  7. Create a file in C:/Tomcat/Tomcat-4.1/conf/jk called workers.properties. In that file, put the following lines:
    worker.list=ajp13
    worker.ajp13.port=8009
    worker.ajp13.host=localhost
    worker.ajp13.type=ajp13
    Save the file. This file provides necessary information to mod_jk, like where to find Tomcat and what port to use when connecting.
  8. Start Tomcat: Wait at least 30 seconds for tomcat to complete the startup process. Verify that you have a file called C:/Tomcat/Tomcat-4.1/conf/auto/mod_jk.conf and that the timestamp on that file is recent before going to the next step. An example mod_jk.conf file can be found here.
  9. Start Apache.
  10. Verify examples at http://localhost:8080/examples. On success, Tomcat is working correctly.
  11. Verify examples at http://localhost/examples. On success, Apache is working correctly, and JSP and servlet requests are being passed to Tomcat.

Please send comments, suggestions, or changes to john AT johnturner DOT com. Be advised that I will be happy to help where I can, but I am not available for free one-on-one tech support to the whole world. :)

Other Resources

My Apache + Tomcat Virtual Hosting HOWTO (coming soon)
My Apache + Tomcat + JK2 HOWTO (coming soon)
Oscar Carillo's Tomcat Site
The Tomcat FAQ

配置整合Win+Apache+PHP+MySQL+Tcomcat(或Resin)完全手册
作者:未知 来源:未知 加入时间:2004-8-24 天新软件园
系统要求:
          硬件能跑起操作系统即可
          Win2K、WinXP或 Win2003操作系统
          
前期准备:
          所需软件列表:(本配置以 下列软件版本完成)
1、 APACHE_2.0.47-win32-x86-no_ssl  (Apache web服务器)
2、 PHP-4.3.3-Win32                  (PHP语言解析器)
3、 MySQL-4.0.12-win                 (MySQL数据库)
4、 j2sdk-1_4_2-windows-i586          (JAVA 语言环境)
5、 Jakarta-Tomcat-5.0.9              (Tomcat JSP解析服务器)
6、 Resin-3.0.3                       (Resin JSP解析服务器)
7、 mod_jk_1.2.5_2.0.47.dll            (整合Apache+Tomcat的plus)
8、 mm.mysql-2.0.4-bin.jar             (JSP访问连接MySQL文件)

开始安装:
   
一、 Apahce+PHP+MySQL安装配置

1. 安装APACHE_2.0.47-win32-x86-no_ssl ,程序默认安装路径为:C:/apache2/program files/apache Group/ ,需要将其安装路径修改为:C:/
(也可以不做修改,主要为了修改配置方便做修改的)。
2. 安装完成之后,apache服务自动加载,这时打开浏览器,浏览:http://localhost,出现apache欢迎页面(这步需要将C:/ apache2/htdocs目录中的文件“index.html.en”改为“ index.html”,方能显示);如果这步出现异常,请检查安装源文 件,重新安装。
3. 安装PHP-4.3.3-Win32,一般下载的PHP文件为一个免安装的压缩包,解压到C:/PHP就可以。
4. 配置PHP和Apache,使之能解析php程序。
PHP配置:将C:/PHP/目录中的“php.ini-dist”改名“php.ini”,并复制到 C:/windows/system32(Win2K目录为:C:/winnt/system32)
Apache配置:
C:/apahce2/conf/httpd.conf




httpd.conf
D在此配置文件最后添加以下语句,用以支持php程序:
    ScriptAlias /php/ "C:/PHP/"
    AddType application/x-httpd-php .php3
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php .phtml
    Action application/x-httpd-php "/php/php.exe"

         5.重新启动Apache服务器,用编 辑器编写如下语句:             
<?
  phpinfo();
?>

             保存文件名为“test.php”到C:/apache2/htdocs目录,然后打开浏览器,浏览:http: //localhost/test.php,出现PHP基本信息就说明配置成功。严格按以上说明安装配置,都会一次成功。
         6. 安装MySQL-4.0.12-win,一直按”next”就安装成功了,然后在C:/mysql/bin目录执行 ” winmysqladmin.exe”,出现mysql的初始信息面,表示安装成功。
         7. PHP连MySQL此处略过,一般没有什么问题。
         
到此可以休息一下,准备下面的漫长过程……

二、安装JDK和Tomcat
1. 安装j2sdk-1_4_2-windows-i586,JDK一定要在Tomcat和Resin之前安装,默认安装路径就可以。
2. 安装Jakarta-Tomcat-5.0.9,默认安装路径就可以。
3. 复制mm.mysql-2.0.4-bin.jar文件分别到C:/j2sdk1.4.2/lib 和 C:/Tomcat 5.0/common/lib
4.设置环境变量(桌面->我的电脑->右键点击->选择“属性”->高级->环境变量),所有 设置均在系统变量栏进行。
新建->变量名:JAVA_HOME
    ->变量值:C:/j2sdk1.4.2
新建->变量名:TOMCAT_HOME
    ->变量值:C:/Tomcat 5.0
新建->变量名: PATH
    ->变量值:.;C:/j2sdk1.4.2/bin;  (前面的 “.;”一定要有)
修改增加环境变量 CLASSPATH (如果没有此变量名,则新建)
    ->增加变量值:.;C:/j2sdk1.4.2/lib/dt.jar;C:/ j2sdk1.4.2/lib/tool.jar;
C:/j2sdk1.4.2/lib/NetComponents.jar;
C:/j2sdk1.4.2/lib/mm.mysql-2.0.4-bin.jar;
C:/Tomcat 5.0/common/classes;
C:/Tomcat 5.0/common/lib;
C:/Tomcat 5.0/common/lib/servlet-api.jar;
(前面的“.;”一定要有)

      5. 启动Tomcat服务器,打开浏览器,浏览:http://localhost:8080/ ,出现Tomcat欢迎页面;如果这步出现异常,请检查安装源文件,重新安装。


   三、整合Apache+Tomcat服务器

1. 复制mod_jk_1.2.5_2.0.47.dll文件到C:/Apache2/modules目录。
2. Apache配置:
C:/apahce2/conf/httpd.conf
httpd.conf
在此配置文件最后添加以下语句,用以支持jsp程序:
LoadModule jk_module modules/mod_jk_1.2.5_2.0.47.dll

JkWorkersFile "C:/Tomcat 5.0/conf/workers.properties"
JkMount /servlet/* ajp13
JkMount /*.jsp ajp13

3. 查看C:/Tomcat 5.0/conf/server.xml文件中有关端口“8009”是否被注释,如果是和我这的版本一致的话,不用修改。
4. 在C:/Tomcat 5.0/conf/目录下,新建文件名为“workers.properties”的文件,将如下内容复制到新建文件 workers.properties中。

workers.properties
# 只复制以下内容即可:

# 这现行根据安装目录做修改
workers.tomcat_home=C:/Tomcat 5.0
workers.java_home=C:/j2sdk1.4.1_01
ps=/
# worker.list=ajp13
worker.list=ajp12,ajp13  

worker.ajp12.port=8007
worker.ajp12.host=localhost
worker.ajp12.type=ajp12
worker.ajp12.lbfactor=1
             
worker.ajp13.port=8009         
worker.ajp13.host=localhost      
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1

worker.loadbalancer.type=lb

worker.loadbalancer.balanced_workers=ajp12, ajp13
worker.inprocess.type=jni
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)classes
worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)jaxp.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)lib$(ps)parser.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)jasper.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)servlet.jar

worker.inprocess.class_path=$(workers.tomcat_home)$(ps)common$(ps)lib$(ps)webserver.jar

worker.inprocess.class_path=$(workers.java_home)$(ps)lib$(ps)tools.jar

worker.inprocess.cmd_line=-config

worker.inprocess.cmd_line=$(workers.tomcat_home)/conf/jni_server.xml

worker.inprocess.cmd_line=-home

worker.inprocess.cmd_line=$(workers.tomcat_home)

worker.inprocess.jvm_lib=$(workers.java_home)$(ps)jre$(ps)bin$(ps)classic$(ps)jvm.dll


worker.inprocess.stdout=$(workers.tomcat_home)$(ps)inprocess.stdout

worker.inprocess.stderr=$(workers.tomcat_home)$(ps)inprocess.stderr

worker.inprocess.sysprops=tomcat.home=$(workers.tomcat_home)


          5. 到此Apache 和 Tomcat整合完成,重启Apache和Tomcat服务器,
用编辑器编写如下内容:

<%@ page contentType="text/html;charset=gb2312"%>

<html>
<head>
<title>HI-JSP实验</title>
</head>
<body>
<%
  String Msg = "This is JSP test! 看到这段话,恭喜你,成功了!";  
  out.print("Hello World!");
%>
<h3><%=Msg%></h3>
The current date and time is <%=new java.util.Date() %>
<br>
<%
  String str = "Using trim() and substring() can be very useful";
  out.println(str);
%>
</body>
</html>

保存文件名为“test.jsp”到C:/Tomcat 5.0/webapps/ROOT目录,然后打开浏览器,浏览:http://localhost:8080/test.jsp,如果显示正常,然后将地 址改为:http://localhost/test.jsp  显示正常说明配置成功。严格按以上说明安装配置,都会一次成功。

  四、整合Apache+Tomcat+MySQL
    
      这步相对简单许多,但也是最不容易成功的部分,前面已经将JSP的MySQL 驱动放到相应的目录中,环境变量也设置,所以只是测试JSP是否可以连接MySQL数据库。

      1. 测试1,用编辑器编写如下内容:

<%@ page contentType="text/html;charset=gb2312" %>
<%
java.sql.Connection conn;
java.lang.String strConn;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn= java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
%>
      注:数据库此处为:test 连接数据库存的用户名为:root  密码为空。根据自己数据库作相应修改。

保存文件名为“test-mysql.jsp”到C:/Tomcat 5.0/webapps/ROOT目录,然后打开浏览器,浏览:http://localhost:8080/test-mysql.jsp 或 http://localhost/test-mysql.jsp ,运行后,如果显示为空白页面,说明连接数据库成功,否则说明没有连接成功,请往回逐步仔细配置。

      2. 测试2,用编辑器编写如下内容:



<%@ page contentType="text/html;charset=GBK" %>
<%@ page language="java" import="java.sql.*"%>
<%
Connection conn = null;
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn = java.sql.DriverManager.getConnection("jdbc:mysql://localhost/test","root","");
if(conn==null){
System.out.println("get Conn Error");
}
Statement stmt=conn.createStatement();
ResultSet RS_result=null;
%>
<html>
<head>
<title>测试</title></head>
<body>
<%
RS_result=stmt.executeQuery("select * from guestbook");
String Name;
while(RS_result.next())
{
Name=RS_result.getString("name");
%>
<%=Name%>
<%
}
RS_result.close();
stmt.close();
conn.close();
%>
</body>
</html>

保存文件名为“test-mysql2.jsp”到C:/Tomcat 5.0/webapps/ROOT目录,然后打开浏览器,浏览:http://localhost:8080/test-mysql2.jsp 或 http://localhost/test-mysql2.jsp ,运行后。




五、安装Resin,整合Apache+Resin

1. 假定机子上现在没有启动别的JSP解析服务器,如果启动请关闭该服务。
2. 直接解压Resin-3.0.3.zip到C:/
3. 在字符模式下用命令:C:/resin-3.0.3/bin/httpd –install
将Resin安装为系统的一个服务,然后在服务中启动Resin.
删除服务命令:C:/resin-3.0.3/bin/httpd –remove
4. 打开浏览器,浏览:http://localhost:8080 ,如果显示有Resin信息,则Resin服务已经启动 。
5. Apache配置:
C:/apahce2/conf/httpd.conf
     
httpd.conf
在此配置文件最后添加以下语句:

    LoadModule caucho_module C:/resin-3.0.3/libexec/apache-2.0/mod_caucho.dll

    <IfModule mod_caucho.c>
      ResinConfigServer localhost 6802
      <Location /caucho-status>
      SetHandler caucho-status
      </Location>
    </IfModule>

    AddHandler caucho-request jsp
    <Location /servlet/*>
     SetHandler caucho-request
    </Location>

      保存,重启apache.

      6. Resin配置:
        C:/resin-3.0.3/conf/resin.conf

resin.conf
修改默认目录,红色部分为修改内容:
<server>
  <host id="">
    <document-directory>C:/Apache2/htdocs</document-directory>
    ...
  </host>
</server>


      完成后保存,重启Resin服务,把编辑好的JSP文件存放到C:/ Apache2/htdocs目录,然后打开浏览器浏览,就可以在PHP和JSP之间自由窜越了。

Window 2K 上 Apache-2.0.47 + Tomcat-4.1.27 + JK-2.0.4 的整合     选择自 ljcao 的 Blog
关键字  Window 2K 上 Apache-2.0.47 + Tomcat-4.1.27 + JK-2.0.4 的整合
出处 

1.  软件获取:
    Apache:去http://httpd.apache.org/download.cgi 下载;
    JDK:去http://jakarta.apache.org/site/binindex.cgi下 载(我的是1.4.2);
    Tomcat:去http://apache.bestwebcover.com/jakarta/tomcat-4/下 载;
    JK:去http://mirrors.mix5.com/apache/jakarta/tomcat-connectors/jk2/binaries/win32/ 下载。

2. 安装Apache、JDK和Tomcat,这就不用说了吧。

3.  将获取的Apache版的JK包jakarta-tomcat-connectors-jk2.0.4-win32-apache2.0.49.zip解 压缩到JK目录,将JK/conf/mod_jk2.conf.sample和JK/conf/workers2.properties.sample复 制到Apache/conf/目录下,并改名为mod_jk2.conf和workers2.properties,用文本编辑器打开 mod_jk2.conf文件,将"/usr/local/etc/apache2/workers2.properties"改为 workers2.properties文件的绝对路径,我的是"JkSet config.file "E:/Apache2047/conf/workers2.properties"";将JK/modules/mod_jk2.so复制到 Apache的modules/目录下,JK/doc/目录是一些说明文档,有兴趣你可以看看。

4. 用文本编辑器打开Apache/conf/httpd.conf文件,找到LoadModule 语句,在LoadModule 区域的最后面加一句"LoadModule jk2_module "modules/mod_jk2.so"";

5. 最后,重新启动Apache和tomcat。(命令行:net stop apache2、tomcat/bin/shutdown.bat;net start apache2、tomcat/bin/startup.bat)

6. 在浏览器访问http://localhost/jkstatus将 会看到JK的运行状态信息,访问http://localhost/examples/ 将会看到Tomcat的示例页面,整合完毕。

7. BTW,如果你想在Apache中添加更多的Tomcat虚拟目录,请在workers2.properties中添加。

最新整理apache-2.0.43和tomcat-4.1.12集成


作者:luyongshou 2005-02-02 15:04:45 来自:Linux先生

 在此介绍一下我在RedHat Linux 7.2下装Apache与Tomcat4整合的过程,重点讲述mod_webapp.so的制作方法,
  以及在虚拟主机环境下的配置、管理和应用,经测试已经成功。希望对各位有所帮助,如有错误也请指正。

一、正确安装Tomcat4
  必要软件的安装,如下:
  1、Java SDK
  版本1.3.1或1.4,建议安装在/usr/java下,并做一个jdk的软链接。
  如果在装版本1.3.1的SDK出现问题,请阅读文档:http://java.sun.com/j2se/1.3/install-linux-sdk.html
  2、Tomcat4
  建议安装最新release版本的二进制文件安装包。当前最新的tomcat版本是4.1.12。
  下载地址:
  http://jakarta.apache.org/builds/ja...t-4.1.12.tar.gz
  下载后接压到一个目录 "tar xvzf jakarta-tomcat-4.1.12.tar.gz"
本例将tomcat安装在/opt目录下,并做了个tomcat的软链接。
  设置如下环境变量并启用:
  PATH=$PATH:/usr/java/jdk/bin:/usr/java/jdk/jre/bin
  JAVA_HOME=/usr/java/jdk
  export JAVA_HOME
  CLASSPATH="./:/usr/java/jdk/lib:/usr/java/jdk/jre/lib"
  export CLASSPATH
  CATALINA_HOME=/opt/tomcat
  export CATALINA_HOME

  建议单建一个用户tomcat,将其设成/opt/tomcat以下所有目录文件的属主,并由它启动tomcat:
  # useradd tomcat
  # chown -R tomcat:tomcat /opt/tomcat
  # su - tomcat -c "/opt/tomcat/bin/startup.sh"

  访问http://localhost:8080/ 应能看到tomcat安装成功的页面。


===================================================================
如果想和apache集成需要修改tomcat/conf/server.xml这个文件的

<!-- Define an Apache-Connector Service -->

<Service name="Tomcat-Apache">
<!--
<Connector className="org.apache.catalina.connector.warp.WarpConnector"
port="8008" minProcessors="5" maxProcessors="75"
enableLookups="true" appBase="webapps"
acceptCount="10" debug="0"/>

<Engine className="org.apache.catalina.connector.warp.WarpEngine"
name="Apache" debug="0">

<Logger className="org.apache.catalina.logger.FileLogger"
prefix="apache_log." suffix=".txt"
timestamp="true"/>

<Realm className="org.apache.catalina.realm.MemoryRealm" />

</Engine>

</Service>
-->
</Server>

中的"<!--"和"-->"删掉,其实就是解除注释,因为这个网站是专门用来和apache的集成的。

二、Apache与Tomcat4的整合

  1、首先安装Apache,
  请注意Apache必须安装DSO模式,即在执行./configure时须加上 --enable-module=so

  默认安装到/usr/local/apache目录下。本例安装的apache的版本是2.0.43系列的。

  2、制作mod_webapp.so
  需要以下软件包:
  jakarta-tomcat-connectors-4.x.xx-src.tar.gz
  下载地址在tomcat对应版本的src目录下。例如,我安装的tomcat版本是4.1.12,则现在所需要的软件包的位置是:
  http://jakarta.apache.org/builds/ja...1.12-src.tar.gz
  apr-0.9.1.tar.gz
  下载地址:http://www.apache.org/dist/apr/apr-0.9.1.tar.gz
  autoconf-2.52-ximian.1.i386.rpm
  下载地址:http://rpmfind.net/linux/RPM/helix/...ian.1.i386.html
  先用rpm安装autoconf-2.52,因为下面的安装将要用到;
  然后解开jakarta-tomcat-connectors-4.1.12-src.tar.gz,生成jakarta-tomcat- connectors-4.1.12-src目录,
  进入jakarta-tomcat-connectors-4.1.12-src/webapp的目录里,再把apr-0.9.1.tar.gz解到 这个目录下,
  并把刚生成的目录apr-0.9.1的目录名改成apr。
  还是在webapp目录,运行以下命令:
  # support/buildconf.sh
  此时如果autoconf的版本低于2.52的话会报错退出,所以必须先安装autoconf-2.52。
  当命令成功结束后会在当前目录下生成configure文件。
  依次运行以下命令:

  # ./configure --with-apxs=/usr/local/apache/bin/apxs
  # make
  # cp apache-2.0/mod_webapp.so /usr/local/apache/modules

  现在mod_webapp.so已经制作好了,并已经拷贝到apache的modules目录下。
  编辑apache的配置文件,在最后加上如下几行:
  ==========================
  LoadModule webapp_module modules/mod_webapp.so
  WebAppConnection Connector warp localhost:8008
  WebAppDeploy examples Connector /examples
  ==========================

  运行以下命令:
  # /usr/local/apache/bin/apachectl configtest

如果出现错误说你的apache的httpd.conf有问题后面的错误是"inviad virual host"

就说明你的httpd.conf的ServerName没有设,把ServerName前面的"#"去掉就可以了!(这是差了好多资料才得到的答案,我也 是在这儿困惑了好多天了)

  只要出现“Syntax OK”就表明mod_webapp.so已经安装成功了。
  启动apache
  # /usr/local/apache/bin/apachectl start
  访问http://localhost/examples 就可以看到tomcat的例子程序了。

注意:一定要先启动tomcat 然后再重新启动apache!

三、虚拟主机下的配置、管理和应用

  下面以一个例子来说明虚拟主机如何同时使用Apache与Tomcat4

  虚拟主机host1的目录结构如下所示:


  /www               
   |---host1  虚拟主机host1的主目录
   |  |--htdocs  普通根目录:用于显示静态页面或php程序
   |  |----logs  apache访问日志
   |  |----webapps java应用目录(新加,与tomcat的webapps目录无任何关联)
   |     |--ROOT jsp根目录:用于显示jsp页面程序
   |     |----jive 一套java应用实例
   |---host2   虚拟主机host2的主目录
  ............



  原来的apache的配置文件是这样配置的:


  =====================================
  NameVirtualHost xxx.xxx.xxx.xxx

  < VirtualHost xxx.xxx.xxx.xxx >
  ServerName host1.mydomain.com
   ServerAdmin webmaster@mydomain.com
   DocumentRoot /www/host1/htdocs
   ErrorLog /www/host1/logs/error_log
  CustomLog /www/host1/logs/access_log common
  < /VirtualHost >
  .............

  =====================================



  现在要让虚拟主机host1能同时使用Apache与Tomcat4,需要做如下配置:

  1、编辑tomcat的配置文件server.xml,在最后的部分做如下修改:


  =====================================
  < !-- Define an Apache-Connector Service -- >

  < Service name="Tomcat-Apache" >

  < Connector className="org.apache.catalina.connector.warp.WarpConnector"
  port="8008" minProcessors="5" maxProcessors="75"
  enableLookups="true" appBase="webapps"
  acceptCount="10" debug="0"/ >

< Engine className="org.apache.catalina.connector.warp.WarpEngine"
  name="Apache" debug="0" >

  < Logger className="org.apache.catalina.logger.FileLogger"
  prefix="apache_log." suffix=".txt"
timestamp="true"/ >

  < Realm className="org.apache.catalina.realm.MemoryRealm" / >

< !-- 下面是新加的内容 -- >

  < Host name="host1.mydomain.com" debug="0" appBase="/www/host1/webapps"
uppackWars="true" autoDeploy="true" >
  < Context path="" docBase="ROOT" debug="0"/ >
< !-- 下面套用的是tomcat自带的管理页面,在虚拟主机下也可使用 -- >
< Context path="/manager" debug="0" privileged="true"
  docBase="/opt/tomcat/server/webapps/manager"/ >
  < Context path="/jive" docBase="jive" debug="0"
reloadable="true" crossContext="true"/ >
  < Logger className="org.apache.catalina.logger.FileLogger"
prefix="host1_log." suffix=".txt"
  timestamp="true"/ >
  < /Host >

< !-- 新加内容结束 -- >

< /Engine >

  < /Service >
  =====================================
  2、编辑tomcat的管理权限文件tomcat-users.xml,在中间加一行:
< user username="myname" password="mypasswd" roles="standard,manager"/ >
  3、编辑apache的配置文件,做如下修改
  =====================================
  LoadModule webapp_module libexec/mod_webapp.so
  AddModule mod_webapp.c
  WebAppConnection warpConnection warp localhost:8008
  NameVirtualHost xxx.xxx.xxx.xxx
  < VirtualHost xxx.xxx.xxx.xxx >
  ServerName host1.mydomain.com
   ServerAdmin webmaster@mydomain.com
   DocumentRoot /www/host1/htdocs
   ErrorLog /www/host1/logs/error_log
   CustomLog /www/host1/logs/access_log common

   WebAppDeploy ROOT warpConnection /

  #注:此行的作用是把ROOT目录作为虚拟主机URL的根,并使前面定义的根htdocs失效。
  #但如果不想整个虚拟主机都使用jsp页面程序,而想使用大量静态页面或php程序的话,
  #就要使用下面这行,并把所有的静态页面和php程序放在htdocs目录下。
  # WebAppDeploy ROOT warpConnection /jsp

   WebAppDeploy manager warpConnection /manager
  WebAppDeploy jive warpConnection /jive
  #在server.xml里每定义一个都要在这里加一条WebAppDeploy。

  < /VirtualHost >
  =====================================

  4、将tomcat用户设成/www/host1/webapps以下所有目录文件的属主。

  要注意的是,以后如果想上传或改动该目录以下的文件,都要将其属主改成tomcat。
  (如果一直是以root身份运行tomcat,这步可以省略。)

  # chown -R tomcat:tomcat /www/host1/webapps
  5、重起tomcat:
  # su - tomcat -c "/opt/tomcat/bin/shutdown.sh"
  # su - tomcat -c "/opt/tomcat/bin/startup.sh"
  6、重起apache:
  /usr/local/apache/bin/apachectl restart

  此时访问http://host1.mydomain.com/manager/html 会提示输入密码,在输入正确的 myname和mypasswd后,就会看到“Tomcat Web Application Manager”的页面,里面的 Application Path已经是虚拟主机里配置的信息了,并可以对其进行管理。
  到此虚拟主机下的配置和管理就全部完成,剩下的事情就是测试和应用了。在上面的例子
  里我们已经安装了jive,经测试已经可以正常运行

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值