Tomcat+nginx Cluster and load balancing

Source: Internet
Author: User
Reprint Please specify source: http://blog.csdn.net/l1028386804/article/details/48272857

We'll be with you today. Cluster and load balancing for Tomcat and Nginx

One, Tomcat cluster configuration port planning

Note: This port is started on the same machine 2 tomcat, need to modify the port is not duplicated, if a machine only deploys 1 tomcat its port can be the same.

Serial number

SHUTDOWN

AJP

http

Cluster receiver

1

8005

8009

8080

5001

2

8015

8019

8081

5002

1. Tomcat Cluster configuration

Modify in Server.xml:

Will:
 
  
Modified to:
 
    
 
  

where jvmroute= "JVM1" is not the same name in different Tomcat.

Add The following content to the node to achieve session replication sharing:

 
  
  
   
 
  
   port= "5001" autobind= "selectortimeout=" 5000 " 
    
    
    maxthreads= "6"/> 
   
          
       
  
    
   
    
        
     
     
      
    
 

  
   
 
  
   
 
  
   
 
  
   
 
  
   
 
  
     

Note on the same machine: Receiver node port:port="5001" either.

2. Modify Tomcat's web. xml

You need to modify the Web. XML configuration parameters of Tomcat to really implement the settings for session sync replication

 
  
  
   
    
   index.html
  
   
  
   
    
   index.htm
  
   
  
   
    
   index.jsp
  
   
 
  
 
   (Add this code in the penultimate line to enable session synchronization)

Second, optimization:

1. Memory optimized configuration

1) Windows:

Set java_opts = "-server-xms512m-xmx2048m-xx:maxnewsize=256m-xx:permsize=256m-xx:maxpermsize=512m-xx:+ Useconcmarksweepgc-xx:+printgcdetails  -xx:+printgctimestamps-djava.awt.headless=true "  

2) Linux

java_opts = "-server-xms512m-xmx2048m-xx:maxnewsize=256m-xx:permsize=256m-xx:maxpermsize=512m-xx:+ USECONCMARKSWEEPGC  -xx:+printgcdetails  

2, other optimized configuration:

1) Add the following configuration 1

 
  
Modify
 
  
For
 
  
Modify:
 
  
For
 
  

2) or

Modify

 
  
For
 
  
Modify
 
  
For
 
  

Note: The main difference between the two is that executor is being employed and associated with maxthreads= "500" being ignored.

3) Several attribute explanations:

    • MaxThreads

Tomcat uses threads to process each request that is received. This value represents the maximum number of threads that Tomcat can create. The default value is 200. Can be adjusted according to the machine's time performance and memory size, generally can be in 400-500. The maximum can be around 800.

    • Acceptcount

Specifies the number of requests that can be placed in the processing queue when all the threads that can be used to process the request are used, and requests that exceed this number will not be processed. The default value is 10.

    • Minsparethreads

The number of threads created when Tomcat was initialized. The default value is 4.

    • Connnectiontimeout

Network connection timed out, default value 20000, in milliseconds. Set to 0 to never time out, so the setting is hidden. It can usually be set to 30000 milliseconds. (This system because the interface with the backend system timeout time is longer, use set to 60000)

    • Enablelookups

Whether to reverse the domain name, the default value is true. To improve processing power, set to False

    • Executor node

Represents a pool of threads shared between Tomcat components.

    • MaxIdleTime

The number of milliseconds before the idle thread is closed. The default value is 60000.

Third, Nginx + Tomcat load Balancer configuration

Add the following code in the configuration file/usr/local/nginx/conf/nginx.conf file

  Upstream  Tomcat {        server 192.168.100.50:8080  weight=1;        Server 192.168.100.50:8081  weight=1;  }
Where the tomcat name is arbitrary, note the IP address and port.
To modify the location in the server node:
Location/{        root   html;        Index  index.html index.htm;    }
For
Location  /{   #root   html;   #index  index.html index.htm;           Proxy_pass  Http://tomcat6;}

Note the Tomcat name in Http://tomcat is the same as the above configuration.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The above describes the Tomcat+nginx cluster and load balancing, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.