其实已经有很多文档了,不过还是老话,给自己备忘,总结些要注意的要点,给一些范例,以后肯定用得着。
以JK作为Apache和Tomcat的连接器,首先配置的是Apache的httpd.conf,主要是加载JK和配置转发规则:
加载和配置JK:
# Load mod_jk module
# Specify the filename of the mod_jk lib
LoadModule jk_module modules/mod_jk.so
# Where to find workers.properties
JkWorkersFile workers2.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 indicates to send SSK KEY SIZE
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
# JkRequestLogFormat
JkRequestLogFormat "%w %V %T"
配置转发规则:
JKMount /* loadbalancer
这个上面的配置差异比较大,简单起见全部转发,可以根据自己的需要修改
然后是定义Workers:
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
#file=anon
file=logs/shm.file
size=1048576
# Defines a load balancer named lb. Use even if you only have one machine.
[lb:lb]
# Example socket channel, override port and host.
[channel.socket:192.168.1.16:8009]
port=8009
host=192.168.1.16
[channel.socket:192.168.1.18:8009]
port=8009
host=192.168.1.18
# Map the Tomcat examples webapp to the Web server uri space
worker.list=loadbalancer
worker.worker1.port=8009
worker.worker1.host=192.168.1.16
worker.worker1.type=ajp13
worker.worker1.lbfactor=1
worker.worker1.cachesize=60
worker.worker1.cache_timeout=300
worker.worker1.socket_keepalive=1
worker.worker1.socket_timeout=180
worker.worker1.connect_timeout=0
worker.worker1.reply_timeout=0
worker.worker1.recovery_options=1
worker.worker1.retries=1
worker.worker2.port=8009
worker.worker2.host=192.168.1.18
worker.worker2.type=ajp13
worker.worker2.lbfactor=1
worker.worker2.cachesize=60
worker.worker2.cache_timeout=300
worker.worker2.socket_keepalive=1
worker.worker2.socket_timeout=180
worker.worker2.connect_timeout=0
worker.worker2.reply_timeout=0
worker.worker2.recovery_options=1
worker.worker2.retries=1
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker1,worker2
worker.loadbalancer.sticky_session=1
[uri:/*]
group=lb
[status:status]
info=Status worker, displays runtime informations
# Status worker for managing load balancer
# worker.status.type=status
[uri:/jkstatus/*]
info=Display status information and checks the config file for changes.
group=status:status
上面的jkstatus的配置是可选的,在开发环境中打开,但是在产品环境中最好关闭。
使用了粘性Session(worker.loadbalancer.sticky_session=1),所以Tomcat的Server.xml中的Engine元素需要添加jvmRoute属性,值就是对应的worker的名字,另外Server.xml中的cluster配置不要打开,否则会进行session的复制。
相关的文章:
http://tomcat.apache.org/connectors-doc/generic_howto/loadbalancers.html
http://tomcat.apache.org/tomcat-5.0-doc/cluster-howto.html
http://blog.csdn.net/ladofwind/archive/2006/08/29/1138484.aspx
http://tomcat.jaxmao.org/cluster-howto.html
http://www.matrix.org.cn/thread.shtml?topicId=39848&forumId=27
2007年9月9日 at 03:58
先记下来,似乎会用得到……