Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

9. Clustering in Tomcat 7 > Vertical clustering in Apache Tomcat 7

Vertical clustering in Apache Tomcat 7

Vertical clustering in Apache Tomcat 7 In the previous topics, we have discussed the different types of cluster architecture, supported by Apache Tomcat 7. It's time to take a real-time challenge to implement clustering. Let's start with vertical clustering. For vertical clustering, we have to configure at least two instances of Apache Tomcat and the complete process consists of three stages. Let's discuss and implement the steps for vertical cluster in Tomcat 7: Installation of the Tomcat instance.Configuration of the cluster.Apache HTTP web server configuration for the vertical cluster. Installation of the Tomcat instance The installation of Apache Tomcat 7 can be done in three easy steps: Download and unzip the software in the required directory.Install the JDK and set the JAVA_HOME.Copy the Apache Tomcat source code in two different directories, for example, /opt/tomcatX (where X= instance number) and verify that the files are properly copied on both instances, using the following command: [root@localhost opt]# ls -l apache-tomcat* The following screenshot shows the output of the previous command: Configuration of a vertical cluster This section is the most critical section for vertical clustering, as all the configurations are done in this section and a simple error can make the cluster non-functioning. So, be careful while carrying out the configuration. Let's do the step-by-step configuration on each node. Configuration of instance 1 For the first instance; node 1, we can use the default configuration, such as Connector, AJP, or shutdown port in server.xml. Let's discuss each component where the configuration needs to be done and why it is used: Shutdown port: The following screenshot shows the configuration for the shutdown port for the Tomcat instance. While running multiple instances, if by any chance, you have skipped configuring the shutdown port, then the Tomcat instance will be unable to start it. Connector port: The following screenshot shows the Connector port configuration for Tomcat 7. This port is used to access the Tomcat instance, for example, normally we access the Tomcat instance by using http://localhost:8080, the 8080 port is called the Connector port. While running multiple instances, if you have skipped configuring this port, then the Tomcat instance will be unable to start it and you will get the Port already in use exception. AJP port: The following screenshot shows the AJP port configuration for Tomcat 7. This port is used for AJP communication between the Apache HTTP server and the Tomcat instance. While running multiple instances, if you have skipped to configuring port, then the Tomcat instance will be unable to start it and you will get the Port already in use exception. Cluster attributes: Enable the cluster attributes for clustering in server.xml and the following screenshot shows the cluster class used for clustering: Configuration test: Run the configtest.sh script from TOMCAT_HOME/bin to check the configuration. The following screenshot shows the output for the following config.sh command: [root@localhost bin]# ./configtest.sh Tomcat instance startup: Start the instance 1 configuration using the script startup.sh. The following screenshot shows the output for the following startup.sh script: [root@localhost bin]# ./startup.sh Check the Tomcat instance process using the following mentioned command. The following screenshot shows the output for the ps command: [root@localhost bin]# ps -ef |grep java Configuration of instance 2 We cannot use the default configuration on node 2. There will be port conflicts as we are running the instance with single a IP on the same physical machine. Let's configure instance 2 step-by-step: Change the shutdown port for instance 2 in server.xml (increment it by 1). The following screenshot shows the configuration: Change the Connector and redirect the port for instance 2 in server.xml (increment it by 1). The following screenshot shows the configuration: Change the AJP and redirect the port for instance 2 in server.xml (increment it by 1). The following screenshot shows the configuration: Enable the cluster attributes for clustering in server.xml. The following screenshot shows the configuration: Save server.xml.Run the configtest.sh script from TOMCAT_HOME/bin to check the configuration. The following screenshot shows the output for the following startup.sh script: [root@localhost bin]# ./configtest.sh Start the configuration of instance 2 using the script startup.sh. The following screenshot shows the output for the following startup.sh script: [root@localhost bin]# ./startup.sh Check the Tomcat instance process. The following screenshot shows the output for the ps command: [root@localhost bin]# ps -ef |grep java Now, check catalina.out for both the nodes. The logs for node 1 are similar to the following: Oct 11, 2011 5:00:24 PM org.apache.catalina.ha.tcp.SimpleTcpCluster startInternal INFO: Cluster is about to start Oct 11, 2011 5:00:24 PM org.apache.catalina.tribes.transport.ReceiverBase bind INFO: Receiver Server Socket bound to:/127.0.0.1:4000 Oct 11, 2011 5:00:24 PM org.apache.catalina.tribes.membership.McastServiceImpl setupSocket # Instance node 1 started on port 4000 INFO: Setting cluster mcast soTimeout to 500 Oct 11, 2011 5:00:24 PM INFO: Sleeping for 1000 milliseconds to establish cluster membership, start level:8 Oct 11, 2011 5:00:26 PM org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers # waiting for other member to join the cluster org.apache.catalina.ha.session.JvmRouteBinderValve startInternal INFO: JvmRouteBinderValve started Oct 11, 2011 5:00:37 PM org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["http-bio-8080"] Oct 11, 2011 5:00:37 PM org.apache.coyote.AbstractProtocolHandler start INFO: Starting ProtocolHandler ["ajp-bio-8009"] Oct 11, 2011 5:00:37 PM org.apache.catalina.startup.Catalina start INFO: Server startup in 13807 ms Oct 11, 2011 5:23:42 PM 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 Oct 11, 2011 5:23:43 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl [tcp://{127, 0, 0, 1}:4001,{127, 0, 0, 1},4001, alive=1043, securePort=-1, UDP Port=-1, id={33 91 -59 78 -34 -52 73 -9 -99 124 -53 34 69 21 -40 -82 }, payload={}, command={}, domain={}, ] #Instance 2 joined the cluster node. The logs for node 2 are similar to the following: INFO: Starting Servlet Engine: Apache Tomcat/7.0.12 Oct 11, 2011 5:23:41 PM org.apache.catalina.ha.tcp.SimpleTcpCluster startInternal INFO: Cluster is about to start Oct 11, 2011 5:23:42 PM org.apache.catalina.tribes.transport.ReceiverBase bind INFO: Receiver Server Socket bound to:/127.0.0.1:4001 Oct 11, 2011 5:23:42 PM org.apache.catalina.tribes.membership.McastServiceImpl setupSocket # Instance node 2 started on port 4001 INFO: Setting cluster mcast soTimeout to 500 Oct 11, 2011 5:23:42 PM org.apache.catalina.tribes.membership.McastServiceImpl waitForMembers INFO: Sleeping for 1000 milliseconds to establish cluster membership, start level:4 Oct 11, 2011 5:23:43 PM org.apache.catalina.ha.tcp.SimpleTcpCluster memberAdded INFO: Replication member added:org.apache.catalina.tribes.membership.MemberImpl [tcp://{127, 0, 0, 1}:4000,{127, 0, 0, 1},4000, alive=1398024, securePort=-1, UDP Port=-1, id={28 42 60 -68 -99 126 64 -35 -118 -97 7 84 26 20 90 24 }, payload={}, command={}, domain={}, ] # Instance 1 joined the cluster node 2. Apache web server configuration for vertical clustering Until now, we have done the Tomcat-level configuration to configure vertical clustering in the Tomcat instance. It's time to integrate the Apache web server to Tomcat 7. Let's enable the integration by performing the following steps: We have to create a new file called mod_jk.conf in the conf directory of APACHE_HOME/conf using the following commands: [root@localhost apache-2.0]# cd /opt/apache-2.2.19/conf vi mod-jk.conf The contents of mod_jk include the following lines of code: LoadModulejk_module modules/mod_jk.so JkWorkersFile conf/workers.properties JkLogFile logs/mod_jk.log JkLogLevel info JkMount /sample/* loadbalancer JkMount /* loadbalancer Create a new file named as workers.properties in conf using the following command: [root@localhost conf]# vi workers.properties worker.list lists all the nodes in Tomcat through which Apache communicates using the AJP protocol. In our example, it has two nodes, as shown in the following line of code: worker.list=tomcatnode1, tomcatnode2, loadbalancer Define the worker.list for the entire nodes in the cluster: worker.tomcatnode1.port=8009 worker.tomcatnode1.host=localhost worker.tomcatnode1.type=ajp13 worker.tomcatnode1.lbfactor=1 The previous lines of code define the tomcatnode1 properties. The highlighted code shows the AJP port and hostname of tomcatnode1, which is essential for vertical clustering: worker.tomcatnode2.port=8010 worker.tomcatnode2.host=localhost worker.tomcatnode2.type=ajp13 worker.tomcatnode2.lbfactor=1 The previous lines of code define the tomcatnode2 properties. The highlighted code shows the AJP port and hostname of tomcatnode2. This is essential for vertical clustering. worker.loadbalancer.type=lb worker.loadbalancer.balanced_workers=tomcatnode1, tomcatnode2 worker.loadbalancer.sticky_session=1 The previous lines of code define the load balancing properties for mod_jk. The last step is to include the mod_jk.conf in the main configuration file of httpd, that is httpd.conf and reload the Apache services: [root@localhostconf]# vi httpd.conf Note Include conf/mod_jk.conf. in the end of the httpd.conf.

  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint