JK2模块已经不被官方支持,而且在性能上和现有的jk模块也有差距,所以用JK模块
1
下载modjk的src包,在apache大版本号相同时是向下兼容的。
2
cd native/
./configure --with-apxs=/opt/apache/bin/apxs
make
cp ./apache-2.0/mod_jk.so /opt/apache/modules/
一 一个apache对应一个tomcat
1.编辑 httpd.conf
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile /opt/apache/conf/workers.properties
# 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"
# 指定那些请求交给tomcat处理
JkMount /csol/* worker1
2.新建配置文件 /opt/apache/conf/workers.properties
# Define 1 real worker using ajp13
worker.list=worker1
# Set properties for worker1 (ajp13)
worker.worker1.type=ajp13
worker.worker1.host=192.168.0.35
worker.worker1.port=8009 #此处为tomcat的connect端口,在server.xml文件里定义,默认为8009
worker.worker1.lbfactor=50
worker.worker1.cachesize=10
worker.worker1.cache_timeout=600
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=300
添加jkstatus,监控mod_jk状态
apache的httpd.conf中添加 jkmount /jkstatus status
workers.properties中添加 worker.status.type=status
workers.properties中修改 worker.list=ajp13,status
二 一个apache对应多个tomcat,负载均衡
第一部份:配置负载均衡
1.编辑 httpd.conf
LoadModule jk_module modules/mod_jk.so
#指定 workers.properties文件路径
JkWorkersFile /opt/apache/conf/workers.properties
# 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"
# 指定那些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器
JkMount /csol/* controller
2 新建配置文件 /opt/apache/conf/workers.properties
worker.list = controller #server 列表
#========tomcat1========
worker.tomcat1.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat1.host=192.168.0.153 #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
worker.tomcat1.local_worker=1 #干嘛的?需要么?
worker.tomcat1.cachesize=1000
worker.tomcat1.cache_timeout=600
worker.tomcat1.socket_keepalive=true
worker.tomcat1.reclycle_timeout=300
worker.tomcat1.retries=3
#========tomcat2========
worker.tomcat2.port=8009 #ajp13 端口号,在tomcat下server.xml配置,默认8009
worker.tomcat2.host=192.168.0.35 #tomcat的主机地址,如不为本机,请填写ip地址
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor = 1 #server的加权比重,值越高,分得的请求越多
worker.tomcat2.local_worker=1
worker.tomcat1.cachesize=1000
worker.tomcat1.cache_timeout=600
worker.tomcat1.socket_keepalive=true
worker.tomcat1.reclycle_timeout=300
worker.tomcat1.retries=3
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balance_workers=tomcat1,tomcat2 #指定分担请求的tomcat
worker.controller.sticky_session=1
第二部分,配置集群
只配置负载均衡还不行,还要session复制,也就是说其中任何一个tomcat的添加的session,是要同步复制到其它tomcat, 集群内的tomcat都有相同的session
1. 修改tomcat1, tomcat2的server.xml,将集群部分配置的在注释符删掉。(搜Cluster)
2.增加jvmroute
Tomcat1 的配置:server.xml
Tomcat2 的配置:server.xml
三 也可以配置虚拟机
# First Virtual Host.
#
DocumentRoot /web/host1
ServerName host1.apache.org
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
# Second Virtual Host. Also accessible via HTTPS
#
DocumentRoot /web/host2
ServerName host2.apache.org
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
DocumentRoot /web/host2
ServerName host2.apache.org
SSLEngine On
JkMount /*.jsp ajp13
JkMount /servlet/* ajp13
出现问题时先查看log日志
阅读(2645) | 评论(0) | 转发(0) |