Cluster configuration (1): Tomcat cluster configuration

Source: Internet
Author: User

A cluster is a solution that connects multiple systems to form a system. On the one hand, a cluster shares requests with multiple systems to improve the load capacity of the system, on the other hand, to improve system reliability, other systems respond to requests when a system crashes. Here, we will introduce the Tomcat cluster configuration. For the structure, see:

I. tools and materials:
Apache Web Server (Apache httpd): http://httpd.apache.org/download.cgi
JK (jk-1.2.18): http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.18/
Tomcat (tomcat5.5): http://tomcat.apache.org/download-55.cgi
For more information, see the documentation provided by each tool. The tool installation is not described here. By default, Apache is installed in the $ Apache directory, and rename the mod_jk-apache-2.2.2.so mod_jk.so under $ Apache/modules (note the relationship between JK and Apache httpd version), the installation paths of both Tomcat are in $ Tomcat AT1 and $ Tomcat 2.
Ii. Server Load balancer
1. Request-Based Load Balancing
In this way, the Load balancer distributes each HTTP request according to the status of each node. When using such a balance policy, you must copy the user's session between multiple nodes to synchronize the user status of the entire cluster in real time. This operation is called session replication ).
The advantage of this method is that the customer will not be bound to all specific nodes. As long as another node is alive, the user status will not be lost, and the cluster can continue to work. The disadvantage is that as the number of nodes increases, the performance may be greatly reduced due to a broadcast storm.
2. Session-Based Load Balancing
In this mode, when the user sends the first request, the Server Load balancer dynamically allocates the user to a node and records the JVM route of the node, in the future, all requests of this user will be bound to this JVM route, and the user will only interact with this server. This policy is called sticky session ). The advantage of this method is that the response speed is fast and there is no need to communicate between multiple nodes. The disadvantage is that when a node dies, all the users it is responsible for will lose the session.
3. Broker Load Balancing
Slice nodes. Each slice is an external service. Request-based load balancing is used in the slice, while session-based load balancing is used outside the slice, using this kind of processing will keep the broadcast of local session replication as a constant, without the performance degradation caused by the addition of nodes, while maintaining high reliability, all session data is not lost because of a node crash.
The configuration of the first and second types of Server Load balancer will be introduced here.
Iii. Session-Based Load Balancing
1) Add the following configuration to $ Apache/CONF/httpd. conf:

The following is the program code:

# Load mod_jk Module
# Update this path to match your modules location
Loadmodule jk_module modules/mod_jk.so
# Declare the module for <ifmodule directive> (remove this line on Apache 2.x)
# Addmodule mod_jk.c
# Where to find workers. Properties
# Update this path to match your conf directory location (put workers. properties next to httpd. conf)
Jkworkersfile CONF/workers. Properties
# Where to put JK logs
# Update this path to match your logs directory location (put mod_jk.log next to access_log)
Jklogfile JK/jk_log.txt
# Set the jk log level [debug/error/info]
Jkloglevel info
# Select the log format
Jklogstampformat "[% A % B % d % H: % m: % S % Y]"
# Jkoptions indicate to send SSL key size,
Jkoptions + forwardkeysize + forwarduricompat-forwarddirectories
# Jkrequestlogformat set the request format
Jkrequestlogformat "% w % v % t"
# Send everything for context/examples to worker named worker1 (ajp13)
Jkmount/* loadbalancer

2) create workers. properties in $ Apache/CONF/. The content is as follows. For detailed configuration of worker, see the jarctor document of jarkarta-Tomcat.

The following is the program code:

Worker. List = loadbalancer, server2, server1
# Define the first node...
Worker. server2.port = 8010
Worker. server2.host = localhost
Worker. server2.type = ajp13
Worker. server2.lbfactor = 1
Worker. server2.local _ worker = 1
Worker. server2.cachesize = 10

# Define the first node...
Worker. server1.port = 8009
Worker. server1.host = localhost
Worker. server1.type = ajp13
Worker. server1.lbfactor = 1
Worker. server1.local _ worker = 1
Worker. server1.cachesize = 10

# Now we define the load-balancing behaviour
Worker. loadbalancer. type = LB
Worker. loadbalancer. balanced_workers = server1, server2
Worker. loadbalancer. sticky_session = 1

In the preceding example, loadbalancer is a virtual worker and does not represent any node. It is only used to manage other workers (note that its type is lb)
3) configuration of two Tomcat servers
Modify the port configuration of $ tomcat/CONF/server. XML according to the preceding workers. properties configuration, and modify
<Engine name = "Catalina" defaulthost = "localhost"> <engine name = "Catalina" defaulthost = "localhost" jvmroute = "server1/2">
Start Tomcat and Apache.
4. Request-Based Load Balancing
Add the following configuration based on the above Configuration:
1) Change worker. loadbalancer. sticky_session value of workers. properties to 0.
2) Remove the cluster configuration comment in server. XML (note the port. If Server Load balancer is performed on the same server, do not conflict with the port)
3) add <distributable/> to the Web. xml file of the application.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.