0

CentOS5.3下Apache+tomcat+jk整合

已有 180 阅读此文人 - - Linux,系统管理 -

CentOS5.3下Apache+tomcat+jk整合

系统环境:
CentOS5.3
httpd-2.2.11
apache-tomcat-6.0.18.t
tomcat-connectors-1.2.28
jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin
一、安装系统必须的包

#yum -y install ntp vim-enhanced gcc gcc-c++ gcc-g77 flex bison autoconf automake glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel libtool* zlib-devel libxml2-devel libjpeg-devel libpng-devel libtiff-devel fontconfig-devel freetype-devel libXpm-devel gettext-devel curl curl-devel pam-devel e2fsprogs-devel krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers

二、下载需要的软件:
#vi wget.txt

http://apache.mirror.phpchina.com/httpd/httpd-2.2.11.tar.gz
http://www.java.net/download/jdk6/6u10/promoted/b28/binaries/jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin
http://apache.mirror.phpchina.com/tomcat/tomcat-6/v6.0.18/bin/apache-tomcat-6.0.18.tar.gz
http://labs.xiaonei.com/apache-mirror/tomcat/tomcat-connectors/jk/source/jk-1.2.28/tomcat-connectors-1.2.28-src.tar.gz

#wget -i wget.txt
三、安装apache
#vi init.sh

./configure \
        "--prefix=/usr/local/apache2" \
        "--with-included-apr" \
        "--enable-so" \
        "--enable-deflate=shared" \
        "--enable-expires=shared" \
        "--enable-rewrite=shared" \
        "--enable-static-support" \
        "--disable-userdir"
make
make install
echo '/usr/local/apache2/bin/httpd -k start ' >> /etc/rc.local

四、安装jdk
#chmod u+x jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin
#./jdk-6u10-rc-bin-b28-linux-i586-21_jul_2008-rpm.bin
一路回车安装就会自动安装好
五、安装tomcat
#tar zvxf apache-tomcat-6.0.18.tar.gz
#mv apache-tomcat-6.0.18 tomcat
六、安装jk
#tar zvxf tomcat-connectors-1.2.28-src.tar.gz
#cd tomcat-connectors-1.2.28-src/native/
#./configure --with-apxs=/usr/local/apache2/bin/apxs && make && make install
到apache的modules下面看看有没有mod_jk.so模块
七、配置apache支持jk模块
#vi /usr/local/apache2/conf/httpd.conf

LoadModule    jk_module   modules/mod_jk.so
……
Include conf/extra/mod_jk.conf

#vi /usr/local/apache2/conf/extra/mod_jk.conf

JkWorkersFile conf/extra/workers.properties
JkLogFile  logs/mod_jk.log
JkShmFile  logs/jk-runtime-status
JkLogLevel info
JkLogStampFormat "<%a %b %d %H:%M:%S %Y> "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
#Sample JkMounts.  Replace these with the paths you would
#like to mount from your JSP server.
#syntax: JkMount ${URL_DIR}/*.jsp worker_name
JkMount  /images/avatar/*    worker1
JkMount  /*.jsp worker1
JkMount /*.page worker1
JkMount /*.cic worker1
JkMount /func/* worker1
JkMount  /assets/*         worker1
JkMount  /remote/*         worker1
JkMount  /services/*       worker1
JkMount  /homebase/*       worker1
JkMount /skin/*     worker1
JkMount /error/*    worker1
JkMount /lib/*      worker1
JkMount /protected/*      worker1
JkMount /rounded/*      worker1
JkMount /FormOverLogin*      worker1
JkMount /fckeditor/editor/filemanager/connectors/*      worker1
JkMount /upload/image/*      worker1

# vi /usr/local/apache2/conf/extra/workers.properties

worker.list=worker1
worker.worker1.port=8009
worker.worker1.host=localhost
worker.worker1.type=ajp13
worker.woker1.lbfactor=1

修改tomcat跟apache知道让web指向同一个目录
#vi /usr/local/tomcat/conf/server.xml

      
      

#vi /usr/local/apache2/conf/httpd.conf

DocumentRoot "/usr/local/apache2/htdocs"

启动测试
#/usr/local/apache2/bin/apachectl start
#sh /usr/local/tomcat/bin/startup.sh
#vi /data/www/wwwroot/index.html

html页面测试

#vi /data/www/wwwroot/index.jsp

<%out.print("jsp页面测试");%>

Html:

Jsp:

遇到问题:
apache不能设置虚拟主机,一设置虚拟主机的话,tomcat就读不了jsp,显示代码,不设置虚拟主机的时候能读,我上面的安装只是修改了http.conf里面的DocumentRoot,期待高手帮我解决这个问题!

期待你一针见血的评论,Come on!

不用想啦,马上 "登录"  发表自已的想法.