CentOS下httpd與tomcat整合

主要步驟:css

1.   安裝JDK

2.   安裝httpd

3. 安裝 tomcat (十分簡單)

  看我發表的上一篇html

 

 

4.  採用mod_jk方式整合httpd 和tomcatjava

4.1安裝httpd-devel  apache

安裝成功後,會有/usr/bin/apxs服務,mod_jk的編譯依賴於apxsvim

# yum install httpd-devel

4.2 安裝mod_jktomcat

apache 網下載 官 tomcat-connectors-1.2.39-src.tar.gzruby

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

安裝tomcat-connectors (mod_jk)app

# tar -xzvftomcat-connectors-1.2.39-src.tar.gz
# mv tomcat-connectors-1.2.39-src  /opt/mod_jk
# cd /opt/mod_jk/native
# ./configure --with-apxs=/usr/bin/apxs --with-java-home=/opt/java
# make
# make install

注意,若是Make的時候
 出現這個-bash: make: command not found提示,是由於安裝系統的時候使用的是最小化mini安裝,系統沒有安裝make、vim等經常使用命令,直接yum安裝下便可;
 #yum -y install gcc automake autoconf libtool make 

複製mod_jk.so

#cp /opt/mod_jk/native/apache-2.0/mod_jk.so /usr/lib64/httpd/modules/

4.3修改httpd的配置socket

4.3.1 建立workers.properties

vim  /etc/httpd/conf/workers.properties

添加如下內容:

# Defining a workernamed worker1 and of type ajp13 worker.list=worker1 # Set properties forworker1 worker.worker1.type=ajp13 worker.worker1.host=localhost worker.worker1.port=8009 worker.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 logs
JkLogFile/etc/httpd/logs/mod_jk.log
# Set the jk log level[debug/error/info] JkLogLevel info # Select the log format JkLogStampFormat"[%a %b %d %H:%M:%S %Y]" # JkOptions indicate tosend SSL KEY SIZE, JkOptions +ForwardKeySize +ForwardURICompat-ForwardDirectories # JkRequestLogFormat setthe request format JkRequestLogFormat"%w %V %T" # 將全部servlet 和jsp請求經過ajp13的協議送給Tomcat,讓Tomcat來處理 JkMount /servlet/* worker1 JkMount /*.jsp worker1

4.3.3 修改httpd.conf 

vim httpd.conf 修改如下內容

ServerName修改成:ServerName 10.11.18.45:80 DirectoryIndex 行添加 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.so Include/etc/httpd/conf/mod_jk.conf

4.3.4 修改tomcat的配置

vim $TOMCAT_HOME/conf/server.xml

將 <Server …>部分 修改成
<Host name="localhost" appBase="/var/wwwroot" unpackWARs="true"autoDeploy="true">

4.3.5  重啓httpd 和 tomcat

 

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="<%=basePath%>"> <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="styles.css"> --> </head> <body> Hello, I am mango_song ,this is my JSPpage. <br> </body> </html>

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

相關文章
相關標籤/搜索