设为首页 收藏本站
查看: 664|回复: 0

[经验分享] Terracotta and Tomcat Clustering

[复制链接]

尚未签到

发表于 2017-1-30 12:42:18 | 显示全部楼层 |阅读模式
原网址:http://javadrama.blogspot.com/2012/10/terracotta-and-tomcat-clustering-page-1.html


In this tutorial we will learn a lot of stuff :)


  • How to install Terracotta in an Active/Passive HA (High Availability) model.
  • How to configure Tomcat 6.0 to store/retrieve sessions on Terracotta.
  • How to install and configure Apache Web Server configure it to relay requests to Tomcat.

Why?

i can do session replication using Tomcat built-in clustering module, so why do i use Terracotta?

well, the Tomcat clustering works just perfect with major four concerns:


  • Clients' sessions data are part of the Tomcat JVM instance.
  • There is extra work for Tomcat to make sure that the sessions and its data are replicated among the cluster
  • not suitable for larger cluster because of using multicasting, imagine the network traffic generated by eight tomcat nodes replicating their sessions.
  • You can't store an object which is not serializable.
So, moving this responsibility to Terracotta would help eliminating those four concerns.




Our Final architecture 

http://five.rdaili.com/sohu.com.php?u=2hpDLHla4MzrNVZwR47dqRDhGv36V5Wmh8Je5EqHiNewe0zfjvQHxz8zsk4OabRbRzsKY852vv%2FyEL2aT5PakC0pyawKurGvi2YHIObjHtMlsrs%2FZhkEJV4%3D&b=3

 

 

it is really simple:

 


  • Both Tomcats store/retrieve sessions on the active Terracotta server.
  • Apache web server forwards requests to both Tomcats.
  • If the active Terracotta fails the passive Terracotta will be the active.

Let's Digg in

First things first! we need:


  • terracotta-3.7.0-installer.jar
  • apache-tomcat-6.0.35
  • mod_jk.so
  • httpd-2.2.22
  • JDK 1.6


My five servers built on a single windows 7 box as a POC, you should have no troubles with running the same example on Linux, only minor chages are needed.

Install and Configure Terracotta

open a terminal and change the directory to the place where you downloaded terracotta-3.7.0-installer.jar

java -jar terracotta-3.7.0-installer.jar



you will see a setup wizard, it is straight forward, install Terracotta to the directory of your choice, from now on i will refer to that directory as ${TC_HOME}
now, go to ${TC_HOME} and create a new directory called 'config', this directory will contain our Terracotta configuration file that will set up the Terracotta cluster.
create a new file inside the config directory called tc-config.xml with the following content:



