作者:姚星火 个人主页:http://fantasyplace.googlepages.com/index.html
Setting up a Tomcat Web Cluster
在每一台机器上安装Terracotta
生成boot jar
可能需要生成Boot jar。脚本文件: make-boot-jar.sh [-o /usr/local/terracotta-2.4.0/lib/dso-boot] -f /tmp/tc-config.xml
启动Terracotta Server
准备配置文件/tmp/tc-config.xml:
<tc:tc-config xsi:schemalocation="&lt;a goog_ds_charindex=" href="http://www.terracotta.org/schema/terracotta-4.xsd">http://www.terracotta.org/schema/terracotta-4.xsd" xmlns:tc=" http://www.terracotta.org/config" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance">
<servers></servers>
<server host="%i" name="sample"></server>
<data></data>data/server-data
<logs></logs>logs/server-logs
<clients></clients>
<logs></logs>logs/client-logs/%(webserver.log.name)
<modules></modules>
<module name="clustered-apache-struts-1.1" version="1.1.0"></module>
<application></application>
<dso></dso>
<instrumented-classes></instrumented-classes>
<include></include>
<class-expression></class-expression>*..*
<exclude></exclude>org.apache.coyote..*
<exclude></exclude>org.apache.catalina..*
<exclude></exclude>org.apache.jasper..*
<exclude></exclude>org.apache.tomcat..*
<web-applications></web-applications>
<web-application></web-application> Cart
</tc:tc-config>
<root></root>
<field-name></field-name>demo.townsend.service.ProductCatalog.catalog
<root-name></root-name>ProductCatalog
<logs></logs>logs/client-logs/%(webserver.log.name)
<modules></modules>
<module name="clustered-apache-struts-1.1" version="1.1.0"></module>
<module name="clustered-websphere-6.1.0.7" version="1.0.0"></module>
<exclude></exclude>org.eclipse..*
<exclude></exclude>com.ddtek..*
<exclude></exclude>tcl.lang..*
<exclude></exclude>org.omg..*
<exclude></exclude>sunlabs.brazil..*
<exclude></exclude>com.sun.mail..*
<exclude></exclude>com.rsa..*
...
[orion@tcserver ~]$ [1] 13545 [orion@tcserver ~]$ 2007-06-07 18:25:57,850 INFO - Terracotta version 2.3.0, as of 20070427-110443 (Revision 2739 by cruise@rh4mo0 from 2.3) 2007-06-07 18:25:59,875 INFO - Configuration loaded from the file at '/home/orion/tc-config.xml'. 2007-06-07 18:26:00,387 INFO - Log file: '/home/orion/logs/server-logs/terracotta-server.log'. 2007-06-07 18:26:01,962 INFO - JMX Server started. Authentication OFF - Available at URL[service:jmx:rmi:///jndi/rmi://localhost:9520/jmxrmi] 2007-06-07 18:26:03,706 INFO - Terracotta Server has started up as ACTIVE node on port 9510 successfully, and is now ready for work. [orion@tcserver ~]$
启动Tomcat Servers
TC_CONFIG_PATH="${TERRACOTTA_SERVER}:9510"
$CATALINA_HOME/bin/startup.sh
或者如下设置JAVA_OPTS环境变量,启动
[orion@domU-12-31-35-00-31-63 ~]$ . set-tc-env.sh [orion@domU-12-31-35-00-31-63 ~]$ echo $JAVA_OPTS -Xbootclasspath/p:/home/orion/terracotta/lib/dso-boot/dso-boot-hotspot_linux_150_12.jar -Dtc.install-root=/home/orion/terracotta -Dtc.config=tcserver:9510 [orion@domU-12-31-35-00-31-63 ~]$ tomcat/bin/catalina.sh start Using CATALINA_BASE: /home/orion/tomcat Using CATALINA_HOME: /home/orion/tomcat Using CATALINA_TMPDIR: /home/orion/tomcat/temp Using JRE_HOME: /home/orion/java [orion@domU-12-31-35-00-31-63 ~]$
在catalina.out log文件中应该要看到类似的信息,如下,说明TOMCAT启动时,Terracotta起作用;在Terracotta Server端如果打开/usr/local/terracotta-2.4.0/bin/admin.sh(AdminConsole)也会显示有App Server连上的信息:
2007-06-07 18:29:23,208 INFO - Terracotta version 2.3.0, as of 20070427-110443 (Revision 2739 by cruise @rh4mo0 from 2.3) 2007-06-07 18:29:24,451 INFO - Configuration loaded from the server at 'tcserver:9510'.
Configure and Start the Load Balancer (实际用IBM EDGE)
In a production environment, you should use a production quality hardware or software load balancer. For testing purposes, Terracotta comes with a simple TCP proxy that may be used like a load balancer. You should not use this TCP proxy in a production environment.
Here's a sample script to start the TCP proxy:
TC_INSTALL_DIR= exec "${JAVA_HOME}/bin/java" \ -Dtc.install-root="${TC_INSTALL_DIR}" -Ddaemon=true \ ${JAVA_OPTS} \\ -cp "${TC_INSTALL_DIR}/lib/tc.jar" \ com.tc.net.proxy.TCPProxy <port to="" listen=""></port> <web host=""></web>:<port></port>,<web host=""></web>:<port></port>,<web host=""></web>:<port></port>
Here's a version of the script with the terracotta installation directory and the web hosts filled in:
[orion@loadbalancer ~]$ cat bin/start-loadbalancer.sh TC_INSTALL_DIR=/home/orion/terracotta exec "${JAVA_HOME}/bin/java" \ -Dtc.install-root="${TC_INSTALL_DIR}" -Ddaemon=true \ ${JAVA_OPTS} \ -cp "${TC_INSTALL_DIR}/lib/tc.jar" \ com.tc.net.proxy.TCPProxy 8080 web01:8080,web02:8080,web03:8080
To run the TCP proxy, execute the script on the load balancer machine:
[orion@loadbalancer ~]$ bin/start-loadbalancer.sh Thu Jun 07 18:56:02 EDT 2007: Starting listener on port 8080, proxying to [web01/10.255.54.145:8080], [web02/10.255.54.97:8080], [web03/10.255.54.146:8080] with 0ms delay