Load Balancing for nginx and tomcat in CentOS

Source: Internet
Author: User

Load Balancing for nginx and tomcat in CentOS

Some time ago, leaders always looked at the system, but the system was always updated frequently. In order to prevent the leaders from seeing anything when updating the system, they planned to use ngix as the proxy and deploy two tomcat servers in the background for load balancing, to avoid the problem that the system cannot be used when updating the system, I read the documents and record several key points here for my memo.

Environment: jdk, 1.7, tomcat7, nginx1.5.8; 64-bit windows Configuration

Step 1: Change the three tomcat ports to ensure that two tomcat servers can run on the same machine. The changed ports include server ports and two ctor ports. For xml configuration, see the following. To avoid excessive file sizes, commented and irrelevant configurations are deleted:

[Html] view plaincopy
  1. <? Xmlversion = '1. 0' encoding = 'utf-8'?>
  2. <Serverport = "18005" shutdown = "SHUTDOWN">
  3. <ListenerclassName = "org. apache. catalina. core. AprLifecycleListener" SSLEngine = "on"/>
  4. <! -- Initializejasperpriortowebjavasareloaded. Documentationat/docs/jasper-howto.html -->
  5. <ListenerclassName = "org. apache. catalina. core. JasperListener"/>
  6. <! -- Preventmemoryleaksduetouseofularjava/javaxAPIs -->
  7. <ListenerclassName = "org. apache. catalina. core. JreMemoryLeakPreventionListener"/>
  8. <ListenerclassName = "org. apache. catalina. mbeans. GlobalResourcesLifecycleListener"/>
  9. <ListenerclassName = "org. apache. catalina. core. ThreadLocalLeakPreventionListener"/>
  10. <GlobalNamingResources>
  11. <Resourcename = "UserDatabase" auth = "Container"
  12. Type = "org. apache. catalina. UserDatabase"
  13. Description = "Userdatabasethatcanbeupdatedandsaved"
  14. Factory = "org. apache. catalina. users. MemoryUserDatabaseFactory"
  15. Pathname = "conf/tomcat-users.xml"/>
  16. </GlobalNamingResources>
  17. <Servicename = "Catalina">
  18. <Connectorport = "8082" protocol = "HTTP/1.1"
  19. ConnectionTimeout = "20000"
  20. RedirectPort = "8443" type = "regxph" text = "yourobjectname"/>
  21. <Connectorport = "18009" protocol = "AJP/1.3" redirectPort = "8443"/>
  22. .....
  23. </Service>
  24. </Server>

Second, configure nginx (Server Load balancer ):

Add the following configuration under the http node:

[Plain] view plaincopy
  1. Upstreamlocalhost {
  2. # Assign a fixed tomcat for user requests from different ip addresses to respond to their requests.
  3. Ip_hash;
  4. # Configure the tomcat server ip Address: Port and process the request weight
  5. Serverlocalhost: 8080 weight = 5;
  6. Serverlocalhost: 8082 weight = 5;
  7. }

Change location/node configuration under http nodes: [plain] view plaincopy
  1. Location /{
  2. # Roothtml;
  3. Define indexindex.htmlindex.htm;
  4. Proxy_connect_timeout3;
  5. Proxy_send_timeout30;
  6. Proxy_read_timeout30;
  7. Proxy_passhttp: // localhost;
  8. }
After the configuration is complete, start two tomcat servers, then start nginx, and enable ngix: Enter the DOS command window, switch to the nginxmain directory, and enter the nginx.exe command,

You can use nginx.exe-s stop to stop nginx.

For more detailed steps, see the following two links:

Http://ari.iteye.com

Http://www.blogjava.net/tunaic/archive/2009/11/30/304212.html

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.