设为首页 收藏本站
查看: 524|回复: 0

[经验分享] Apache与Tomcat平台全面解决方案

[复制链接]

尚未签到

发表于 2017-1-5 07:09:22 | 显示全部楼层 |阅读模式
WEB 服务器解决方案

Apache+Tomcat

                                                                    作者:张浦
                                                                    2007-4-26
 

 
1.   概述
1.1.   本文目的
1.2.   环境及文档约定
2.   JDK安装配置
2.1.   安装JDK
2.2.   设置系统JAVA环境
3.   TOMCAT安装配置
3.1.   获取Tomcat
3.2.   安装Tomcat
3.2.1.   安装
3.2.2.   验证安装
3.2.3.   常见问题
3.3.   配置与优化
3.4.   APR整合
4.   APACHE安装配置
4.1.   获取Apache软件
4.2.   Apache安装配置与优化
5.   APACHE+TOMCA整合配置
5.1.   获取JK软件
5.2.   安装编译JK
5.3.   配置JK连接APACHE和TOMCAT
5.4.   验证配置
6.   完整的配置参考
6.1.   环境变量
6.2.   Tomcat相关配置文件
6.3.   apache相关配置文件
<!--[if !supportLists]--> 1. <!--[endif]--> 概述
<!--[if !supportLists]--> 1.1. <!--[endif]--> 本文目的
描述建立简单高效的 apache 服务器,应用于集成 tomcat 服务。
即: apache+jk1.2+tomcat 部署方案中 apache 的安装配置和优化
<!--[if !supportLists]--> 1.2. <!--[endif]--> 环境及文档约定
操作系统: RedHat AS 4 update 1
硬件环境:普通 PC C4-2.8G/1G 内存
设系统的 IP 地址为: $IP
<!--[if !supportLists]--> 2. <!--[endif]--> JDK 安装配置
JDK 官方网站: http://java.sun.com
<!--[if !supportLists]--> 2.1. <!--[endif]--> 安装 JDK
JDK 版本: jdk1.5.0_05
 
下载地址:
http://192.18.108.219/ECom/EComTicketServlet/BEGIN5EA4351D3E051D464E9716D18FE4FF31
/-2147483648/2093779515/1/798890/798650/2093779515/2ts+/westCoastFSEND
/jdk-1.5.0_11-oth-JPR/jdk-1.5.0_11-oth-JPR:3/jdk-1_5_0_11-linux-i586-rpm.bin
 
# cd /tools
# wget http://192.18.108.219/ECom/EComTicketServlet/BEGIN5EA4351D3E051D464E9716D18FE4FF31/
-2147483648/2093779515/1/798890/798650/2093779515/2ts+/westCoastFSEND
/jdk-1.5.0_11-oth-JPR/jdk-1.5.0_11-oth-JPR:3/jdk-1_5_0_11-linux-i586-rpm.bin
 
# cd /tools
# chmod +x jdk-1_5_0_11-linux-i586-rpm.bin
# ./ jdk-1_5_0_11-linux-i586-rpm.bin
# rpm –ivq jdk-1_5_0_11-linux-i586.rpm
 
<!--[if !supportLists]--> 2.2. <!--[endif]--> 设置系统 JAVA 环境
Java 环境的设置是为了支持 tomcat 服务器的运行,主要需要设置的环境变量是 JAVA_HOME, 即 jdk 的安装路径。默认安装 jdk 的目录是 /usr/java/ jdk1.5.0_11
 
设置环境变量到系统环境配置文件 /etc/profile
 
# vi /etc/profile
加入: exprot JAVA_HOME=/usr/java/ jdk1.5.0_11
# source /etc/profile
 
<!--[if !supportLists]--> 3. <!--[endif]--> TOMCAT 安装配置
Tomcat 官方网站: http://tomcat.apache.org/
<!--[if !supportLists]--> 3.1. <!--[endif]--> 获取 Tomcat
本文使用 Tomcat-5.5.17
下载地址: http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.17/bin/apache-tomcat-5.5.17.tar.gz
如果目标服务器可以上公网,可以直接在目标服务器下载该版本 tomcat ,标准发行版本比较小,只有几兆而已。
 
$ cd /tools
$ wget http://archive.apache.org/dist/tomcat/tomcat-5/v5.5.17/bin/apache-tomcat-5.5.17.tar.gz
 
<!--[if !supportLists]--> 3.2. <!--[endif]--> 安装 Tomcat
<!--[if !supportLists]--> 3.2.1. <!--[endif]--> 安装
首先在获取 tomcat 软件版本后,直接解压,并拷贝到对应的安装目录就可以了,一般 linux 下安装目录可以设置在 /usr/local 下面,现在设 Tomcat 安装目录为 $CATALINA_HOME 。
 
