java tomcat 负载均衡_Tomcat 负载均衡

Step 1 Download 3 software

1, Apache2.0.xx

2,Tomcat5.5.1x

3,mod_jk, it is connector of  tomcat

Step 2 Install Apache2.0 at d:\Apache2, start service, then browse http://localhost for testing, you can see welcome page of apache.

Step 3 Install 2 Tomcats at d:\tomcat1 and d:\tomcat2, set JAVA_HOME, PATH, start tomcat service, then browse http://localhost:8080 for test, you can see welcome page of tomcat.

Step 4 Config apache:

Copy mod_jk.so to d:\apache2\modules.

Add “include D:\Apache2\conf\mod_jk.conf” in the end of d:\apache2\conf\httpd.conf

Add a new file: d:\Apache2\conf\mod_jk.conf, the content is as following:

# Load mod_jk module

LoadModule jk_module modules/mod_jk.so

# Where to find workers.properties

JkWorkersFile conf/workers.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"

# Send servlet for context /examples to worker named ajp13

#JkMount /servlet/* ajp13

# Send JSPs for context /examples to worker named ajp13

JkMount /*.jsp loadbalancer

JkMount /*.htm loadbalancer

Add a new file d:\Apache2\conf\ workers.properties, the content is as following:

#

# 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

#

Step 5 Config Tomcat

Modify conf/server.xml file

1 Add a unique jvmRoute to the Catalina engine

Near line 100, replace:

with:

For tomcat2, put jvmRoute="tomcat2".

2 Change the control port

At line 13, replace:

with:

For the tomcat2 server, replace port 8005 with 12005. This will prevent the two servers from conflicting.

3 Change the AJP13 port

At line 75, in the AJP 13 connector definition, replace:

port="8009"

with:

port="11009"

For the tomcat2 server, replace port 8009 with 12009.

4 Disable the standalone HTTP port

We don't want or need our tomcat servers to directly respond to HTTP requests. So we comment out the HttpConnector section between lines and 58 in the server.xml file.

Example:

NOTE: If you don't comment this out, you will need to change the port numbers so they don't conflict between tomcat instances.

Step 6 Test

1 Create a file named index.jsp and put it in the /usr/local/tomcat1/webapps/ROOT directory:

Tomcat 1

2 Create a file named index.jsp and put it in the /usr/local/tomcat2/webapps/ROOT directory:

Tomcat 2

3 Browse http://localhost/index.jsp

posted on 2006-12-12 18:14 MingIsMe 阅读(71) 评论(0)  编辑  收藏 所属分类: 06 J2EE

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
概念: AJP是Apache提供的完成与其它服务器通讯的一种协议。在Apache中通过mod_proxy_ajp模块发送AJP数据,另外一端的服务器需要实现AJP协议,能够接受mod_proxy_ajp模块发送的AJP协议数据,在接受到AJP协议数据后做适当处理,并能够将处理结果以AJP协议方式发送回给mod_proxy_ajp模块。 配置过程: 1 安装apache 2 测试apache是否安装成功:http://localhost 出现It works! 3 解压、安装tocmat 4 测试tocmat是否安装成功:http://localhost:8080 5 配置tocmat的jdk: 打开startup.bat添加: rem ----------------------------------------------------JDK目录 SET JAVA_HOME=D:\progam\jdk160_05 rem ----------------------------------------------------解压后Tomcat的目录 6 复制tocmat,名字为tomcat2 7 apache 整合tomcat 1)modules目录下添加模块:jk mod_jk-1.2.26-httpd-2.2.4.so 2)修改conf/httpd.conf 最后一行添加: include conf/mod_jk.conf 3)在conf目录下创建mok_jk.conf 内容: #加载mod_jk Module LoadModule jk_module modules/mod_jk-1.2.26-httpd-2.2.4.so #指定 workers.properties文件路径 JkWorkersFile conf/workers.properties #指定哪些请求交给tomcat处理,"controller"为在workers.propertise里指定的负载分配控制器名 JkMount /*.jsp controller 4)在confi目录下创建workers.properties 内容为: worker.list = controller,tomcat1,tomcat2 #========tomcat1======== worker.tomcat1.port=8009 worker.tomcat1.host=192.168.9.210 worker.tomcat1.type=ajp13 worker.tomcat1.lbfactor = 1 #加权因子 越大执行的请求越多 #========tomcat2======== worker.tomcat2.port=9009 worker.tomcat2.host=192.168.9.210 worker.tomcat2.type=ajp13 worker.tomcat2.lbfactor = 1 #========controller,负载均衡控制器======== worker.controller.type=lb worker.controller.balanced_workers=tomcat1,tomcat2 worker.controller.sticky_session=1 5 修改tomcat的端口号(3处) <Server port="8005" shutdown="SHUTDOWN"> 改为: <Server port="9005" shutdown="SHUTDOWN"> <Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/> 改为: <Connector port="9090" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443"/> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443"/> 改为: <Connector port="9009" protocol="AJP/1.3" redirectPort="8443"/> 注意:该处需要与worker.tomcat2.port=9009对应 6 修改jvmRoute 备注与worker.list = controller,tomcat1,tomcat2的tomcat1或tocmat2对应 <Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值