Terracotta and Tomcat Clustering - Page 3

Ok, our tutorial will end by adding Apache web server to load balance the traffic between both Tomcats.

install Apache Web Server 
just run the msi installer or install it from an RPM or from the OS repositories, i will refer to the installation directory as ${APACHE_HOME}. 
 
point your browser to  localhost and make sure you are welcomed with the most famous message

IT WORKS!

 
install mod_jk
extract the file  tomcat-connectors-x.x.xx-windows-arch-httpd-2.2.x.zip, copy mod_jk.so to ${APACHE_HOME}\modules
 

Configure Apache Web Server

 
httpd.conf
edit the file ${APACHE_HOME}\conf\httpd.conf to add the following settings: 
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkShmFile logs/mod_jk.shm
JkLogFile logs/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkMount /examples loadbalancer
JkMount /examples/* loadbalancer
JkMount /status status
JkMount /status/* status

here we are loading the mod_jk module, the mod_jk will load cluster members (Tomcats) from a file named workers.properties under ${APACHE_HOME}\conf directory.
also, any requests coming to apache at /examples will be forwarded to one of our Tomcats.
while /status will direct us to the mod_jk control panel.


workers.properties
create a new file under the directory ${APACHE_HOME}\conf named workers.properties with the following content: 
# Define list of workers that will be used
worker.list=loadbalancer,status
# Define tomcat1
worker.tomcat1.port=8009
worker.tomcat1.host=127.0.0.1
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
# Define tomcat2
worker.tomcat2.port=8010
worker.tomcat2.host=127.0.0.1
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
# Load-balancing behaviour
worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=0
# Status worker for managing load balancer
worker.status.type=status

note that the worker names must match the jvmRoute configurations on the Tomcats. also, you can enable sticky sessions or disable to fit your need, however, i have turned it off here. 

restart apache web server, if everything went as it should, navigating to http://localhost/examples would result in this page. 
 
if you have debugging installed on your browser, like firebug, you can check your JSESSIONID value, you will find it post fixed with the jvmRoute value of the tomcat server who served the response.
if you hit the refresh button you can see that you are moving for every hit from one Tomcat to the other.
 
Testing Sessions Failover
point your browser to http://localhost/examples/servlets/servlet/SessionExample add a couple of values in the session.
 
now it is up to you, bring any Tomcat down (not both, of course) or any Terracotta (not both, of course), play around, your minimal setup is one Tomcat and  one Terracotta server.
your values in the session should never disappear!!!
 
Have Fun.

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值