Apache,Tomcat的集成和负载均衡
一、Apache的安装
1、下载Apache:http://httpd.apache.org/最新的Apache Web Server
2、安装Apache Web Server:根据安装向导安装Apache Web Server
3、我的安装目录是E:/Apache2
二、安装两个Tomcat Server
1、 参考JSP开发之二中的Tomcat的安装和配置
2、 检查两个Tomcat是安装成功我的安装分别是E:/tomcat1;E:/tomcat2
三、Apache和Tomcat的集成
1、 下载和安装Tomcat Connector
下载后修改文件名
mod_jk.so并复制到E:/Apache2/modules目录
2、 打开E:/Apache2/conf目录中的httpd.conf文件,并在文件最后加下如下的一段文字
LoadModule jk2_module modules/mod_jk2.so
3、 在E:/Apache2/conf目录下建立workers2.properties文件,文件的内容如下
#******************************************************
[logger.apache2]
level=DEBUG
[config]
file=E:/Apache2/conf/workers2.properties
[shm]
file=E:/Apache2/logs/jk2.shm
size=1048576
[channel.socket:tomcat1]
port=8009
host=127.0.0.1
[ajp13:tomcat1]
channel=channel.socket:tomcat1
tomcatId=tomcat1
routeRedirect=tomcat1
# Load Balance
[lb:lb1]
worker=ajp13:tomcat1
[uri:/*.jsp]
group=lb:lb1
group=lb:lb1
[uri:/*.jsp.]
group=lb:lb1
[uri:/*.jsp ]
group=lb:lb1
如图
4、 打开E:/tomcat1下的conf目录,并在目录打开或创建jk2.properties文件。
文件内容如下:
## THIS FILE MAY BE OVERRIDEN AT RUNTIME. MAKE SURE TOMCAT IS STOPED
## WHEN YOU EDIT THE FILE.
## COMMENTS WILL BE _LOST_
## DOCUMENTATION OF THE FORMAT IN JkMain javadoc.
# Set the desired handler list
# handler.list=apr,request,channelJni
#
# Override the default port for the socketChannel
# channelSocket.port=8019
# Default:
# channelUnix.file=${jkHome}/work/jk2.socket
# Just to check if the the config is working
# shm.file=${jkHome}/work/jk2.shm
# In order to enable jni use any channelJni directive
# channelJni.disabled = 0
# And one of the following directives:
# apr.jniModeSo=/opt/apache2/modules/mod_jk2.so
# If set to inprocess the mod_jk2 will Register natives itself
# This will enable the starting of the Tomcat from mod_jk2
# apr.jniModeSo=inprocess
handler.list=apr,request,channelJni
channelSocket.port=8009
shm.file=d:/sunpro/Apache2/logs/jk2.shm
apr.jniModeSo=d:/sunpro/apache2/modules/mod_jk2.so
5、 打开E:/tomcat1下的conf目录下的server.xml文件,去掉会没用的。
加入如下的几行
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" maxThreads="50" minSpareThreads="20" maxSpareThreads="35" enableLookups="false"
redirectPort="8443" acceptCount="100" connectionTimeout="20000" disableUploadTimeout="true"
URIEncoding="gb2312" protocol="AJP/1.3" />
如图:
6、 重新起动tomat1和apache。就用可通过apache来访问jsp和servlet了
四、Apache和Tomcat的集成和负载均衡