Chapter 17: Clustering . Membership service based on

November 19th, 2009

Chapter 17: Clustering . Membership service based on multicast heartbeat and TCP failure detection; dynamically determines the members in a group. . Reliable messaging service between the different members of a group, providing a range of message delivery guarantees. You can configure the exact characteristic of the channel used via: . Configuration of the subelement . Configuration of the and (and associated ) subelements . Configuration of subelements Thorough coverage of the Apache Tribes communications framework is beyond the scope of this chapter; interested readers should peruse the detailed Apache Tribes documentation included with the Tomcat 6 distribution (as part of the webapps/docsapplication). The following subsections explain the specific configuration used in this example. The element has only one attribute as illustrated in the table that follows. Attribute Name Description Default className It must be org.apache.catalina.tribes.group.GroupChannel, the only supported implementation. Configuring the Subelement The subelement configures the membership service. This service is based on sending a multicast heartbeat regularly, and you need to select the frequency, dropTime, and multicast address and port to be used. This service determines and maintains information on the machines that are considered part of the group (cluster) at any point in time. The following table lists some of the attributes on the element. Attribute Name Description Default className address port Currently, only org.apache.catalina.tribes.membership .McastServiceis available. The multicast address selected for this instance. You can use a different multicast address and port to partition your LAN into multiple groups (clusters). However, because of the network traffic that even one replicating cluster generates, this partitioning feature is not as useful as it seems. The multicast port used. You can use a different address:port for multicast to partition your LAN into multiple groups. 228.0.0.4 45564 Table continued on following page

For high quality website hosting services please check tomcat web hosting website.

Chapter 17: Clustering Attribute Name Description Default channelSendOptions

November 19th, 2009

Chapter 17: Clustering Attribute Name Description Default channelSendOptions Option flags are included with messages sent and can be used to trigger Apache Tribes channel interceptors. The numerical value is a logical OR of flag values including: Channel.SEND_OPTIONS_ASYNCHRONUS 8 Channel.SEND_OPTIONS_BYTE_MESSAGE 1 Channel.SEND_OPTIONS_SECURE 16 Channel.SEND_OPTIONS_SYNCHRONIZED_ACK 4 Channel.SEND_OPTIONS_USE_ACK 2 11 (async with ack) The channelSendOptionsvalue is used by the DeltaManager only. If you switch to the BackupManager, this options value is not used. The default value of 11, asynchronous sent with ACK, is adequate in most cases. Configuring DeltaManager or BackupManager The component is the first mandatory nested component within the . Here, you can configure an instance of either DeltaManageror BackupManagerusing the following attributes. Attribute Name Description Default className name notifyListeners- OnReplication expireSessions- OnShutdown domainReplication mapSendOptions For SimpleTcpCluster, only org.apache.catalina.ha .session.DeltaManageror org.apache.catalina.ha .session.BackupManager are available. A name for the cluster manager. The same name should be used on all instances. Indicates if any session listeners should be notified when sessions are replicated between Tomcat instances. Specifies whether it is necessary to expire (and replicate the expiry) of all sessions upon application shutdown. Specifies whether replication should be limited to domain members only; the domain is set as an attribute of the tag. This option is available only with the DeltaManager. When using the BackupManager, this maps the send options that are set to trigger interceptors. See the channelSendOptions attribute of the tag for possible values. false false false 8 (async) Both DeltaManagerand BackupManager send replication information to others via channels from the Apache Tribes group communications library. Configuring Apache Tribes Communications Framework A channel is an abstract endpoint, analogous to a socket, that a member of the group can send and receive replicated information through. Channels are managed and implemented by the Apache Tribes communications framework. The Apache Tribes framework provides the following services:

For high quality website hosting services please check java web hosting website.

Chapter 17: Clustering Replace 192.168.23.2 with your own

November 18th, 2009

