Este contenido no está disponible en el idioma seleccionado.
Chapter 22. HTTP Services
- Session state replication
- Load-balancing HTTP Requests
all configuration, session state replication is enabled by default. Just configure your web application as <distributable> in its web.xml (see Section 22.2, “Configuring HTTP session state replication”), deploy it, and its session state is automatically replicated across all JBoss instances in the cluster.
Note
22.1. Configuring load balancing using Apache and mod_jk Copiar enlaceEnlace copiado en el portapapeles!
22.1.1. Download the software Copiar enlaceEnlace copiado en el portapapeles!
APACHE_HOME directory.
mod_jk.so and copy it under APACHE_HOME/modules/.
22.1.2. Configure Apache to load mod_jk Copiar enlaceEnlace copiado en el portapapeles!
Include mod_jk's specific configuration file
# Include mod_jk's specific configuration file
Include conf/mod-jk.conf
APACHE_HOME/conf/mod-jk.conf:
- The
LoadModuledirective must reference the mod_jk library you have downloaded in the previous section. You must indicate the exact same name with the "modules" file path prefix. - The
JkMountdirective tells Apache which URLs it should forward to the mod_jk module (and, in turn, to the Servlet containers). In the above file, all requests with URL path/application/*are sent to the mod_jk load-balancer. This way, you can configure Apache to serve static contents (or PHP contents) directly and only use the loadbalancer for Java applications. If you only use mod_jk as a loadbalancer, you can also forward all URLs (i.e.,/*) to mod_jk.
JkMount directive, you can also use the JkMountFile directive to specify a mount points configuration file, which contains multiple Tomcat forwarding URL mappings. You just need to create a uriworkermap.properties file in the APACHE_HOME/conf directory. The format of the file is /url=worker_name. To get things started, paste the following example into the file you created:
/jmx-console and /web-console to Tomcat.
mod_jk.conf. They are used to tell mod_jk where to put its logging file, which logging level to use and so on.
22.1.3. Configure worker nodes in mod_jk Copiar enlaceEnlace copiado en el portapapeles!
conf/workers.properties. This file specifies where the different Servlet containers are located and how calls should be load-balanced across them. The configuration file contains one section for each target servlet container and one global section. For a two nodes setup, the file could look like this:
workers.properties file, each node is defined using the worker.XXX naming convention where XXX represents an arbitrary name you choose for each of the target Servlet containers. For each worker, you must specify the host name (or IP address) and the port number of the AJP13 connector running in the Servlet container.
lbfactor attribute is the load-balancing factor for this specific worker. It is used to define the priority (or weight) a node should have over other nodes. The higher this number is for a given worker relative to the other workers, the more HTTP requests the worker will receive. This setting can be used to differentiate servers with different processing power.
ping_mode attribute enables CPing/CPong. It determines when established connections are probed to determine whether they are still working. In this case, ping_mode is set to A, which means that the connection is probed once after connecting to the backend, before sending each request to the backend, and at regular intervals during the internal maintenance cycle.
conf/workers.properties file defines the loadbalancer worker. The only thing you must change is the worker.loadbalancer.balanced_workers line: it must list all workers previously defined in the same file. Load-balancing will happen over these workers.
sticky_session property specifies the cluster behavior for HTTP sessions. If you specify worker.loadbalancer.sticky_session=0, each request will be load balanced between node1 and node2; i.e., different requests for the same session will go to different servers. But when a user opens a session on one server, it is always necessary to always forward this user's requests to the same server, as long as that server is available. This is called a "sticky session", as the client is always using the same server he reached on his first request. To enable session stickiness, you need to set worker.loadbalancer.sticky_session to 1.
Note
worker.list=node1 entry.
22.1.4. Configuring JBoss to work with mod_jk Copiar enlaceEnlace copiado en el portapapeles!
workers.properties. For instance, on JBoss instance node1, edit the JBOSS_HOME/server/all/deploy/jbossweb.sar/server.xml file (replace /all with your own server name if necessary). Locate the <Engine> element and add an attribute jvmRoute:
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1"> ... </Engine>
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="node1">
...
</Engine>
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}"
redirectPort="8443" />
<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector protocol="AJP/1.3" port="8009" address="${jboss.bind.address}"
redirectPort="8443" />
Note
http://www.jboss.org/community/wiki/UsingModjk12WithJBoss.
22.1.5. Configuring the NSAPI connector on Solaris Copiar enlaceEnlace copiado en el portapapeles!
Note
-b switch to bind your instance of JBoss Enterprise Platform to a public IP address. Remember to edit the workers.properties file on the SJWS machine to reflect these changes in IP address.
22.1.5.1. Prerequisites Copiar enlaceEnlace copiado en el portapapeles!
- Your worker node(s) are already installed with a JBoss Enterprise Platform 5.1 or later. The Native components are not a requirement of the NSAPI connector. Refer to the Installation Guide for assistance with this prerequisite.
- Your master node is already installed with any of the following technology combinations, and the appropriate Native binary for its operating system and architecture. Refer to the Installation Guide for assistance with this prerequisite.
- Solaris 9 x86 with Sun Java System Web Server 6.1 SP12
- Solaris 9 SPARC 64 with Sun Java System Web Server 6.1 SP12
- Solaris 10 x86 with Sun Java System Web Server 7.0 U8
- Solaris 10 SPARC 64 with Sun Java System Web Server 7.0 U8
22.1.5.2. Configure JBoss Enterprise Platform as a Worker Node Copiar enlaceEnlace copiado en el portapapeles!
Procedure 22.1. Configure a JBoss Enterprise Platform instance as a worker node
Create a server profile for each worker node
Make a copy of the server profile that you wish to configure as a worker node. (This procedure uses thedefaultserver profile.)cp -r default/ default-01 cp -r default/ default-02
[user@workstation jboss-eap-5.1]$ cd jboss-as/server [user@workstation server]$ cp -r default/ default-01 [user@workstation server]$ cp -r default/ default-02Copy to Clipboard Copied! Toggle word wrap Toggle overflow Give each instance a unique name
Edit the following line in thedeploy/jbossweb.sar/server.xmlfile of each new worker instance:<Engine name="jboss.web" defaultHost="localhost">
<Engine name="jboss.web" defaultHost="localhost">Copy to Clipboard Copied! Toggle word wrap Toggle overflow Add a uniquejvmRoutevalue, as shown. This value is the identifier for this node in the cluster.For thedefault-01server profile:<Engine name="jboss.web" defaultHost="localhost" jvmRoute="worker01">
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="worker01">Copy to Clipboard Copied! Toggle word wrap Toggle overflow For thedefault-02server profile:<Engine name="jboss.web" defaultHost="localhost" jvmRoute="worker02">
<Engine name="jboss.web" defaultHost="localhost" jvmRoute="worker02">Copy to Clipboard Copied! Toggle word wrap Toggle overflow Enable session handling
Edit the following line in thedeployers/jbossweb.deployer/META-INF/war-deployers-jboss-beans.xmlfile of each worker node:<property name="useJK">false</property>
<property name="useJK">false</property>Copy to Clipboard Copied! Toggle word wrap Toggle overflow This property controls whether special session handling is used to coordinate with mod_jk and other connector variants. Set this property totruein both worker nodes:<property name="useJK">true</property>
<property name="useJK">true</property>Copy to Clipboard Copied! Toggle word wrap Toggle overflow Start your worker nodes
Start each worker node in a separate command line interface. Ensure that each node is bound to a different IP address with the-bswitch.[user@workstation jboss-eap-5.1]$ ./jboss-as/bin/run.sh -b 127.0.0.1 -c default-01
[user@workstation jboss-eap-5.1]$ ./jboss-as/bin/run.sh -b 127.0.0.1 -c default-01Copy to Clipboard Copied! Toggle word wrap Toggle overflow [user@workstation jboss-eap-5.1]$ ./jboss-as/bin/run.sh -b 127.0.0.100 -c default-02
[user@workstation jboss-eap-5.1]$ ./jboss-as/bin/run.sh -b 127.0.0.100 -c default-02Copy to Clipboard Copied! Toggle word wrap Toggle overflow
22.1.5.3. Configure Sun Java System Web Server for Clustering Copiar enlaceEnlace copiado en el portapapeles!
/tmp/connectors/jboss-ep-native-5.1/. This path is referred to as NATIVE in the procedures that follow. These procedures also assume that the /tmp/connectors directory is used to store logs, properties files and NSAPI locks.
- for Solaris 9 x86 or SPARC 64:
/opt/SUNWwbsrv61/ - for Solaris 10 x86 or SPARC 64:
/opt/SUNWwbsrv70/
Procedure 22.2. Initial clustering configuration
Disable servlet mappings
Under Built In Servlet Mappings in theSJWS/PROFILE/config/default-web.xmlfile, disable the mappings for the following servlets, as shown in the code sample:- default
- invoker
- jsp
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Load the required modules and properties
Append the following lines to theSJWS/PROFILE/config/magnus.conffile:Init fn="load-modules" funcs="jk_init,jk_service" shlib="NATIVE/lib/nsapi_redirector.so" shlib_flags="(global|now)" Init fn="jk_init" worker_file="/tmp/connectors/workers.properties" log_level="debug" log_file="/tmp/connectors/nsapi.log" shm_file="/tmp/connectors/jk_shm"
Init fn="load-modules" funcs="jk_init,jk_service" shlib="NATIVE/lib/nsapi_redirector.so" shlib_flags="(global|now)" Init fn="jk_init" worker_file="/tmp/connectors/workers.properties" log_level="debug" log_file="/tmp/connectors/nsapi.log" shm_file="/tmp/connectors/jk_shm"Copy to Clipboard Copied! Toggle word wrap Toggle overflow These lines define the location of thensapi_redirector.somodule used by thejk_initandjk_servicefunctions, and the location of theworkers.propertiesfile, which defines the worker nodes and their attributes.Note
Thelibdirectory in theNATIVE/lib/nsapi_redirector.sopath applies only to 32-bit machines. On 64-bit machines, this directory is calledlib64.
22.1.5.3.1. Configure a basic cluster with NSAPI Copiar enlaceEnlace copiado en el portapapeles!
/nc path, while worker01 serves /status and all other paths defined in the first part of the obj.conf file.
Procedure 22.3. Configure a basic cluster with NSAPI
Define the paths to serve via NSAPI
Edit theSJWS/PROFILE/config/obj.conffile. Define paths that should be served via NSAPI at the end of thedefaultObject definition, as shown:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can map the path of any application deployed on your JBoss Enterprise Platform instance in thisobj.conffile. In the example code, the/ncpath is mapped to an application deployed under the namenc.Define the worker that serves each path
Edit theSJWS/PROFILE/config/obj.conffile and add the followingjknsapiObject definition after thedefaultObject definition.Copy to Clipboard Copied! Toggle word wrap Toggle overflow ThisjknsapiObject defines the worker nodes used to serve each path that was assigned toname="jknsapi"in thedefaultObject.In the example code, the third Service definition does not specify apathvalue, so the worker node defined (worker01) serves all of the paths assigned tojknsapiby default. In this case, the first Service definition in the example code, which assigns the/statuspath toworker01, is superfluous.Define the workers and their attributes
Create aworkers.propertiesfile in the location you defined in Step 2. Define the list of worker nodes and each worker node's properties in this file, like so:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
22.1.5.3.2. Configure a Load-balanced Cluster with NSAPI Copiar enlaceEnlace copiado en el portapapeles!
Procedure 22.4. Configure a load-balancing cluster with NSAPI
Define the paths to serve via NSAPI
Edit theSJWS/PROFILE/config/obj.conffile. Define paths that should be served via NSAPI at the end of thedefaultObject definition, as shown:Copy to Clipboard Copied! Toggle word wrap Toggle overflow You can map the path of any application deployed on your JBoss Enterprise Platform instance in thisobj.conffile. In the example code, the/ncpath is mapped to an application deployed under the namenc.Define the worker that serves each path
Edit theSJWS/PROFILE/config/obj.conffile and add the followingjknsapiObject definition after thedefaultObject definition.<Object name="jknsapi"> ObjectType fn=force-type type=text/plain Service fn="jk_service" worker="status" path="/jkmanager(/*)" Service fn="jk_service" worker="router" </Object>
<Object name="jknsapi"> ObjectType fn=force-type type=text/plain Service fn="jk_service" worker="status" path="/jkmanager(/*)" Service fn="jk_service" worker="router" </Object>Copy to Clipboard Copied! Toggle word wrap Toggle overflow ThisjknsapiObject defines the worker nodes used to serve each path that was assigned toname="jknsapi"in thedefaultObject.Define the workers and their attributes
Create aworkers.propertiesfile in the location you defined in Step 2. Define the list of worker nodes and each worker node's properties in this file, like so:Copy to Clipboard Copied! Toggle word wrap Toggle overflow
22.1.5.3.3. Restart Sun Java System Web Server Copiar enlaceEnlace copiado en el portapapeles!
SJWS/PROFILE/stop SJWS/PROFILE/start
SJWS/PROFILE/stop
SJWS/PROFILE/start
SJWS/PROFILE/bin/stopserv SJWS/PROFILE/bin/startserv
SJWS/PROFILE/bin/stopserv
SJWS/PROFILE/bin/startserv