Apache-based Tomcat load balancing and cluster configuration

Source: Internet
Author: User
Tags f5 load balancer

Not very busy recently, do a little experiment with a bit of time.

Previously, the company used F5 load balancer switch, F5 forwarded the request to multiple servers, each server has multiple webserver instances, each webserver distributed across multiple servers, cross-distributed cluster. F5 just simple to understand, after all, that thing hundreds of thousands of of the price is not a small I can get to do experiment play, and the company can not open authority. Later know that Apache, Nginx software can implement the load (F5 is operating in the iOS Network model Transport layer, Nginx, Apache is based on the HTTP reverse proxy mode, located in the ISO model of the seventh tier application layer. Straightforward is the difference between TCP UDP and HTTP protocol, Nginx can not provide load balancing for TCP protocol-based applications. )

Now to the window under the Nginx+tomcat load balancing to do the configuration attempt to forward all requests to Tomcat, do not do static, dynamic separation, picture anti-theft chain configuration, all the first simple, follow-up slowly add perfect.

Use the Software:

Nginx, two tomcat,Eclipse must have, Web project-owned, other none.

1. Download Nginx

2. Directory structure


nginx-

|_ conf Configuration directory

|_ Contrib

|_ Docs Documentation Directory

|_ Logs Log directory

|_ Temp Temporary file directory

|_ HTML Static page directory

|_ Nginx.exe Main Program


Window installation Nginx is extremely simple, unzip to a non-blank English directory can (personal habits, worry about Chinese problems), double-click Nginx Start, here I installed to: D:\server directory, the following Tomcat is also installed in this directory.

Nginx boot: To execute nginx under directory

Nginx Stop: Nginx-s stop

3, download two versions of TOMCAT6.

The following are the key configuration issues.

Nginx configuration file by default in the Conf directory, the main configuration file is nginx.conf, we installed in D:\server\nginx-1.6.2, the default master profile is D:\server\nginx-1.6.2\nginx.conf. The following is the configuration of Nginx as the front-end reverse proxy server

Nginx.conf

1 #Nginx所用用户和组2 #user NIUMD NIUMD;3 4 #工作的子进程数量 (usually equal to the number of CPUs or twice times the CPU)5Worker_processes2;6 7 #错误日志存放路径8#error_log logs/Error.log;9#error_log logs/Error.log notice;TenError_log logs/Error.log info; One  A #指定pid存放文件 -PID logs/Nginx.pid; -  the Events { - #使用网络IO模型linux建议epoll, FreeBSD recommends using Kqueue - #use Epoll; -      + #允许最大连接数 -Worker_connections2048; + } A  at http { - include mime.types; -Default_type application/octet-stream; -  - #定义日志格式 -#log_format Main'$remote _addr-$remote _user [$time _local] $request' in#'"$status" $body _bytes_sent "$http _referer"' -#'"$http _user_agent" "$http _x_forwarded_for "'; to  + #access_log off; -Access_log logs/Access.log; the  * client_header_timeout 3m; $ client_body_timeout 3m;Panax Notoginseng send_timeout 3m; -   the Client_header_buffer_size 1k; +Large_client_header_buffers44k; A  the sendfile on; + Tcp_nopush on; - tcp_nodelay on; $  $#keepalive_timeout the  -; -  - include gzip.conf; the upstream localhost { - #ip_hashWuyi #ip_hash; theServer localhost:8081; -Server localhost:8080; Wu      } -  About server { $Listen the; - server_name localhost;  -  -Location/ { AProxy_connect_timeout3; +Proxy_send_timeout -; theProxy_read_timeout -; -Proxy_pass http://localhost; $             } the              the    } the}

The gzip compression related configuration is as follows:

gzip              on;gzip_min_length      gzip_types         text/plain text/css application/ X-javascript;

The following is the configuration of Tomcat, which should be familiar to everyone.

I have two tomcat6 here, apache-tomcat-6.0.37-8081 and tomcat-6.0.18-8080, respectively, meaning very clear one with 8081 port one with 8080 ports, modify the Server.xml configuration file can be, port modification is not mentioned here.

After booting two Tomcat successfully. It's time to test the effect.

Browser input: http://localhost/user/test.do This is a link to my own project to see if the background log of a service has been printed, and the results are OK.

In passing, fix the problem: Remove the item name from the URL. Workaround in Server.xml Add the following code, the Path property is not filled, the normal case for the project name, Docbase for the published address, can no longer tomcat directory everyone arbitrarily.

      <context docbase="D:\server\apache-tomcat-6.0.37-8081\wtpwebapps\ project name " path="" reloadable="true" source="org.eclipse.jst.jee.server:mySpring "/>

Apache-based Tomcat load balancing and cluster configuration

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.