在 用jk进行整合apache和tomcat时,jk的配置最关键的是三个文件,分别是
1 httpd.conf
apache 服务器的配置文件,用来加载jk模块以及指定jk的配置文件信息的
2 workers.porperties
到tomcat服务器的连接定义文件
3 uriworkermap.properties
URI映射文件,用来指定哪些URL由Tomcat 处理,当然您也可以直接在httpd.conf 中配置这些URI,但是独立这些配置的优点是JK模块定期更新该文件的内容,使得我们修改配置的时候无需重新启动Apache 服务器
1 安装连接器
#tar xvf tomcat-connectors-1.2.28-src.tar.gz
#cd tomcat-connectors-1.2.28-src
#cd native
#./configure --with-apxs=/usr/local/apache/bin/apxs --with-Java-home=/usr/java/
#make && make install
2编辑apache的配置文件
#vim httpd.conf
在其尾部添加
Include conf/mod_jk.conf并保存
3 创建文件mod_jk.conf文件
#vim mod_jk.conf
#Load mod_jk module
LoadModule jk_module modules/mod_jk.so
#Where to find workers.properties
JkWorkersFile conf/workers.properties
#Where to find uriworkermap.preperties
JkMountFile conf/uriworkermap.properties
#Where to put jk logs
JkLogFile 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 to send SSL KEY SIZE,
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
#JkRequestLogFormat set the request format
JkRequestLogFormat "%w %V %T"
JkShmFile logs/mod_jk.shm
HostnameLookups Off
4 创建workers.properties 文件
#vim workers.properties
#list the workers by name
worker.list=loadBalancer,status
#################tomcat1##########
worker.tomcat1.port=8009
worker.tomcat1.host=localhost 注:可以换成IP地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat1.cachesize=100
worker.tomcat1.cache_timeout=600
worker.tomcat1.socket_keepalive=120
worker.tomcat1.socket_timeout=300
worker.tomcat1.connect_timeout=0
worker.tomcat1.reply_timeout=30000
worker.tomcat1.recovery_options=0
worker.tomcat1.retries=1
####################tomcat2#############
worker.tomcat2.port=8009
worker.tomcat2.host=192.168.2.213
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.tomcat2.cachesize=100
worker.tomcat2.cache_timeout=600
worker.tomcat2.socket_keepalive=120
worker.tomcat2.socket_timeout=300
worker.tomcat2.connect_timeout=0
worker.tomcat2.reply_timeout=30000
worker.tomcat2.recovery_options=0
worker.tomcat2.retries=1
############LoadBalancer############
worker.retries=3
worker.loadBalancer.type=lb
worker.loadBalancer.balance_workers=tomcat ,tomcat2
worker.loadBalancer.sticky_session=1
worker.status.type=status
并保存,应为我用的是两台机器,配置tomcat集群,如果是用同一台机器配置tomcat集群的话只需要把端口改为其他端口以防止端口冲突
在最后配置了一个类型为status的worker。这是用来监控JK本身的模块,当然有了这桑worker 还是不够的,还需要告诉JK,其中的哪些worker 是可用的所以就配置了worker.list=loadBalancer,status