Photo Commentary: Nginx + tomcat6 configure load balancing
Advertisements
Applications developed by F5 load balancing switches, F5 forwards the request to 5 hp unix servers, each have more than one webserver instance, external provision of services and the socket interface, such as web services. The beginning, there was a little doubt that the reasons for not using open source, apache, Nginx software load, F5 hundreds of thousands of devices easily, expensive? A rather naive question yourself, follow-up to understand: F5 is the operating model in the IOS network transport layer, Nginx, apache http reverse proxy based approach, in the seventh layer ISO model application layer. TCP UDP and more straightforward is the difference between http protocol, Nginx can not be based on TCP protocol load balancing applications.
Different from the understanding between the two scenarios, a strong interest on the Nginx, reading Zhang Yan's <real Nginx> (the 85 years young and promising young man envy + jealousy), thoroughly understand the general principles and configuration, Ubuntu10 .10, window under Nginx + tomcat configuration tries to do load balancing, all requests will be forwarded to tomcat, did not do static and dynamic separation, pictures and other anti-Daolian configuration.
Nginx Introduction
Nginx (pronounced the same engine x) is a lightweight Web server / reverse proxy server and e-mail (IMAP/POP3) proxy server, and a BSD-like agreement issued. Characterized by possession of less memory, concurrent capacity, ability to do concurrent nginx fact the same type of web server performance is better. Nginx web site is currently used in mainland China users: Sina, Netease, Tencent, another well-known micro-network Chi also use Plurk nginx.
Nginx described above are all essentially nonsense, turn to the question below, graphic display with the basic configuration, the first is the window environment, followed by the Ubuntu environment (Vbox virtual). This article is based on Nginx configure two tomcat, the structure below:
Window xp environment: Nginx + Tomcat6
1, Download
http://nginx.org/en/download.html, here we recommend downloading the stable (stable versions), this paper nginx-0.8.20.
2, the directory structure
Nginx-
| _ Conf configuration directory
| _ Contrib
| _ Docs documentation directory
| _ Logs log directory
| _ Temp temporary files directory
| _ Html static pages directory
| _ Nginx.exe main
window is extremely simple to install Nginx, unzip to a directory without spaces in English can be (personal habits, worrying the Chinese problem), double-click the nginx start, where I installed: D: \ server directory, the following is also related to the tomcat installed in this directory.
DOC environment starts
If you want to stop nginx, dos environment, run the command: nginx-s stop
3, nginx.conf configuration
Nginx configuration file conf directory by default, the main configuration file for nginx.conf, we have installed in D: \ server \ nginx-0.8.20, the default master configuration file for D: \ server \ nginx-0.8.20 \ nginx.conf. The following is nginx as a front-end reverse proxy server configuration.
#Nginx For all users and groups, window is not specified under
#user niumd niumd;
# The number of child processes to work ( Usually equal to the number of CPU or 2 Times CPU)
worker_processes 2;
# Error log storage path
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
# Pid file documents specified
pid logs/nginx.pid;
events {
# IO models use the network linux Suggested epoll, FreeBSD recommended kqueue,window Not specified under .
#use epoll;
# Maximum number of connections allowed
worker_connections 2048;
}
http {
include mime.types;
default_type application/octet-stream;
# Custom Log Format
#log_format main '$remote_addr - $remote_user [$time_local] $request '
# '"$status" $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log off;
access_log logs/access.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 75 20;
include gzip.conf;
upstream localhost {
# Calculated according to the request to assign the ip that the back-end tomcat, Many people mistakenly believe that the problem can be solved session , In fact, not .
# The same machine in case of multi-network, routing switch ,ip May be different
#ip_hash;
server localhost:18081;
server localhost:18080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
}
}
}
Proxy settings are as follows:
proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 300; proxy_send_timeout 300; proxy_read_timeout 300; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k;
gzip compression related configuration is as follows:
gzip on; gzip_min_length 1000; gzip_types text/plain text/css application/x-javascript;
4, Tomcat configuration
For tomcat you are familiar with, only you can modify the server.xml configuration file, here we apache-tomcat-6.0.14, for example, were in the server directory, unzip it and name it: apache-tomcat-6.0.14_1, apache-tomcat-6.0.14_2.
The first change at the port:
<!-- Modify the port port :18006 Tomcat can not be repeated two months , Port free, too young --> <Server port="18006" shutdown="SHUTDOWN">
The second change at the port:
<!-- port="18081" tomcat Monitor port, random set , Do not be too small -->
<Connector port="18081" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Third Department of the port changes:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />
Engine elements increase jvmRoute attributes:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
Do not repeat the two ports tomcat, guaranteed to start up, the other tomcat configuration Seagate omitted, listens on port 18080, annex, we will upload all the configuration information.
5, the test configuration and load balancing
First Test nginx configuration is correct, the test command: nginx-t (the default authentication: conf \ nginx.conf), you can specify the configuration file path.
In this case nginx installation directory: D: \ server \ nginx-0.8.20, dos environment map screen success examples:
Second authentication tomcat, start two tomcat, port conflict shall not successful (tomcat java dependencies, etc. to engage in "kicked" and is not to say nonsense);
Finally, verify the configuration load balancing settings, http://localhost/ or http://localhost/index.jsp. I changed the index.jsp page to increase the log output, easy to observe. Note: The upper left corner of kitten's head: access tomcat2, access tomcat1. That access to the different tomcat.
At this point the next window nginx + tomcat end load balancing configuration on tomcat Session of the problem is often used memcached, or to use nginx_upstream_jvm_route, he is a Nginx extension modules used to implement the Session Sticky Cookie-based features. Tomcat session is not recommended if excessive synchronization, server synchronization session between a waste of resources with each other, high-concurrency environment prone Session storm. Application according to their own session to adopt a reasonable solution.
Ubuntu10.10 Environment: Nginx + Tomcat6
Here we simply how to install and configure the next ubuntu10.10, mainly picture-based, simple explanation.
1, Download Nginx
Address: http://nginx.org/en/download.html, linux version: nginx-0.8.20.tar.. The extract command:
tar -zxvf nginx-0.8.20.tar.gz
2, compiled Nginx
Nginx rely on some other PCRE, openssl (dependent on libssl-dev), the environment I have installed Ubuntu notebooks PCRE, just install the dependencies openssl, we simply say the following PCRE, and how to install openssl, etc.
PCRE Download: ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/
tar zxvf pcre-8.01.tar.gz cd pcre-8.01 sudo ./configure sodu make sodu make install
openssl installed via apt-get install, order, screenshot as follows:
sudo apt-get install openssl sudo apt-get install libssl-dev // Such as lack of other packages, please use this method to install ,ubuntu Have to rely on tips
Dependent packages installed, the following to compile Nginx:
# Copies of the software window to the shared directory the current working directory cp /mnt/fileshare/nginx-0.8.20.tar.gz ./ # Unzip Package tar zxvf nginx-0.8.20.tar.gz cd nginx-0.8.20 // Compile source code, default nobody, Specify the local existing users, groups, , Nginx-status feature is enabled , Nginx status monitoring . Start debug sudo ./configure --user=niumd --group=niumd --with-debug --with-http_stub_status_module sudo make sudo make install
Screenshot below:
Screenshot installation results are as follows:
Compile and install correctly concluded, in accordance with the above method to check under the default configuration window, and then in the default configuration to start nginx, visit http://127.0.0.1, the following diagram illustrates the success
Nginx configuration under ubuntu and under the same window, the difference in the use of the IO network model, linux is recommended to use epoll;
#Nginx Users and groups used
user niumd niumd;
# The number of child processes to work ( Usually equal to the number of CPU or 2 Times CPU)
worker_processes 2;
# Error log storage path
#error_log logs/error.log;
#error_log logs/error.log notice;
error_log logs/error.log info;
# Pid file documents specified
pid logs/nginx.pid;
events {
# IO models use the network linux Suggested epoll, FreeBSD recommended kqueue
use epoll;
# Maximum number of connections allowed
worker_connections 2048;
}
http {
include mime.types;
default_type application/octet-stream;
# Custom Log Format
#log_format main '$remote_addr - $remote_user [$time_local] $request '
# '"$status" $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log off;
access_log logs/access.log;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
client_header_buffer_size 1k;
large_client_header_buffers 4 4k;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
#keepalive_timeout 75 20;
include gzip.conf;
upstream localhost {
#ip_hash
#ip_hash;
server localhost:18081;
server localhost:18080;
}
server {
listen 80;
server_name localhost;
location / {
proxy_connect_timeout 3;
proxy_send_timeout 30;
proxy_read_timeout 30;
proxy_pass http://localhost;
}
}
}
Related Posts of Photo Commentary: Nginx + tomcat6 configure load balancing
-
***** JavaScript function advanced programming of the same name, the implementation of the order of [original] *****
Author: Topcss QQ: 419074376 E-mail: andpai1.0 @ gmail.com Time :2008-10-20 Background: This is to help teachers make a Friend of Writing for class teaching. When we JavaScript, it is necessary to the implementation of a function are often written li ...
-
***** JavaScript object-oriented object-wide solution [half of original] *****
Author: Topcss QQ: 419074376 E-mail: andpai1.0 @ gmail.com Time :2008-11 on Background: JavaScript quick contacts for two years. From the start of her full of curiosity, and now a lot of study about Her framework. Friend ask me: there are so many framewor
-
JavaScript is an object-oriented MVC-based framework for the implementation of non-absolute [original] [add precision application]
Author: Topcss QQ: 419074376 E-mail: andpai1.0 @ gmail.com Time :2009-03-08 Just look at JavaEye News Monthly - January 2009 - No. 11 overall, he saw a surprise, there is JS-based implementation of the MVC framework, because should not the Internet ( ...
-
Use javascript to calculate the accuracy of floating-point problem
AJAX applications become more widespread today, occasionally the use of javascript for some floating point calculation. Try a bit today and found a very interesting question. In fact, this problem with java is the same as the problem is the accuracy ...
-
Rails caused by the speed of Session storage problem
At. / Config / environment.rb to remove the following Note: Session storage allows the use of active_record_store way to test a very simple request: After testing will: Comment out this sentence, and then test the method. Same deployment, the same pr ...
-
Web safety test of cross-site request forgery (CSRF) articles (Figure)
Cross-site request forgery (ie, CSRF) has been referred to as Web security sector number of loopholes in the "sleeping giant", and its level of threat which "reputation" will be shown. This article will briefly explain the loopholes, a
-
"Layman's language and Ext JS" 2.19 First National
"Layman's language and Ext JS" 2.19 First National "Layman's language and Ext JS" Since self-selection project, and at JavaEye Garden blog Well-known techniques, such as the community has attracted wide attention and a strong r
-
Ext common problem of summing up
scripts / ext / resources / css / ext-all.css / / EXT generic CSS, contains all the style (must) scripts / ext / resources / css / icon.css / / custom menu item or other storage page icon scripts / utils / HiTRUST-CMS.css / / old version of the payment sy
-
In the Windows platform using Apache2.2 and Mongrel running Ruby on Rails
First, install Ruby, rails, mongrel and Apache2.2 Rubyforge download from the web site One-Click Ruby Install, run setup on installed ruby and rubygems. Run the command: gem install rails-y gem install mongrel-y gem install mongrel_service-y Installed rai
-
How to do a good job in the demand for change management - needs to change flow specification
Project Leader: assessment needs to change some of the workload to determine whether it needs to change the contents of the progress on the development of an impact, if the demand to change the progress of an impact on the development, the project le ...