# cd /tools
# tar –xzvf apache-tomcat-5.5.17.tar.gz
# cp apache-tomcat-5.5.17 /usr/local/tomcat-5.5.17
即: $CATALINA_HOME=/usr/local/tomcat-5.5.17
 
<!--[if !supportLists]--> 3.2.2. <!--[endif]--> 验证安装
请确保系统的 8080 端口没有被占用,因为 tomcat 默认使用 8080 端口。
# $CATALINA_HOME/bin/startup.sh
 
启动浏览器(如 IE ),输入 http://$IP:8080
如果显示了有 tomcat 图标的 tomcat 首页的话,表示 tomcat 服务器正常 .
 
<!--[if !supportLists]--> 3.2.3. <!--[endif]--> 常见问题
<!--[if !supportLists]--> 1.         <!--[endif]--> 确保服务器操作系统防火墙关闭
<!--[if !supportLists]--> 2.         <!--[endif]--> 确保端口没有被其他程序占用,验证方法是 :
关闭 tomcat 服务器( $CATALINA_HOME/bin/shutdown.sh )
telnet $IP 8080
如果仍然能连通,说明 8080 端口已经被其他程序使用。
<!--[if !supportLists]--> 3.3. <!--[endif]--> 配置与优化
我的其他文章参考: TOMCAT-5.5.X优化配置
 
<!--[if !supportLists]--> 3.4. <!--[endif]--> APR 整合
我的其他文章参考: TOMCAT-5.5.X整合APR

 
<!--[if !supportLists]--> 4. <!--[endif]--> APACHE 安装配置
<!--[if !supportLists]--> 4.1. <!--[endif]--> 获取 Apache 软件
Apache2.0.59 : http://httpd.apache.org
 
本例使用 linux source 包版本
可以直接下载:
# cd /tools
# wget http://httpd.apache.org/xxxx/xxxx/ apache-2.0.59.tar.gz
<!--[if !supportLists]--> 4.2. <!--[endif]--> Apache 安装配置与优化
我的其他文章参考: Apache安装配置与优化
<!--[if !supportLists]--> 5. <!--[endif]--> APACHE+TOMCA 整合配置
官方参考: http://tomcat.apache.org/connectors-doc/webserver_howto/apache.html
<!--[if !supportLists]--> 5.1. <!--[endif]--> 获取 JK 软件
下载地址:
http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/v1.2.0/src/
jakarta-tomcat-connectors-jk-1.2.0-src.tar.gz
# cd /tools
# wget http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/v1.2.0/src/
jakarta-tomcat-connectors-jk-1.2.0-src.tar.gz
<!--[if !supportLists]--> 5.2. <!--[endif]--> 安装编译 JK
# cd /tools
# tar –xzvf jakarta-tomcat-connectors-jk-1.2.0-src.tar.gz
# cd tomcat-connectors-1.2.20-src
# cd native
# ./configure --with-apxs=$APACHE_HOME/bin/apxs  // 使用 apache 的 apxs
# make
# make install
 
成功安装完成后,会在 $APACHE_HOME/modules 中发现 mod_jk.so 文件。
<!--[if !supportLists]--> 5.3. <!--[endif]--> 配置 JK 连接 APACHE 和 TOMCAT
<!--[if !supportLists]--> 1.  <!--[endif]--> 配置 worker.properties
在 $APACHE_HOME/conf 下建立 worker.properties
# vi worker.properties
写入:
       # Define 1 real worker using ajp13
worker.list=tomcat
# Set properties for worker1 (ajp13)
worker.tomcat.type=ajp13
worker.tomcat.host=127.0.0.1
worker.tomcat.port=8009
worker.tomcat.cachesize=10
worker.tomcat.cache_timeout=600
    
<!--[if !supportLists]--> 2.  <!--[endif]--> 配置 JK 连接
配置 $APACHE_HOME/conf 下 httpd.con 文件
# vi httpd.conf
写入:
# Load mod_jk module
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile /usr/local/apache2.0.59/conf/workers.properties
# Where to put jk logs
JkLogFile /usr/local/apache2.0.59/logs/mod_jk.log
# Set the jk log level [debug/error/info]
JkLogLevel error
# Select the log format
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
# JkOptions indicate to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkShmFile /usr/local/apache2/logs/mod_jk.shm
 