<tc-config xmlns="/config">
<servers secure="false" xmlns:tc="/config" xmlns:con="/config" xmlns="">
<server bind="0.0.0.0" host="127.0.0.1" name="node1">
<data>C:\terracotta\server-data</data>
<logs>C:\terracotta\server-logs</logs>
<statistics>C:\terracotta\server-statistics</statistics>
<dso-port bind="0.0.0.0">9510</dso-port>
<jmx-port bind="0.0.0.0">9520</jmx-port>
<l2-group-port bind="0.0.0.0">9530</l2-group-port>
<data-backup>C:\terracotta\data-backup</data-backup>
<index>C:\terracotta\server-data\index</index>
<dso>
<client-reconnect-window>120</client-reconnect-window>
<persistence>
<mode>temporary-swap-only</mode>
</persistence>
<garbage-collection>
<enabled>true</enabled>
<verbose>false</verbose>
<interval>3600</interval>
</garbage-collection>
</dso>
</server>
<server bind="0.0.0.0" host="127.0.0.1" name="node2">
<data>C:\terracotta\server-data2</data>
<logs>C:\terracotta\server-logs2</logs>
<statistics>C:\terracotta\server-statistics2</statistics>
<dso-port bind="0.0.0.0">9511</dso-port>
<jmx-port bind="0.0.0.0">9521</jmx-port>
<l2-group-port bind="0.0.0.0">9531</l2-group-port>
<data-backup>C:\terracotta\data-backup2</data-backup>
<index>C:\terracotta\server-data\index2</index>
<dso>
<client-reconnect-window>120</client-reconnect-window>
<persistence>
<mode>temporary-swap-only</mode>
</persistence>
<garbage-collection>
<enabled>true</enabled>
<verbose>false</verbose>
<interval>3600</interval>
</garbage-collection>
</dso>
</server>
<mirror-groups>
<mirror-group>
<members>
<member>node1</member>
<member>node2</member>
</members>
</mirror-group>
</mirror-groups>
<ha>
<mode>networked-active-passive</mode>
<networked-active-passive>
<election-time>5</election-time>
</networked-active-passive>
</ha>
<update-check>
<enabled>true</enabled>
<period-days>7</period-days>
</update-check>
</servers>
<system xmlns:tc="/config" xmlns:con="/config" xmlns="">
<configuration-model>production</configuration-model>
</system>
<clients xmlns:tc="/config" xmlns:con="/config" xmlns="">
<logs>%(user.home)/terracotta/client-logs</logs>
<modules>
<module name="terracotta-toolkit-1.6" group-id="org.terracotta.toolkit"/>
</modules>
</clients>
</tc-config>
the important thing to note here is the servers node

 


  • for each Terracotta server that will run in the cluster you need to define a server node.
  • the server tag has three attributes:


  • bind: the default bind address which Terracotta listen to.
  • host: the IP address that will be used to connect to the Terracotta server.
  • name: the name of this node

data: is where this server stores its data (make it unique for each server if you are running the cluster on one box)
logs: is where the server store its logs (make it unique for each server if you are running the cluster on one box)
statistics:  is where the server store its statistics (make it unique for each server if you are running the cluster on one box)
port configurations: JMX, DSO and group ports (make it unique for each server if you are running the cluster on one box)
data-backup: is where the server store its data backups  (make it unique for each server if you are running the cluster on one box)
index: is where the server store its index files  (make it unique for each server if you are running the cluster on one box)
dso: is the Distributed Shared Objects specific options.  we have now defined two servers, we need to define how they would work.


  • mirror-group: a tag to define Terracotta groups 


  • members: a tag to add a server to a group using its name

ha: is a tag to define the High Availability options of the group

  • mode: networked-active-passive it means that the communications between the servers will relay on networking.
  • election-time: the Terracotta server would wait for that time to decide if it should start as an Active or passive.
let's start out cluster an make sure everything is OK.
 




  • open three consoles and navigate to ${TC_HOME}\bin on the three of them
  • Start node1
    start-tc-server.bat -f ..\config\tc-config.xml -n node1

    you should see
    Becoming State[ ACTIVE-COORDINATOR ]
    Terracotta Server instance has started up as ACTIVE node on 0.0.0.0:9510 successfully, and is now ready for work.
  • Start node2
    start-tc-server.bat -f ..\config\tc-config.xml -n node2

    you should see
    NodeID[127.0.0.1:9510] joined the cluster
    Moved to State[ PASSIVE-UNINITIALIZED ]
    Moved to State[ PASSIVE-STANDBY ]
  • on the third console start the Terracotta Development Console
    dev-console.bat

    connect to either 127.0.0.1:9520 or 127.0.0.1:9521, you should see this screen


http://five.rdaili.com/sohu.com.php?u=2hpDKXla4MzrNVZwR47dqRDhGv36V6DHsfwC0BuDutzBe0zfjs1G7mwIkx4OabRbRzsKY852vv%2FiELbWVaDT6zx377AaurGvi2YHAObjDZwsrag%3D&b=3

 

as per the screen shot, node1 is active and node2 is passive, play around by taking node1 down and see if node2 becomes the active and then Vice Versa.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-335342-1-1.html 上篇帖子: 解决tomcat下中文乱码问题【转】 下篇帖子: 配置Eclpise+tomcat并实现JSP的编写与部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表