tomcat负载均衡配置:
1:安装apache和tomcat
2:修改apache下的http.conf,
修改监听端口:Listen 8080
把mod_jk-1.2.28-httpd-2.2.3.so拷贝到apache下的modules目录下.
在http.conf加入:LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so
然后再http.conf最后加入:
JkWorkersFile conf/workers.properties
JkMountFile conf/uriworkermap.properties
JkLogFile logs/mod_jk.log
JkLogLevel warn
3:在conf目录下新建:uriworkermap.properties和workers.properties
1):uriworkermap目录下的内容为:
/*=controller
/jkstatus=status
2):workers.properties内容为:
worker.list=controller
#========tomcat1========
worker.tomcat1.port=8019 #tomcat1的ajp端口
worker.tomcat1.host=192.168.0.2
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=500
#worker.tomcat1.stopped=1
#========tomcat2========
worker.tomcat2.port=8029 #tomcat2的ajp端口
worker.tomcat2.host=192.168.0.2
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=500
#worker.tomcat2.stopped=1
#========controller,负载均衡控制器========
worker.controller.type=lb
worker.controller.balanced_workers=tomcat1,tomcat2
worker.controller.sticky_session=1
worker.status.type=status
4:修改tomcat下的server.xml文件:
<Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
<Host name="192.168.0.2" appBase="webapps"
unpackWARs="true" autoDeploy="true"
xmlValidation="false" xmlNamespaceAware="false">
打完收工.Ok.配置通过
复制session,在应用程序的web.xml里添加
现在出现的问题:两台Tomcat之间经常会出现session丢失的问题,比如A,B。用户登录后(进入的A),然后点击链接,有时候会转发到B,但是Session没有复制B,这样系统会提示B没有登录。