# Send jsp,servlet for context * to worker named tomcat
JkMount /dwr/* tomcat
JkMount /*.jsp tomcat
JkMount /*.mvc tomcat
JkMount /*.do tomcat
JkMount /captcha.jpg tomcat
JkMount /j_acegi_security_check tomcat
JkMount /j_acegi_logout tomcat
JkMount /admin/adminlogout tomcat
JkMount /WEB-INF/* tomcat
 
<!--[if !supportLists]--> 5.4. <!--[endif]--> 验证配置
确保 tomcat 配置正确,并能正常启动。
启动 tomcat ,然后启动 apache ,测试是否配置成功。
      
 
<!--[if !supportLists]--> 6. <!--[endif]--> 完整的配置参考
<!--[if !supportLists]--> 6.1. <!--[endif]--> 环境变量
<!---->export JAVA_HOME =/ usr / java / jdk1 . 5 . 0_05

export PATH
= $JAVA_HOME / bin : $PATH

export JAVA_OPTS
= " $CATALINA_OPTS -Xms700m -Xmx700m
-Djava.library.path=/usr/local/apr/lib
"
<!--[if !supportLists]--> 6.2. <!--[endif]--> Tomcat 相关配置文件
Server.xml :
<!---->< Server  port ="8005"  shutdown ="SHUTDOWN" >

  
< GlobalNamingResources >

    
<!--  Used by Manager webapp  -->

    
< Resource  name ="UserDatabase"  auth ="Container"

              type
="org.apache.catalina.UserDatabase"

       description
="User database that can be updated and saved"

           factory
="org.apache.catalina.users.MemoryUserDatabaseFactory"

          pathname
="conf/tomcat-users.xml"   />

  
</ GlobalNamingResources >

  
< Service  name ="Catalina" >

    
< Connector  port ="8009"

               maxTreads
="500"  minSpareThreads ="10"  maxSpareThreads ="50"

               acceptCount
="50"  connectionTimeout ="60000"

               enableLookups
="false"  redirectPort ="8443"  protocol ="AJP/1.3" />

    
< Engine  name ="Catalina"  defaultHost ="localhost" >

      
< Realm  className ="org.apache.catalina.realm.UserDatabaseRealm"

             resourceName
="UserDatabase"   />

      
< Host  name ="localhost"  appBase =""

       unpackWARs
="true"  autoDeploy ="true"

       xmlValidation
="false"  xmlNamespaceAware ="false" >

        
< Context  path =""  docBase ="/www/xxxxx/site/web"  reloadable ="true"  debug ="0" />

      
</ Host >

    
</ Engine >

  
</ Service >

</ Server >
<!--[if !supportLists]--> 6.3. <!--[endif]--> apache 相关配置文件
<!--[if !supportLists]--> 1. <!--[endif]--> httpd.conf
<!---->Include conf/includes/*.conf

ServerRoot /usr/local/apache2.0.59

DocumentRoot /www/xxxxx/site/web

DirectoryIndex index.jsp index.htm index.html

User  webuser

Group cvs

< IfModule  prefork.c >

ServerLimit      800

MaxClients       800

StartServers     5

MinSpareServers  5

MaxSpareServers 10

</ IfModule >

 

< IfModule  worker.c >

StartServers         2

MaxClients         150

MinSpareThreads     25

MaxSpareThreads     75

ThreadsPerChild     25

MaxRequestsPerChild  0

</ IfModule >

 

MaxRequestsPerChild 0

ErrorLog logs/error_log

< Directory  />

    Options FollowSymLinks

    AllowOverride None

</ Directory >
 
<!--[if !supportLists]--> 2. <!--[endif]--> conf/includes/deflate.conf
<!---->AddOutputFilterByType DEFLATE text/html text/plain text/xml text/javascript text/css

# Compress everything except images

< Location  />

# Insert filter

SetOutputFilter DEFLATE

# Netscape 4.x has some problemshttp://wangdei.iteye.com/Images/dot.gif

BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems

BrowserMatch ^Mozilla/4\.0[678] no-gzip


# MSIE masquerades as Netscape, but it is fine

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don't compress images

SetEnvIfNoCase Request_URI \

\.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don't deliver the wrong content

Header append Vary User-Agent env=!dont-vary

</ Location >

<!--[if !supportLists]--> 3. <!--[endif]--> conf/includes/ mod_jk.conf
<!---->#  Load mod_jk module

LoadModule jk_module modules
/ mod_jk . so

#  Where to find workers.properties

JkWorkersFile 
/ usr / local / apache2 . 0.59 / conf / workers . properties

#  Where to put jk logs

JkLogFile 
/ usr / local / apache2 . 0.59 / logs / mod_jk . log

#  Set the jk log level [debug/error/info]

JkLogLevel error

#  Select the log format

JkLogStampFormat 
" [%a %b %d %H:%M:%S %Y]  "

#  JkOptions indicate to send SSL KEY SIZE,

JkOptions 
+ ForwardKeySize  + ForwardURICompat  - ForwardDirectories

#  JkRequestLogFormat set the request format

JkRequestLogFormat 
" %w %V %T "

JkShmFile 
/ usr / local / apache2 / logs / mod_jk . shm

 

#  Send jsp,servlet for context * to worker named tomcat

JkMount 
/ dwr /*  tomcat

JkMount 
/*. jsp tomcat

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-323911-1-1.html 上篇帖子: (转)Apache Http Server 日志分割 下篇帖子: 【维护】apache 配置和日志+shell
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表