RedHat Linux 中 Apache HTTP Server 与 Tomcat 集成
程序员文章站
2022-03-11 21:21:05
...
本文主要介绍,通过Apache HTTP Server 访问部署在Tomcat下的应用
RedHat Linux Version:
Linux version 2.6.18-308.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Fri Jan 27 17:17:51 EST 2012
假设:
WEB Server Machine 的 IP 为:192.168.4.242 ( Apache HTTP Server 所在机器 ),Apache版本:2.2.26
APP Server Machine 的 IP 为:192.168.4.234 ( Tomcat 所在机器 ), Tomcat 版本:6
前提:
Apache HTTP Server 在RedHat Linux 已经安装,见另一博客:http://brofe.iteye.com/blog/1989128
JDK 在RedHat Linux 已经安装,见另一博客:http://brofe.iteye.com/blog/1988590
下载JK 模块,因为我使用的集成方式为JK:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/netware/mod_jk-1.2.32-httpd-2.2.21-nw.zip
开始配置Apache HTTP Server
第一步:
将mod_jk-1.2.31-httpd-2.2.x.so 拷贝到Apache安装目录下的:/usr/local/httpd2.2/modules
第二步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 目录中增加:workers.properties 文件
内容为:
Java代码 收藏代码
worker.list=worker1
worker.worker1.port=8009 # 此处的端口为,tomcat/conf/server.xml AJP 端口
worker.worker1.host=192.168.4.234 # 此处IP为:tomcat 所在机器的IP
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
第三步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 目录中增加:workers.conf 文件,内容为:
Java代码 收藏代码
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.xxxx.com
JkMount /* worker1
</VirtualHost>
第四步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 下修改httpd.conf 文件,内容为:
Java代码 收藏代码
# 第56行增加以下三行
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.x.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
# 文件最后增加以下一行,内容为:
include /usr/local/httpd2.2/conf/workers.conf
第五步:修改Tomcat/conf/server.xml
Java代码 收藏代码
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<!-- -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<!-- 自定义域名配置 -->
<Host name="www.xxxx.com" appBase="webapps">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="walmartros_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="ros" debug="0" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="walmartros." suffix=".log" timestamp="true"/>
</Context>
</Host>
</Engine>
至此,通过JK方式将Apache与Tomcat集成配置已完成,重启Apache即可
测试:http://192.168.4.242/examples/index.html # 此处IP为Apache所在机器IP
以后为介绍Apache的集群配置
RedHat Linux Version:
Linux version 2.6.18-308.el5 (mockbuild@x86-007.build.bos.redhat.com) (gcc version 4.1.2 20080704 (Red Hat 4.1.2-50)) #1 SMP Fri Jan 27 17:17:51 EST 2012
假设:
WEB Server Machine 的 IP 为:192.168.4.242 ( Apache HTTP Server 所在机器 ),Apache版本:2.2.26
APP Server Machine 的 IP 为:192.168.4.234 ( Tomcat 所在机器 ), Tomcat 版本:6
前提:
Apache HTTP Server 在RedHat Linux 已经安装,见另一博客:http://brofe.iteye.com/blog/1989128
JDK 在RedHat Linux 已经安装,见另一博客:http://brofe.iteye.com/blog/1988590
下载JK 模块,因为我使用的集成方式为JK:http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/netware/mod_jk-1.2.32-httpd-2.2.21-nw.zip
开始配置Apache HTTP Server
第一步:
将mod_jk-1.2.31-httpd-2.2.x.so 拷贝到Apache安装目录下的:/usr/local/httpd2.2/modules
第二步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 目录中增加:workers.properties 文件
内容为:
Java代码 收藏代码
worker.list=worker1
worker.worker1.port=8009 # 此处的端口为,tomcat/conf/server.xml AJP 端口
worker.worker1.host=192.168.4.234 # 此处IP为:tomcat 所在机器的IP
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
第三步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 目录中增加:workers.conf 文件,内容为:
Java代码 收藏代码
NameVirtualHost *:80
<VirtualHost *:80>
ServerName www.xxxx.com
JkMount /* worker1
</VirtualHost>
第四步:
在 Apache安装目录 :/usr/local/httpd2.2/conf 下修改httpd.conf 文件,内容为:
Java代码 收藏代码
# 第56行增加以下三行
LoadModule jk_module modules/mod_jk-1.2.31-httpd-2.2.x.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
# 文件最后增加以下一行,内容为:
include /usr/local/httpd2.2/conf/workers.conf
第五步:修改Tomcat/conf/server.xml
Java代码 收藏代码
<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">
<!--For clustering, please take a look at documentation at:
/docs/cluster-howto.html (simple how to)
/docs/config/cluster.html (reference documentation) -->
<!--
<Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
<!-- Use the LockOutRealm to prevent attempts to guess user passwords
via a brute-force attack -->
<Realm className="org.apache.catalina.realm.LockOutRealm">
<!-- This Realm uses the UserDatabase configured in the global JNDI
resources under the key "UserDatabase". Any edits
that are performed against this UserDatabase are immediately
available for use by the Realm. -->
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm>
<!-- -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true" xmlValidation="false" xmlNamespaceAware="false">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
</Host>
<!-- 自定义域名配置 -->
<Host name="www.xxxx.com" appBase="webapps">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="walmartros_access_log." suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" />
<Context path="" docBase="ros" debug="0" reloadable="true">
<Logger className="org.apache.catalina.logger.FileLogger" prefix="walmartros." suffix=".log" timestamp="true"/>
</Context>
</Host>
</Engine>
至此,通过JK方式将Apache与Tomcat集成配置已完成,重启Apache即可
测试:http://192.168.4.242/examples/index.html # 此处IP为Apache所在机器IP
以后为介绍Apache的集群配置
上一篇: java 算法