Tomcat-5.5.7 + Apache-2.0.46 + mod_jk-2.0.4整合配置

发表于:2007-05-25来源:作者:点击数: 标签:
原文出处:http://blog.beijingnet.com/index.php?op=ViewArticleblogId=1 安装环境: OS:RedhatEnterpriseAS3 apahce:使用系统自带httpd-2.0.46,使用其它版本的redhat自带的apache安装过程也一样。 Tomcat:Tomcat-5.5.7 jdk:mod_jk:2.0.4 参考: http://w

原文出处:http://blog.beijingnet.com/index.php?op=ViewArticle&articleId=81&blogId=1

安装环境: 

OS:Redhat Enterprise AS 3 
apahce:使用系统自带httpd-2.0.46,使用其它版本的redhat自带的apache安装过程也一样。 
Tomcat:Tomcat-5.5.7 
jdk:mod_jk:2.0.4 
参考: 
http://www.reliablepenguin.com/clients/misc/tomcat/ http://www.pixelfreak.net/howto/apache2_jk2_tomcat/socket.html http://www.csse.uwa.edu.au/~ryan/tech/mod_jk2.html http://www.edong.org/main/content/view/386/38/ http://www.pixelfreak.net/howto/apache2_jk2_tomcat/socket.html http://www.cn-java.com/target/news.php?news_id=3043  



1. 安装apache
   系统自带,无须安装。需要注意的是需要安装httpd开发包,用于编译mod_jk.
   查看是否安装httpd-develop
   #rpm -qa|grep httpd-devel
   httpd-devel-2.0.46-38.ent
   如果出现以上信息说明httpd开发包已安装,如果未安装请从redhat第三张盘中安装。
   

2、安装jdk
   从java.sun.com下载jdk-1_5_0_01-linux-i586-rpm.bin,tomcat5需要jdk5的支持。
   下载后:
   #chmod 755 jdk-1_5_0_01-linux-i586-rpm.bin
   #rpm -ivh dk-1_5_0_01-linux-i586.rpm
   在/etc/profile文件中加入:
   JAVA_HOME=/usr/java/jdk1.5.0_01
   export JAVA_HOME
   PATH=$PATH:/usr/java/jdk1.5.0_01/bin
   export PATH
   export CATALINA_HOME=/usr/local/tomcat
   export TOMCAT_HOME=/usr/local/tomcat


3.安装Tomcat
   #wget http://apache.justdn.org/jakarta/tomcat-5/v5.5.7/bin/jakarta-tomcat-5.5.7.tar.gz
   #tar zxvf jakarta-tomcat-5.5.7.tar.gz
   #mv jakarta-tomcat-5.5.7 /usr/local/tomcat

4、编译和设置mod_jk
   此时注意重新登录服务器使环境变量生效。
   #wget http://apache.justdn.org/jakarta/tomcat-connectors/jk2/jakarta-tomcat-connectors-jk2-src-current.tar.gz     
   #tar zxvf jakarta-tomcat-connectors-jk2-src-current.tar.gz    
   #cd jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/
   #./configure --with-apxs2=/usr/sbin/apxs --with-jni --with-apr-lib=/usr/lib
   #vi server/apache2/Makefile
   将:LIBTOOL=/bin/sh /var/www/build/libtool --silent
   改为:LIBTOOL=/usr/bin/libtool
   将:
   fdef APR_LIBDIR_LA
   JK_LDFLAGS=-L${APACHE2_LIBDIR} -lcrypt
   else
   JK_LDFLAGS=-lcrypt ${APR_LIBS}
   endif
   改为:
   ifdef APR_LIBDIR_LA
   JK_LDFLAGS=-L${APACHE2_LIBDIR} -lcrypt
   else
   JK_LDFLAGS=-lcrypt ${APR_LIBS} -lapr-0 -laprutil-0 -lgdbm -ldb-4.1 -lexpat
   endif

   如果不修改以上内容,将出现以下错误:
   INFO: APR not loaded, disabling jni components: java.io.IOException: java.lang.UnsatisfiedLinkError:      
   /usr/lib/httpd/modules/libjkjni.so: 
   /usr/lib/libaprutil-0.so.0: undefined symbol: gdbm_errno
   或者:
   INFO: APR not loaded, disabling jni components: java.io.IOException: java.lang.UnsatisfiedLinkError:    
   /usr/lib/httpd/modules/libjkjni.so: 
   /usr/lib/httpd/modules/libjkjni.so: undefined symbol: apr_md5_final
   #make
   #libtool --finish /usr/lib/httpd/modules
   #cp ../build/jk2/apache2/mod_jk2.so ../build/jk2/apache2/libjkjni.so /usr/lib/httpd/modules/
   mod_jk安装完毕。

