A51 Clustering Smartfox
A51 Clustering Smartfox
Documentation Created by: A51 Integrated 107 atlantic ave. toronto ont. m6k 1y2 canada a51integrated.com 416.703.2300
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Table of Contents 1. Preparing the Hardware 3. Preparing the Software 4. Software Configuration 5. Starting up the Cluster 6. Monitoring the Services 7. FAQ
pg.15 pg.3 pg.4-5
[page 02]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Users
Load Balancer
Fig.1
SFS1 SFS2 SQL Database
TC Active
TC Passive
Terracotta Cluster
Note, that the SQL server is optional, but will be used in our examples to keep the users Buddy List and other variables set across both SFS. Also, The load balancer is used to equally place each new connection across the two SFS. This white-paper will skip the load balancer setup, as any software or hardware load balancer can be used to complete this simple action. By default the load balancer will need to forward connections on ports 9339 and 8080 for Smartfox to establish the socket connection.
[page 03]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Be sure to set a good range of IP addresses for the new servers. For this documentation we will use a internal set of IP's starting with 50. So our cluster IP setup should look something like the following. 192.168.1.50 - Load Balancer 192.168.1.51 - Terracotta Server 1 192.168.1.52 - Terracotta Server 2 192.168.1.53 - Smartfox Server 1 192.168.1.54 - Smartfox Server 1 192.168.1.55 - SQL Server
[page 04]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Finally, be sure to get every machine updated with the latest patches and packages. In this documentation we will be running all of our shell commands as root. If you are not logged in as root be sure you're a sudo user and 'sudo' each of these commands. In CentOS, yum will take care of all of our package management. [root@A51-S01 ~]# yum update yum will then retrieve and install all updated packages for the CentOS install. Finally, there is one extra package we will need on each server and that is 'screen' will get more into screen later, but for now install it with the command: [root@A51-S01 ~]# yum install screen Finally, we will need to configure iptables to allow the machines to talk to each othr. In this documentation we will take the easy route and just disable the iptables service, but in a production environment, it should be setup with a specific set of rules. To shutdown the server and make sure it wont start again on reboot run the following commands: [root@A51-S01 ~]# /etc/init.d/iptables stop && chmod -x /etc/init.d/iptables Once this is done to each machine in the cluster, we are ready to start setting up the specific software on each of them. Depending on how the yum updates went (ie. a new kernel was retrieved - you may want to restart the server. Best practice is to just do this anyways).
Now we will start a new screen session to manage the rest of the server in. [root@A51-S01 ~]# screen -S tc1
*Note: Again I have used tc1 in this command, please reflect the screen name properly for every server you're working on.
Once we have loaded & extracted the files on each server as well as started a screen session we can move on to the next step.
[page 05]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
But before we start up the service - we need to create a config file to let the server know what our intentions are. The easiest way to do this is to create a new file with a text editor I will use nano. [root@A51-S01 ~]# nano tc-config.xml
[page 06]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Inside that file create a XML structure somewhat similar to the following (making changes to the IP addresses that you have used).
<?xml version="1.0" encoding="UTF-8"?> <tc:tc-config xmlns:tc="http://www.terracotta.org/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd"> <servers> <server host="192.168.1.51" name="tc1"> <data>/root/terracotta/tc1-data</data> <logs>/root/terracotta/tc1-logs</logs> <l2-group-port>9530</l2-group-port> </server> <server host="192.168.1.52" name="tc2"> <data>/root/terracotta/tc2-data</data> <logs>/root/terracotta/tc2-logs</logs> <l2-group-port>9530</l2-group-port> </server> <ha> <mode>networked-active-passive</mode> <networked-active-passive> <election-time>5</election-time> </networked-active-passive> </ha> </servers> </tc:tc-config>
Again be sure to reflect the proper IP & Port addresses as well as the log directory you wish to have. Be sure to leave the server name the same as listed above as they will need to be used in some commands in the near future. We can now do the exact same setup to tc2. Be sure to name the screen session properly (ie. screen -S tc2). The XML structure can stay the same on both TC servers because our main concern is what the server name is that we have listed in the XML doc. The fastest way to get the XML document over to tc2 is to probably just SCP it. [root@A51-S01 ~]# scp tc-config.xml 192.168.1.52:~/root/tc1/terracotta-2.5.2/bin/ It's just that easy! For now lets just leave these servers and go on to setup the configuration on the two Smartfox Servers.
[page 07]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Smartfox Server Config The two Smartfox Servers will need to be setup exactly the same (except a couple IP address declarations) so everything I do in the following should be reflected on both sfs1 and sfs2. Start by remoting into the SFS and reattaching the screen if its not already attached. [root@A51-S01 ~]# screen -r sfs1 Next, move yourself into the SFS application directory: [root@A51-S01 ~]# cd /root/sfs1/Server && ll There is a couple config variables we will need to change in the following source. The first one being in the 'tc-cluster-lobby.xml' file. Open the file in a editor, again I will use nano: [root@A51-S01 ~]# nano tc-cluster-lobby.xml You will see a file similar to the following - the only change needed for now is to point the IP address to the IP of your ACTIVE Terracotta server.
<?xml version="1.0" encoding="UTF-8"?> <!-All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved. --> <tc:tc-config xmlns:tc="http://www.terracotta.org/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-4.xsd"> <!-- Server is colocated with client and DSO is listening on default port (9510). --> <servers> <server host="192.168.1.51" name="tc1" /> <update-check> <enabled>false</enabled> </update-check> </servers> <!-- Tell DSO where to put the generated client logs. See the Terracotta Configuration Guide and Reference for additional information. --> <clients> <logs>%(user.home)/terracotta/client-logs/pojo/cluster-lobby/%D</logs> </clients> <application> .... the file goes on....
line to reflect the proper IP address. Our second config change is with the XML config document for Smartfox itself. The best way to do this is to either start from scratch with the 'config_template.xml' file or use your own current SFS config file that you already have running from a previous server. That's it, Smartfox should be ready for you to start it up. But don't start it up yet - that's the next step!
[page 08]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
If you get an error please read the FAQ. Once the server is ready for work we can go ahead close the screen session (it will allow the application to continue to run without us being logged in). To close the screen session hit CTRL+A and then D. Now we can connect to tc2 and run the same command just substituting the -n tc1 for -n tc2. It would look something like this: [root@A51-S01 ~]# ./start-tc-server.sh -f tc-config.xml -n tc2
[page 09]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Running that command should give an output something close to the following:
2008-08-21 05:20:11,204 INFO - Terracotta 2.5.2, as of 20080218-120204 (Revision 7031 by cruise@rh4mo0 from 2.5) 2008-08-21 05:20:12,001 INFO - Configuration loaded from the file at '/root/tc2/terracotta-2.5.2/bin/tcconfig.xml'. 2008-08-21 05:20:12,065 INFO - Log file: '/root/terracotta/tc2-logs/terracotta-server.log'. 2008-08-21 05:20:12,799 INFO - JMX Server started. Available at URL[service:jmx:jmxmp://0.0.0.0:9520] Aug 21, 2008 5:20:13 AM org.apache.catalina.tribes.transport.ReceiverBase bind INFO: Receiver Server Socket bound to:/0.0.0.0:9530 2008-08-21 05:20:13,996 INFO - NodeID[tcp://192.168.1.51:9530] joined the cluster Aug 21, 2008 5:20:14 AM org.apache.catalina.tribes.io.BufferPool getBufferPool INFO: Created a buffer pool with max size:104857600 bytes of type:org.apache.catalina.tribes.io.BufferPool15Impl 2008-08-21 05:20:14,450 INFO - Moved to State[ PASSIVE-UNINITIALIZED ] 2008-08-21 05:20:14,527 INFO - Moved to State[ PASSIVE-STANDBY ]
Note the last line of output stating that the state is moved to '[ PASSIVE-STANDBY ]'. This is exactly what we want to see, as it shows that tc2 saw tc1 running and automatically placed itself in PASSIVE mode. We can now move forward and get Smartfox up and running and talking to our new Terracotta cluster. Getting Smartfox up and running should be even easier than getting the Terracotta service started. Connect to sfs1 and sfs2 and reattach the screen sessions. To get SFS running, we just need to run the start script with the SFS config XML document that we have created supplied. [root@A51-S01 ~]# ./start-cluster.sh our_config.xml The startup script will run and if everything starts up right - the final line of output should look something like the following: 05:24:43.671 - [ INFO ] > Server is up and running! If you get an error please read the FAQ. Everything should be up and running now!
[page 10]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Fig.2
[page 11]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
Enter the IP address of your active Terracotta server and try connecting to it. Your application should now look something like the following (Fig.3). If you get an error please read the FAQ.
Fig.3
Notice that the 'Cluster Members' panel has two items in it. They should be our tc1 and tc2. tc1 should have a green square next to it show that is in ACTIVE mode and tc2 should be blue for PASSIVE mode. (Fig.4)
Fig.4
[page 12]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
The second thing we should notice is that the 'Clients' label under our tc1 DSO should have (2) beside it showing that both Smartfox Servers are connected. (Fig.5)
Fig.5
We can also check on our Smartfox servers in a similar fashion. Download and run the Smartfox AdminTool supplied by the Smartfox website. Enter the admin credentials set in your Smartfox config.xml file. (Fig.6)
Fig.6
[page 13]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
After logging in we should see a screen with the basic stats of our Smartfox Server. (Fig.7)
Fig.7
From here we can update many features of the Smartfox Server. Like always, if you get an error please read the FAQ.
[page 14]
Documentation Created by: A51 Integrated - 107 atlantic ave. toronto ont. m6k 1y2 canada - a51integrated.com - 416.703.2300
[page 15]