首页 > 代码库 > Centos6 httpd与tomcat整合发布

Centos6 httpd与tomcat整合发布

有时候需要在Web入口地址中隐藏非80端口,而最常见的方案是整合httpd和tomcat ,下面是通过mod_jk实现httpd和tomcat整合的详细流程,希望对大家有所帮助。

OS: CentOS5.7 X64

 主要步骤:

1.   安装JDK

 略

2.   安装httpd

yum install httpd/etc/init.d/httpd start

http://localhost 看到欢迎界面

3. 安装 tomcat (十分简单)

  3.1官网下载apache-tomcat-7.0.42.tar.gz ,解压缩

tar –xzvf apache-tomcat-7.0.42.tar.gz  mv apache-tomcat-7.0.42/opt/tomcat7

  3.2vim ~/bash_profile  添加:

export TOMCAT_HOME=/opt/tomcat7
  3.3开启tomcat服务
$TOMCAT_HOME/bin/startup.sh

 3.4 http://localhost:8080 看到欢迎界面

4.  采用mod_jk方式整合httpd 和tomcat

4.1安装httpd-devel  

安装成功后,会有/usr/sbin/apxs服务,mod_jk的编译依赖于apxs

yum install httpd-devel

4.2 安装mod_jk

apache 网下载 官 tomcat-connectors-1.2.37-src.tar.gz

http://tomcat.apache.org/download-connectors.cgi

安装tomcat-connectors (mod_jk)

tar -xzvftomcat-connectors-1.2.37-src.tar.gzmv tomcat-connectors-1.2.37-src  /opt/mod_jkcd /opt/mod_jk/native./configure--with-apxs=/usr/sbin/apxs --with-java-home=/opt/javaMakeMake install
复制mod_jk.so
cp/opt/mod_jk/native/apache-2.0/mod_jk.so /usr/lib64/httpd/modules/

4.3修改httpd的配置

4.3.1 创建workers.properties

vim  /etc/httpd/conf/workers.properties 添加以下内容:

# Defining a workernamed worker1 and of type ajp13worker.list=worker1# Set properties forworker1worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009worker.worker1.lbfactor=50 worker.worker1.cachesize=10 worker.worker1.cache_timeout=600 worker.worker1.socket_keepalive=1 worker.worker1.socket_timeout=300

4.3.2 创建 mod_jk.conf

vim  /etc/httpd/conf/mod_jk.conf 添加以下内容:

JkWorkersFile /etc/httpd/conf/workers.properties# Where to put jk logsJkLogFile/etc/httpd/logs/mod_jk.log# Set the jk log level[debug/error/info]JkLogLevel info# Select the log formatJkLogStampFormat"[%a %b %d %H:%M:%S %Y]"# JkOptions indicate tosend SSL KEY SIZE,JkOptions  +ForwardKeySize +ForwardURICompat-ForwardDirectories# JkRequestLogFormat setthe request formatJkRequestLogFormat"%w %V %T"# 将所有servlet 和jsp请求通过ajp13的协议送给Tomcat,让Tomcat来处理JkMount /servlet/*  worker1JkMount /*.jsp worker1
4.3.3 修改httpd.conf

vim httpd.conf 修改以下内容

ServerName修改为:ServerName 10.11.18.45:80DirectoryIndex 行添加 index.jsp index.htm

添加以下内容,其中”/var/wwwroot”是你要发布的Web项目所在的父目录

DocumentRoot"/var/wwwroot"<Directory"/var/wwwroot">    Options Includes FollowSymLinks    AllowOverride None    Order deny,allow    Allow from all    XBitHack on</Directory><Directory"/var/wwwroot/WEB-INF">    Order deny,allow    Deny from all</Directory>

以下内容:添加

LoadModule jk_module/usr/lib64/httpd/modules/mod_jk.soInclude/etc/httpd/conf/mod_jk.conf
4.3.4 修改tomcat的配置

vim $TOMCAT_HOME/conf/server.xml

<Server …>部分 修改为<Hostname="localhost" appBase="/var/wwwroot"            unpackWARs="true"autoDeploy="true">

4.3.5  restart httpd 和 tomcat

/etc/init.d/httpd restart$TOMCAT_HOME/bin/shutdown.sh$TOMCAT_HOME/bin/startup.sh
4.3.6 测试

在/var/wwwroot 目录下新建目录myproject,m yproject下新建index.jsp

<%@ page language="java" import="java.util.*"pageEncoding="ISO-8859-1"%><%String path = request.getContextPath();String basePath =request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN"><html>  <head>    <basehref="http://www.mamicode.com/">    <title>My JSP ‘index.jsp‘ startingpage</title>        <meta http-equiv="pragma"content="no-cache">        <metahttp-equiv="cache-control" content="no-cache">        <meta http-equiv="expires"content="0">           <metahttp-equiv="keywords" content="keyword1,keyword2,keyword3">        <metahttp-equiv="description" content="This is my page">        <!--        <link rel="stylesheet"type="text/css" href="http://www.mamicode.com/styles.css">        -->  </head>  <body>    Hello, I am mango_song ,this is my JSPpage. <br>  </body></html>

http://localhost/myproject 看到相应界面,至此httpd tomcat已经整合成功