6、配置tomcat
   #vi vi /usr/local/tomcat/bin/catalina.sh 
   # Get standard environment variables
   PRGDIR=`dirname "$PRG"`
   CATALINA_HOME=`cd "$PRGDIR/.." ; pwd`
   if [ -r "$CATALINA_HOME"/bin/setenv.sh ]; then
   . "$CATALINA_HOME"/bin/setenv.sh
   fi
   # 添加以下行
   serverRoot=/etc/httpd
   export serverRoot

   #vi /usr/local/tomcat/conf/jk2.properties 
   handler.list=apr,request,channelJni
   channelUnix.file=/usr/local/tomcat/work/jk2.socket
   serverRoot=/etc/httpd
   apr.NativeSo=/usr/lib/httpd/modules/libjkjni.so

   #vi /usr/local/tomcat/conf/server.xml 
   在</Engine>前加入
  <Host name="www.abc.com" debug="1" appbase="/var/www/abc" unpackwars="true"> 
    <Context path="" docBase="" debug="1"/> 
 </Host> 
   配置其它虚拟主机与此同。 
   
7、设置虚拟主机
    比如,我现在有虚拟主机 www.abc.com 希望把jsp和servlet都转到tomcat去

    在 /etc/httpd/conf/ 下面创建workers2.properties,内容如下:
    [shm]
    file=/var/log/httpd/shm.file
    size=1048576


    # Example socket channel, explicitly set port and host.
    [channel.socket:localhost:8009]
    port=8009
    host=127.0.0.1


    # Example UNIX domain socket
    [channel.un:/usr/local/tomcat/work/jk2.socket]
    tomcatId=localhost:8009
    debug=0


    # define the worker
    [ajp13:localhost:8009]
    #channel=channel.un:/usr/local/tomcat/work/jk2.socket
    # To use the TCP/IP socket instead, just comment out the above
    # line, and uncomment the one below
    channel=channel.socket:localhost:8009


    # Announce a "status" worker
    [status:status]

    [uri:/status/*]
    worker=status:status

    # Uri mapping
    [uri:/jsp-examples/*]


    在/etc/httpd/conf/httpd.conf里面配置:
    #tomcat
    LoadModule jk2_module modules/mod_jk2.so
    JkSet config.file /etc/httpd/conf/workers2.properties

    #把下面这段放到VirtualHost之前,可以从全局避免用户用apache访问WEB-INF目录。
    
    <Directory ~ "/WEB-INF/">
     Order allow,deny
     Deny from all
    </Directory>
    

    #典型的VirtualHost配置样本
    NameVirtualHost 1.2.3.4 #(1.2.3.4你的服务器IP)
    <VirtualHost 1.2.3.4>
    ServerName www.abc.com
    DocumentRoot /var/www/abc
    DirectoryIndex index.htm index.html default.htm index.php index.jsp
    <Location ~ "/*.jsp|/*/servlet/*>
    JkUriSet worker ajp13:localhost:8009
    </Location>
    ErrorLog logs/www.abc.com-err_log
    CustomLog logs/www.abc.com-aclearcase/" target="_blank" >cc_log common
    </VirtualHost>
    
    这样就可以为每个不同的虚拟主机分别指定使用或者不使用jsp功能。

8、启动、测试
   #service httpd start
   #/usr/local/tomcat/bin/startup.sh 
   浏览器里输入
   http://1.2.3.4/jsp-examples/
   http://1.2.3.4/status/

   如果没有问题则说明安装成功。


欢迎与我交流
qq:138722
e-mail:xiaowei@beijingnet.com

 flighttop 回复于:2005-03-10 02:20:11
Several products, such as Blackboard Learning System, is built on this model. It is very good. Thanks!

 斜月三星 回复于:2005-03-10 11:44:29
太感谢了,我正在发愁这个问题呢!用别的方法不行。看了很多文章了。一会儿我就去试一试。另外,Apache怎么升级呢?我怕影响里面的设置,没敢动。

 嘻哈标明 回复于:2005-03-11 14:08:02
运行到./configure --with-apxs2=/usr/sbin/apxs --with-jni --with-apr-lib=/usr/lib 时为何出configure: error: Invalid location for apxs: '/usr/sbin/apxs'
呢?

 wolfg 回复于:2005-03-11 15:28:42
[quote:3ca1f3fecf="嘻哈标明"]运行到./configure --with-apxs2=/usr/sbin/apxs --with-jni --with-apr-lib=/usr/lib 时为何出configure: error: Invalid location for apxs: '/usr/sbin/apxs'
呢?[/quote:3ca1f3fecf]你的apxs不在/usr/sbin/下吧

 wolfg 回复于:2005-03-11 15:29:50
[b:8891894ec0]JK2 is officially unsupported![/b:8891894ec0]

http://jakarta.apache.org/tomcat/connectors-doc/

JK2 has been put in maintainer mode and no further development will take place. The reason for shutting down JK2 development was the lack of developers interest. Other reason was lack of users interest in adopting JK2, caused by configuration complexity when compared to JK.

JK2 will have it's successor within core Apache2.1/2.2 distribution. We have developed new proxy_ajp that is an addition to the mod_proxy and uses Tomcat's AJP protocol stack. It is developped in httpd-2.1 and integrated in it. We have also developed a new proxy_balancer module for load balancing http and ajp protocol stacks.

 嘻哈标明 回复于:2005-03-11 20:26:58
[quote:48570fad0a="wolfg"]愕腶pxs不在/usr/sbin/下吧[/quote:48570fad0a]

不 好意思,写错了,现在我改为 ./configure --with-apxs2=/usr/java/httpd2/bin/apxs --with-java-home=/usr/java/j2sdk1.4.2_07
还是出错啊。。。如下:

checking for mkdir... /bin/mkdir
no apxs given
need to check for Perl first, apxs depends on it...
checking for perl... /usr/bin/perl
configure: error: can't locate libapr
[root@localhost native2]#

 嘻哈标明 回复于:2005-03-14 23:57:57
上面这步已经自己解决,找不到LIBAPE。在本站查了相关文章得知需安装libapr和libaprutil。但已经安装了又出了个问题,我完成根据楼上所说的做,到修改server/apache2/Makefile 后 mark就出现了下面的错,/usr/bin/ld: cannot find -ldb-4.1
collect2: ld returned 1 exit status
make[1]: *** [../../../build/jk2/apache2/libjkjni.la] 错误 1
make[1]: Leaving directory `/root/www/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/server/apache2'
make: *** [jk2-build] 错误 1
[root@localhost native2]#
。。。。应该又少了ldb,这个是啥 文件,在哪下载呢?

 嘻哈标明 回复于:2005-03-15 01:16:23
ldb-4.1,,,我改成了4.2就可以过了。 http://1.2.3.4/jsp-examples/
  http://1.2.3.4/status/ 也都能访问。只不过不配置还不好。现在比如说http://localhost/jsp-examples/index.jsp能正常访问,但http://localhost/jsp-examples/index.htm不能访问。我还在找原因。

 挡泥板 回复于:2005-03-15 10:49:46
我的老是不成功,提示我:configure: error: Apache 1.3 requires apr to built from source, use --with-apr and --with-apr-util

 vulcan 回复于:2005-03-15 14:54:57
我在运行到connector 的make这步时有如下的错误libtool: link: `../../../build/jk2/apache2/jk_channel_apr_socket.lo' is not a valid libtool object
make[1]: *** [../../../build/jk2/apache2/mod_jk2.la] Error 1
make[1]: Leaving directory `/usr/local/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/server/apache2'
make: *** [jk2-build] Error 1
哪错了 啊?

 vulcan 回复于:2005-03-15 15:09:56
我在做到vi makefile 之后的make那步出现了下面的问题libtool: link: `../../../build/jk2/apache2/jk_channel_apr_socket.lo' is not a valid libtool object
make[1]: *** [../../../build/jk2/apache2/mod_jk2.la] Error 1
make[1]: Leaving directory `/usr/local/jakarta-tomcat-connectors-jk2-2.0.4-src/jk/native2/server/apache2'
make: *** [jk2-build] Error 1
为什么?

 嘻哈标明 回复于:2005-03-15 16:35:04
我现在重新安装了FC3了出错也和楼上的一样。希望高手出手帮助。谢谢

 vulcan 回复于:2005-03-15 20:56:29
把以前的安装删掉重来好像就行了,我想可能的原应是我前面几步没有完全按照文档来。

 嘻哈标明 回复于:2005-03-15 21:37:25
我是照抄了(当然有些路径是要改的),系统都重新安装了N次,我都有些担心硬盘会受不了呢?

 li2002 回复于:2005-04-19 16:55:46
出现问题!!
我是按照楼主的步骤做的。做
http://xxx/status/
有正常信息
在做
http://xxx/jsp-examples/

http://xxx/jsp-examples/index.jsp
都出错(503错)
Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.
请问是什么没做???
我的jk2-connect没改make也正常的。

 li2002 回复于:2005-04-19 17:21:55
知道了,原来tomcat有个默认端口8080被我系统用作代理端口了,把它改成其他的就行了。
终于看到了成功的画面了。哈哈~~~~

 yxg0512 回复于:2005-04-20 14:24:53
no apxs given
need to check for Perl first, apxs depends on it...
checking for perl... /usr/bin/perl
building connector for "apache-2.0"
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
checking for JDK location (please wait)... checking Try to guess JDK location... configure: error: can't locate a valid JDK location

 yxg0512 回复于:2005-04-25 13:37:59
[quote:fca61c5c92="li2002"]知道了,原来tomcat有个默认端口8080被我系统用作代理端口了,把它改成其他的就行了。
终于看到了成功的画面了。哈哈~~~~[/quote:fca61c5c92]

兄弟 在哪里改的?  我也出现跟你同样的情况了   :(

 er 回复于:2005-04-27 18:46:27
整了一天没成功,搜到这段话,真是晕
[quote:11fc65fa1c]在整合的过程中要注意的是,由于apache、mod_jk2均依赖于apr,所以三者的版本要注意匹配,不要一味求新,不然很容易出现“undefined symbol:apr_socket_send”之类的错误。如果是安装了redhat9和fedora自带的apache,mod_jk2用2.0.2的版本编译就好,用2.0.4的版本编译会有问题。[/quote:11fc65fa1c]

原文转自:http://www.ltesting.net