apache+tomcat做会话保持的负载均衡配置

1.环境:
一台服务器装apache,作负载均衡器
地址100.100.11.110
操作系统:windows2003
另外两台服务器装tomcat,作站点1和站点2
地址为:100.100.10.22 100.100.10.23
操作系统:window2003
2.安装软件:
apache_2.2.4
apache-tomcat-6.0.14
mod_jk-apache-2.2.4.so
jdk-1_5_0_06
3.配置:
3.1 apache服务器:
在100.100.11.110上安装jdk,配置环境变量,执行java -version查看是否正常
在100.100.11.110上安装apache
把mod_jk-apache-2.2.4.so拷贝到/modules下
编辑httpd.conf,在最后添加:Include conf/mod_jk.conf
在conf目录下新建一个mod_jk.conf文件,内容如下:
# Load mod_jk module
LoadModule jk_module modules/mod_jk-apache-2.2.4.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 JSPs for context / to worker named loadBalancer
JkMount /*.jsp loadBalancer
在conf目录里新建一个名称为workers.properties的文件,内容如下:
worker.list=loadBalancer,tomcat1,tomcat2
worker.tomcat1.port=8009
worker.tomcat1.host=100.100.10.22
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
#worker.tomcat1.cachesize=60
#worker.tomcat1.cache_timeout=300
worker.tomcat1.socket_keepalive=1
worker.tomcat1.socket_timeout=180
worker.tomcat1.connect_timeout=0
worker.tomcat1.reply_timeout=0
worker.tomcat1.recovery_options=1
worker.tomcat1.retries=1
worker.tomcat2.port=8009
worker.tomcat2.host=100.100.10.23
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
#worker.tomcat2.cachesize=60
#worker.tomcat2.cache_timeout=300
worker.tomcat2.socket_keepalive=1
worker.tomcat2.socket_timeout=180
worker.tomcat2.connect_timeout=0
worker.tomcat2.reply_timeout=0
worker.tomcat2.recovery_options=1
worker.tomcat2.retries=1
worker.loadBalancer.type=lb
worker.loadBalancer.balance_workers=tomcat1,tomcat2
#worker.loadbalancer.method=Session
worker.loadBalancer.sticky_session=1
#worker.loadBalancer.sticky_session_force=1
3.2 配置tomcat服务器:
在两台服务器上安装jdk,设置环境变量,测试
在两台服务器上安装tomcat
编辑server.xml
在其中一台上作如下更改:
用<Engine jvmRoute="tomcat1" name="Catalina" defaultHost="localhost" debug="0"> 
替换<Engine name="Catalina" defaultHost="localhost">
在另一台上用tomcat2
4.增加测试程序:
在tomcat1的\webapps\ROOT里增加index.jsp
内容为:
<html>
<body bgcolor=red>
<center>
<h1>Tomcat 1</h1>
</body>
</html>
在tomcat2的\webapps\ROOT里增加index.jsp
<html>
<body bgcolor=blue>
<center>
<h1>Tomcat 2</h1>
</body>
</html>
5.测试:
启动100.100.11.110上的apache
启动两台tomcat
在一台测试机器上测试 http://100.100.11.110/index.jsp ,频繁刷新,一直显示tomcat1,
在另一台测试机器上输入 http://100.100.11.110/index.jsp ,频繁刷新,一直显示tomcat2
测试说明负载均衡和根据原ip的session保持生效。

你可能感兴趣的:(apache,tomcat,jsp,socket,软件测试)