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文件:
<Engine name="Catalina" defaultHost="192.168.0.2" jvmRoute="tomcat1">
<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">
<Context path="/mip" docBase="E:\quanyou\web\WebRoot2" debug="0" reloadable="false">
</Context>
</Host>
</Engine>
打完收工.Ok.配置經過
複製session,在應用程序的web.xml裏添加<distributable/>
如今出現的問題:兩臺Tomcat之間常常會出現session丟失的問題,好比A,B。用戶登陸後(進入的A),而後點擊連接,有時候會轉發到B,可是Session沒有複製B,這樣系統會提示B沒有登陸。