原文来自西部数码帮助中心:http://www.west.cn/faq/list.asp?unid=863
接下来将说明如何将Apache与Tomcat整合:
其实也就是理解起来也简单,Apache也就是通过 mod_jk模块利用AJP协议与Tomcat进行通信,在Tomcat的配置文件server.xml 中有这样的代码,这个就是与mod_jk通信的端口。
mod_jk模板可以官方下载源文件再进行编译即可,如
wget -c "http://download.west263.net/tools/jsp/tomcat-connectors-1.2.30-src.tar.gz" tar xzvf tomcat-connectors-1.2.30-src.tar.gz cd tomcat-connectors-1.2.30-src/native ./configure -with-apxs=/usr/sbin/apxs make&&make install
以上需要注意的时需要先安装httpd 和 httpd-devel在上面编译时需要。
再将mod_jk加载到APACHE里面
LoadModule jk_module modules/mod_jk.so
JkWorkersFile /etc/httpd/conf.d/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel error
再编写mod_jk的配置文件workers.properties 如
worker.list=test
worker.test.type=ajp13
worker.test.host=localhost
worker.test.port=9003
再编写APACHE文件
<VirtualHost *:80>
ServerName www.test.cn "www.test.cn
DocumentRoot /home/wzmjsp/wwwroot
JkMountFile /home/tomcat7/vhost/test/uriworkermap.properties
DirectoryIndex index.jsp
</VirtualHost>
注意上面的 JkMountFile 文件路径,这个也是 mod_jk的一部份
里面是设置需要提交给TOMCAT处理的文件类型 如
/*=test
这里的test与 workers.properties里面的test是同一帐号、*表示所有,也可以 /*.jsp=test
以下是写的一键安装脚本,自动整合并自动部署TOMCAT和JDK
http://download.west263.net/tools/jsp/apach+tomcat.sh 在CentOS6.0及以上版本中测试无误。
添加站点的脚本
http://download.west263.net/tools/jsp/createjspweb.sh 这个只是编写了添加站点功能,若需要其它功能可自行修改脚本。
修改脚本后,wdcp兼容tomcat
http://www.gotoip.top/download/tomcat+wdcp+apache.sh 这个是兼容西部数码预装wdcp环境一件脚本。
修订版脚本
#!/bin/bash ############################################################ # $Name: tomcat+wdcp+apache.sh # $Version: v1.2 # $Function: 基于wdcp一键部署Apache.Tomcat整合环境 # $Author: 琴子小白 # $organization: west.cn # $Create Date: 2017-4-2 # $Description: 1、基于wdcp自动部署Tomcat环境 # 2、纯净版环境一键搭建Apache.Tomcat整合环境 # 3、$Mod_jk_URL:apache的apxs路径 $Vhost_URL :apache的虚拟主机配置文件路径 $Httpd_URL : apache的配置文件路径 $Tomcat_URL: tomcat的安装文件路径 $Java_URL : java的配置文件路径 ############################################################# Tomcat_URL="/home" Java_URL="/home" isapache="yes" Mod_jk_URL="/usr/sbin/apxs" Vhost_URL="/home/wddata/vhost" Httpd_URL="/www/wdlinux/apache/conf" #设置tomcat和java安装路径 Set_Tom_Jdk() { read -p '设置tomcat和java安装路径(默认都在/home)' isset; if [ "$isset" = "" ];then read -p '请输入您Tomcat的程序安装路径' Tomcat_URL; read -p '请输入您Java的程序安装路径' Java_URL; fi } #纯净版安装apache yum安装 Install_YumApache() { Install_Main yum -y install httpd httpd-devel wget gcc make rpm -ivh http://repo.webtatic.com/yum/centos/5/`uname -i`/webtatic-release-5-0.noarch.rpm yum -y install --enablerepo=webtatic httpd-itk service httpd stop mv /usr/sbin/httpd /usr/sbin/httpd.old mv /usr/sbin/httpd.itk /usr/sbin/httpd } #安装tomcat Install_Tomcat() { wget -c "http://download.west263.net/tools/jsp/tomcat-7.0.11.tar.gz" tar xzvf tomcat-7.0.11.tar.gz mv tomcat-7.0.11 $Tomcat_URL/tomcat7 } #安装java Install_Java() { wget -c "http://download.west263.net/tools/jsp/jdk7.tar.gz" tar xzvf jdk7.tar.gz mv jdk1.7.0/ /home/java7 chown -R root.root $Java_URL/java7 } #安装Mod_jk Install_Mod_jk() { wget -c "http://download.west263.net/tools/jsp/tomcat-connectors-1.2.30-src.tar.gz" tar xzvf tomcat-connectors-1.2.30-src.tar.gz cd tomcat-connectors-1.2.30-src/native ./configure -with-apxs=$Mod_jk_URL make&&make install } #添加环境变量 Source_profile() { echo "export JAVA_HOME=$Java_URL" >> /etc/profile #java echo "export ANDROID_JAVA_HOME=$JAVA_HOME" >> /etc/profile echo "export JRE_HOME=$Java_URL/jre" >> /etc/profile echo "export CLASSPATH=$Java_URL/lib" >> /etc/profile echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile echo "export TOMCAT_HOME=$Tomcat_URL/tomcat7/" >> /etc/profile #tomcat source /etc/profile } #生成load_jk.conf Touch_load_jk_conf() { touch $Vhost_URL/workers.properties echo "LoadModule jk_module modules/mod_jk.so" > $Vhost_URL/load_jk.conf echo "JkWorkersFile /home/wddata/vhost/workers.properties" >> $Vhost_URL/load_jk.conf echo "JkLogFile logs/mod_jk.log" >> $Vhost_URL/load_jk.conf echo "JkLogLevel error" >> $Vhost_URL/load_jk.conf echo "JkRequestLogFormat \"%w %V %T %U %q\"" >> $Vhost_URL/load_jk.conf groupadd clients sed -i "s/\#NameVirtualHost \*\:80/NameVirtualHost \*\:80/g" $Httpd_URL/httpd.conf } Install_Main() { Set_Tom_Jdk cp -rpfu /bin/bash /bin/bash_tomcat_jsp_use chmod 700 /bin/bash echo '/bin/bash_tomcat_jsp_use' >>/etc/shells cd /root/ if [ "$isapache" = "no" ];then Install_YumApache fi Install_Tomcat Install_Java Source_profile Touch_load_jk_conf groupadd clients echo "安装完成" exit 1 } echo '==============================================' echo '请选择当前服务器环境' echo '1) wdcp环境' echo '2) 纯净版环境' echo '3) 其他环境' read -p '请选择您的服务器环境 (1-3 default: 1): ' isUrl; case "${isUrl}" in '1') Mod_jk_URL="/www/wdlinux/apache/bin/apxs" Install_Main ;; '2') isapache="no" Vhost_URL="/etc/httpd/conf.d" Httpd_URL="/etc/httpd/conf" Install_Main ;; '3') read -p '请输入您的站点配置路径: (ps:apache站点配置路径:/etc/httpd/conf.d)' Vhost_URL; read -p '请输入您的站点配置路径: (ps:apache安装路径路径:/etc/httpd/conf)' Httpd_URL; Install_Main ;; *) Mod_jk_URL="/www/wdlinux/apache/bin/apxs" Install_Main ;; esac