Tomcat5.5.12配置负载均衡 发表人:fsz521job

来源:互联网 发布:索尼a6000和佳能m3知乎 编辑:程序博客网 时间:2024/06/15 07:16

Tomcat5.5.12配置负载均衡

参考:http://raibledesigns.com/tomcat/


1:安装准备

下载Tomcat5.5.12.zip;apache_2.0.55-win32-x86-no_ssl;mod_jk.dll;

2:解压缩Tomcat5.5.12.zip设置环境变量(JAVA_HOME=C:Program FilesJavajdk1.5.0_02),安装apache_2.0.55-win32-x86-no_ssl(安装时需要填写本机的计算机名!!)

3:把mod_jk.dll COPY到..Apache2modules下,在..Apache2conf下建新文件workers.properties,文件内容:

#
# workers.properties
#

# In Unix, we use forward slashes:
ps=/

# list the workers by name

worker.list=tomcat1, tomcat2, loadbalancer

# ------------------------
# First tomcat server
# ------------------------
worker.tomcat1.port=11009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13

# Specify the size of the open connection cache.
#worker.tomcat1.cachesize

#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
worker.tomcat1.lbfactor=100


# ------------------------
# Second tomcat server
# ------------------------
worker.tomcat2.port=12009
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13

# Specify the size of the open connection cache.
#worker.tomcat2.cachesize

#
# Specifies the load balance factor when used with
# a load balancing worker.
# Note:
# ----> lbfactor must be > 0
# ----> Low lbfactor means less work done by the worker.
worker.tomcat2.lbfactor=100


# ------------------------
# Load Balancer worker
# ------------------------

#
# The loadbalancer (type lb) worker performs weighted round-robin
# load balancing with sticky sessions.
# Note:
# ----> If a worker dies, the load balancer will check its state
# once in a while. Until then all work is redirected to peer
# worker.
worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcat1, tomcat2

#
# END workers.properties
#

4:设置confhttpd.config文件

在# Example:
# LoadModule foo_module modules/mod_foo.so
#下添加
LoadModule jk_module modules/mod_jk.dll

#
# Configure mod_jk
#
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info

在DocumentRoot "C:/Program Files/Apache Group/Apache2/htdocs"下添加:

JkMount /*.jsp loadbalancer
JkMount /* loadbalancer
JkMount /servlet/* loadbalancer

5:配置tomcat的server.xml文件

(1)把<Server port="8005" shutdown="SHUTDOWN">改成
tomcat1:<Server port="11005" shutdown="SHUTDOWN">
tomcat2:<Server port="12005" shutdown="SHUTDOWN">

(2)把<Connector port="8080" maxHttpHeaderSize="8192"
tomcat1:<Connector port="11080" maxHttpHeaderSize="8192"
tomcat2:<Connector port="12080" maxHttpHeaderSize="8192"

(3)把<Connector port="8009" 改成
tomcat1: <Connector port="11009"
tomcat2: <Connector port="12009"

(4)把<Engine name="Catalina" defaultHost="localhost">改成
<Engine jvmRoute="tomcat1" name="Catalina" defaultHost="localhost" debug="0">
<Engine jvmRoute="tomcat2" name="Catalina" defaultHost="localhost" debug="0">

(5)去掉注释
<Cluster className="org.apache.catalina.cluster.tcp.SimpleTcpCluster"
……………………
<Receiver
className="org.apache.catalina.cluster.tcp.ReplicationListener"
tcpListenAddress="auto"
tomcat1: tcpListenPort="4001"
tomcat2: tcpListenPort="4002"
tcpSelectorTimeout="100"
tcpThreadCount="6"/>
……………………
</Cluster> 

原创粉丝点击