Chapter 17: Clustering Replace 192.168.23.2 with your own IP address. Note that the highlighted line is the TCP port on which the Apache Tribes data replication mechanism listens for incoming session update information. Because all three of the Tomcat instances are running on the same physical machines, the port must be different for machine1, machine2, and machine3. The following table shows the port assignments that you need to use. Make sure you configure them properly in the corresponding server.xmlfile. Instance Name tcpListenPort machine1 4200 machine2 4300 machine3 4400 Binding to a Specific Adapter on Multi-Homed Machines Another parameter to be careful about is the bindattribute of the element. This bind attribute is highlighted in bold within the preceding configuration listing. This attribute selects the physical network interface to use on machines that have more than one network adapter called multi-homed machines. If you have only one network adapter, this parameter is typically not necessary. However, because of the way operating systems tend to create virtual network adapters for high-speed links such as IEEE 1394 Firewire, specifying this parameter prevents surprises. The address specified should be the IP address of the specific adapter you want to use. Configuring the Element The following table shows the attributes available for the element. Attribute Name Description Default className The implementation Java class for the cluster manager. Currently, only org.apache.catalina.ha.tcp .SimpleTcpClusteris available. Table continued on following page

For high quality website hosting services please check java web hosting website.

Chapter 17: Clustering TOMCAT 6 component and Apache

November 17th, 2009

Chapter 17: Clustering TOMCAT 6 component and Apache Tribes Membership (determine members dynamically) Data Replication (send data to other member[s], merge incoming data) Figure 17-10: Operational model of Tomcat 6 SimpleTcpCluster implementation To and from other members To and from other members Alternatively, if you were to nest the element under the element, all deployed applications in all hosts are session replicated. Here is the configuration for the element:

For high quality website hosting services please check java web hosting website.

Chapter 17: Clustering Sessions Filtered Replication valve (filter)

November 17th, 2009

Chapter 17: Clustering Sessions Filtered Replication valve (filter) TOMCAT Replication Apache Tribes To other nodes in cluster Figure 17-9: Tomcat components for in-memory session replication This operation of Apache Tribes based implementation is shown in Figure 17-10 . It uses regular multicast (heartbeat packets) to determine membership (and TCP for data transfer and other communications). Any node that is up and running must multicast a heartbeat at regular frequency. Nodes within the same cluster listen to and multicast at the same multicast address and port. Nodes that do not multicast within a required dropTime are considered dead and are removed from the cluster (until they start multicasting again). The membership listens for the multicast and manages the set of current nodes in the cluster dynamically. Session replication requests and session updates are sent between member nodes in the cluster using TCP connections directly, in an end-to-end connection. This means that a node sending replication data makes a direct TCP connection to each and every member node in the cluster when replicating a session. Because of the amount of network traffic generated, the default implementation is practical for use only for clusters with a small membership size. You can achieve some economy by using the BackupManager instead of the default DeltaManagerwith the component. The BackupManagersends data to a backup node (and nodes with the corresponding application deployed) instead of to all members in the cluster. Cluster Session Manager Configuration with the Element The first component is a new component. For this example, the component is nested inside an enclosing element. Including this component in a essentially enables session replication for all applications in the host. The standard manager component used to manage sessions in Tomcat will be replaced with a session replication enabled manager (either DeltaManageror BackupManager).

For reliable and cheap web hosting services please check cheap web hosting website.

Chapter 17: Clustering worker.bal1.sticky_session = 1 worker.bal1.balance_workers =

November 16th, 2009

Chapter 17: Clustering worker.bal1.sticky_session = 1 worker.bal1.balance_workers = machine1, machine2, machine3 worker.stat1.type = status You need to replace 192.168.23.2 with the IP address of your machine (or machines if you are using more than one). For a detailed explanation of the configuration directives, refer to Chapter 11 . Map Path to Load Balance Working Using JkMount Back in the http.conf file of the Apache server, you need to map the path /examples/jsp/*to the mod_jkload balance worker that you have defined in the workers.propertiesfile. JkMount /examples/jsp/* bal1 JkMount /jkstatus/ stat1 You also need to make sure an entry exists to tell the Apache server where the workers.propertiesfile is located. JkWorkersFile conf/workers.properties Preparation for Using Different Session-Sharing Backends This completes the basic common setup for the upcoming cluster examples. Each of the session-sharing backends that will be configured requires very specific configuration and customization, and each is covered individually. More specifically, the following example shows how to configure the following backends: . In-memory replication . The Persistent Session Manager, using a shared-file system . The Persistent Session Manager, using JDBC-to-MySQL RDBMSs The following section covers the configuration of the in-memory replication mechanism. Backend 1: In-Memory Replication Configuration Two components need to be configured to enable in-memory configuration with Tomcat 6. Figure 17-9 depicts the position and function of the two components. In Figure 17-9 , a new component is responsible for the actual session replication. This includes the sending of new session information to the group, incorporating new incoming session information locally, and management of group membership. Under the hood, it uses the Apache Tribe group communications framework to get the job done. Another component, a replication Valve, is used to reduce the potential session replication traffic by ruling out (filtering) certain requests from session replication. Operation of the Tomcat 6 SimpleTcpCluster The default implementation of in-memory replication for Tomcat 6 is called SimpleTcpCluster. It is the only one available as of this writing. Development for clustering and the underlying Apache Tribes groups communications framework is an ongoing development activity.

For high quality jboss hosting services please check jboss web hosting website.

Chapter 17: Clustering If you are configuring three

November 15th, 2009

Chapter 17: Clustering If you are configuring three physical machines, make sure that the web.xmlfile on each machine has the element added. Configuration Consistency The three clustered instances of Tomcat 6 should be identically configured, both software and hardware. This is a wise practice, in general, to reduce potential problems arising from dissimilar configuration. Typically, if the application or system requires machines with different hardware/software configurations, they are maintained in separate clusters (or in a nonclustered configuration). Common Front End: Load Balancing via Apache mod_ jk The load-balancing front end consists of an Apache server with mod_jkinstalled. The following is only a brief recap of the configuration procedure. See Chapter 11 for a detailed, step-by-step explanation of this configuration. Apache Server Configuration Make sure you are using the version of the mod_jk.so that supports your Apache server. Many problems may arise from version mismatch. The examples in this chapter are tested with Apache 2.2.3 (Win32) with mod_jk 1.2.19. On the Apache server side, if the mod_jk support is not included, you must make sure the mod_jkmodule is loaded at startup. This can be done by adding the following line to the conf/http.conffile: LoadModule jk_module modules/mod_jk.so This line should immediately follow all the LoadModule directives in the file. Note that the downloaded mod_jk library needs to be renamed to mod_jk.so. It should be placed in the modules directory of the Apache server. mod_ jk Configuration When the mod_jkmodule starts up, it looks for a workers.propertiesfile. The following workers .propertiesfile should be placed into the conf subdirectory of the Apache server: worker.list = bal1,stat1 worker.machine1.type = ajp13 worker.machine1.host = 192.168.23.2 worker.machine1.port = 8009 worker.machine1.lbfactor = 10 worker.machine2.type = ajp13 worker.machine2.host = 192.168.23.2 worker.machine2.port = 8109 worker.machine2.lbfactor = 10 worker.machine3.type = ajp13 worker.machine3.host = 192.168.23.2 worker.machine3.port = 8209 worker.machine3.lbfactor = 10 worker.bal1.type = lb (continued)

For reliable and cheap web hosting services please check cheap web hosting website.

Chapter 17: Clustering … The following table shows

November 15th, 2009

Chapter 17: Clustering … The following table shows the jvmRoute attribute values that you need to set for each of the three Tomcat instances. Instance Name File to Modify jvmRoute Value machine1 machine2 machine3 clustermachine1confserver.xml clustermachine2confserver.xml clustermachine3confserver.xml machine1 machine2 machine3 If you are configuring on three physical machines, you must configure the Tomcat instance on each machine with a different jvmRoutevalue. Setting the Attribute for Web Applications Instead of creating a Web application from scratch, this experiment takes advantage of the existing jsp-examples Web application. To indicate to the Servlet container (Tomcat 6) that this application can be clustered, a Servlet 2.4 standard element is placed into the application s deployment descriptor: the web.xmlfile. The following code shows the placement of the element. If you remove this element, the session maintained by this application across the three Tomcat 6 instances will not be shared: Servlet and JSP Examples. Servlet and JSP Examples Servlet Mapped Filter filters.ExampleFilter … This element must be manually added to the web.xml file in all three instances: . clustermachine1webappsexamplesWEB-INFweb.xml . clustermachine2webappsexamplesWEB-INFweb.xml . clustermachine3webappsexamplesWEB-INFweb.xml

For high quality website hosting services please check java web hosting website.

Chapter 17: Clustering on port 8005 for shutdown,

November 13th, 2009

Chapter 17: Clustering on port 8005 for shutdown, and the AJP Coyote Connector listens on 8009. The relevant lines in server .xml that must be customized for each instance are highlighted here: … The following table shows what you need to configure in each instance. Instance Name File to Modify TCP Ports (Shutdown, AJP Connector) machine1 machine2 machine3 clustermachine1confserver.xml clustermachine2confserver.xml clustermachine3confserver.xml 8005, 8009 8105, 8109 8205, 8209 The settings chosen here ensure that there will be no conflict starting the three Tomcat 6 instances simultaneously on the same physical machine. If you are actually setting up the test across three physical machines on the network, they can all use the setting of machine1in the table. Setting Up jvmRoute for Each Tomcat Instance to Support mod_ jk To support the mod_jkload balancing, you must set a unique jvmRoute for each Tomcat instance. jvmRoute is an Engine attribute and acts as an identifier for that particular Tomcat worker. This identifier must be unique across all the available Tomcat instances participating in the load-balancing envi ronment. It must also be specified in the Apache Server s mod_jk s worker.propertiesfile (see next section). In each of the server.xmlfiles, modify the following highlighted line to add the jvmRouteattribute. … … (continued)

If you looking for unlimited one inclusive web hosting plan please check cheap web hosting website.

Chapter 17: Clustering number of applications loaded. This

November 12th, 2009

Chapter 17: Clustering number of applications loaded. This is because considerable overhead is associated with each clustered application (session management, network traffic, and so on). The webapps subdirectory on clustered machines should be thoroughly clean, except for the clustered Web applications. web applications to run on this instance server.xml and other conf files for this instance logs for this instance server temp files for this instance temporary files directory for this instance clustermachine1machine2machine3shareddirwebappsconflogsworktemp same subdirectories as machine 1 same subdirectories as machine 1 for persistence session manager Figure 17-8: Directory tree for the clustering examples In this case, make sure you copy the webappsexamples subdirectory from the Tomcat 6 distribution into each of the webapps directories of the three machines. Disabling the HTTP Connectors The default server.xml file included with the Tomcat 6 distribution sets up two Connectors. One is an HTTP 1.1 Connector listening on port 8080, and the other one is an AJP 1.3 Connector listening on port 8009. You must first comment out the HTTP Connector if you are using the standard server.xmlfile. This ensures that the three instances will not fight for the 8080 port during startup: –> … Note that if you use the code distribution provided with this blog, the HTTP Connectors are already removed from the server.xmlfiles. Configuring AJP TCP Ports for Clustered Tomcat Instances In order for the three Tomcat 6 instances to coexist peacefully on a single physical machine, it is necessary to give the AJP Connectors different TCP ports on which to listen. By default, the server is listening

For reliable and cheap web hosting services please check cheap web hosting website.