Lab-bill-sys_nginxtomcatloadbalance

Source: Internet
Author: User
Tags openssl openssl library domian

Nginx Load Balancer Tomcat and implement reverse proxy

dependent packages are pre-installed into the /local Drive

1. Gzip module requires zlib library

2. Rewrite module requires Pcre library

3. SSL support requires OpenSSL library

4.nginx

Download the source Package

1. wgethttp://www.openssl.org/source/openssl-1.0.0l.tar.gz

2. wgetftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.bz2

3. wgethttp://www.zlib.net/zlib-1.2.8.tar.gz

4. wgethttp://nginx.org/download/nginx-1.6.0.tar.gz

5. wgethttp://labs.frickle.com/files/ngx_cache_purge-2.0.tar.gz

Tar xzvf nginx-1.6.0.tar.gz

CD nginx-0.8.30

./configure–prefix=/local/nginx--add-module=/local/ngx_cache_purge--with-openssl=/local/openssl--with-pcre=/ Local/pcre--with-zlib=/local/zlib--with-http_stub_status_module--with-http_ssl_module

Make

Make install

VI nginx.conf

User nobody;

Worker_processes 1;

PID Logs/nginx.pid;

Worker_rlimit_nofile 65535;

Events {

Use Epoll;

Worker_connections 65535;

}

HTTP {

Include Mime.types;

Default_type Application/octet-stream;

Log_format Main ' $remote _addr-$remote _user[$time _local] '

' "$request _method$scheme://$host $request_uri $server _protocol" $status $body _bytes_sent '

' "$http _referer" "$http _user_agent";

Server_names_hash_bucket_size 128; # Specify the server name hash table box size

Client_header_buffer_size 32k;

Large_client_header_buffers 4 128k; # above two is the header buffer size to set the client request , should increase the value of the request for larger cookie content. (414 or error)

Client_max_body_size 8m; # Maximum number of single-file bytes allowed for client requests

Client_body_buffer_size 32k; # Buffer proxy buffers The maximum number of bytes requested by the client, which can be understood to be saved locally and then passed to the user

Proxy_connect_timeout 600; #nginx with backend server connection time-out ( proxy connection timed out )

Proxy_read_timeout 600; # Back -end server response time after successful connection ( proxy receive timeout )

Proxy_send_timeout 600; # Back-end server data backhaul time ( proxy send timeout )

Proxy_buffer_size 32k; # Set the proxy server (nginx) to save the user header information buffer size

Proxy_buffers 4 32k; #proxy_buffers Buffer, the average page is below 32k, so set

Proxy_busy_buffers_size 64k; # buffer size under high load (proxy_buffers*2)

Proxy_temp_file_write_size 1024m; # Set the cache folder size, greater than this value, will be sent from the upstream server # recursive request, without buffering to disk

Proxy_ignore_client_abort on; # do not allow the proxy to actively close the connection

Sendfile on;

Tcp_nopush on;

Keepalive_timeout 65;

Tcp_nodelay on;

gzip on;

Gzip_min_length 1k;

Gzip_buffers 4 16k;

Gzip_http_version 1.0;

Gzip_proxied any; # The front end is squid case to add this parameter, otherwise squid does not cache gzip file

Gzip_comp_level 2;

Gzip_types text/plain application/x-javascript text/css application/xml;

Gzip_vary on;

Server_tokens off;

Proxy_temp_path/cache/proxy_temp_path;

Proxy_cache_path/cache/proxy_cache_path levels=1:2 keys_zone=cache_one:200minactive=1d max_size=30g;

Note: the path specified by Proxy_temp_path and Proxy_cache_path must be in the same partition

Upstream My_server_pool {

Ip_hash;

Server 10.0.0.51:8080;

Server 10.0.0.52:8080;

}

server {

Listen default;

server_name _;

return 500;

Access_log off;

}

server {

Listen 80;

server_name davy.domian.com davymail.domian.com davydb.domian.com davyhadoop.domian.com;

Access_log Logs/access.log;

Location/{

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for $proxy _add_x_forwarded_for;

Proxy_set_header x-forwarded-for$remote_addr;

Proxy_pass Http://my_server_pool;

Expires 12h;

}

# extensions to the static file cache ending with. gif,. jpg,. CSS, and so on.

Location ~.*\. (GIF|JPG|JPEG|PNG|BMP|SWF|JS|CSS) $ {

Proxy_next_upstream http_502 http_504 errortimeout invalid_header;# If the backend server returns 502,504, execution timeout, and so on , the request is automatically forwarded to another server in the upstream load balancer pool for failover.

Proxy_cache Cache_one; # caching, using the Web Cache Cache_one

Proxy_cache_valid 304 12h; # set different cache times for different HTTP status codes

Proxy_cache_valid 301 302 1m;

Proxy_cache_valid any 1m;

Proxy_cache_key$host$uri$is_args$args; # The key value of the Web cache is combined with the domain name,URI, and Parameters , andthe cache content is stored in the level two cache directory , based on the hash of the key value.

Proxy_set_header Host $host;

Proxy_set_header X-real-ip $remote _addr;

Proxy_set_header x-forwarded-for$remote_addr;

Proxy_set_header accept-encoding "None"; # set proxy_set_headeraccept-encoding '; (or the backend server shuts down gzip) so that the machine does not cache the compressed files, causing garbled

#proxy_set_header accept-encoding ""; This can also be

Proxy_ignore_headers "Cache-control" "Expires"; # This configuration plus,Proxy_cache will be able to support the background settings of the expires.

Proxy_pass Http://my_server_pool;

Expires 1h;

}

# Dynamic applications with the extension ending in. php,. JSP,. CGI are not cached.

Location ~. *\. (php|jsp|cgi)? $ {

Proxy_set_header Host $host;

Proxy_set_header x-forwarded-for$remote_addr;

Proxy_pass Http://my_server_pool;

}

Location ~ ^/nginxstatus {

Stub_status on;

Access_log off;

if (-D $request _filename) {

Rewrite ^/(. *) ([^/]) $/HTTP $host/$1$2/permanent;

}

}

Location ~ ^/(Web-inf)/{

Deny all;

}

# setting allows only the specified IP or IP segment to clear the URL cache.

Location ~/purge (/.*) {

Allow 127.0.0.1;

Allow 10.0.0.0/16;

Allow all;

Proxy_cache_purge Cache_one$host$1$is_args$args;

}

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

}

}

Tomcat Other Configurations

Location ~. *.jsp$ # all JSP pages are referred to Tomcat for processing

{

Index index.jsp;

Proxy_pass http://localhost:8080;# turn Tomcat handling

}

Location ~. *\. (gif|jpg|jpeg|png|bmp|swf) $ # set access static files directly read without Tomcat

{

Expires 30d;

}

Location ~. *\. (JS|CSS)? $

{

Expires 1h;

}

Manage Nginx

#/usr/local/nginx/sbin/nginx-t

#/usr/local/nginx/sbin/nginx

#ps-ef | grep "Nginx:masterprocess" | Grep-v "grep" | Awk-f ' {print $} '

#/usr/local/nginx/sbin/nginx-s stop

#kill-hup PID

#kill-hup ' Cat/local/nginx/logs/nginx.pid '

Today the company wants to build a set of integrated environmentNl-tmssystem, aOracledatabase, two xTomcatnode throughWarpackage deployment, and then goApacheof theAJPprotocol agent, toNetScalerof theTCPlink Map to the public network toposemachine Access, internal throughVIPAccess Management background. The later optimization willOraclemadeRAC,Guide the development and modification of source code, access to the engineering platform, to achieve automatic upgrade and management.

Hard day, to catch the week 51 group of foodie colleagues called to eat hot pot

finish the document very late, and despite the intensity of the work each day, I would like to make progress with you. Hehe every day adhere to progress a little, insist on sharing a little.

follow up the other modules, what is the problem please do not mean to point out, together to improve. So far our common,service,application modules have all been completed, Of course, the follow-up will have some in-depth supplement, welcome everyone and the technical enthusiasts join our QQ Group 262407268, build our "Chinanetcloud Smart city"

At present, has completed three relatively small modules: common, service, application in fact, to achieve high performance inside there is a lot of content to learn to accumulate, follow-up will do to supplement. Next we should share the Data Warehouse section, first relational database Oracle, MySQL and then non-relational database mogondb, Redis, hbase, finally we open the path of distributed computing Hadoop, mainly for data analysis and processing. Here we will mention a collection of the production of the engine: sphinx+ Chinese word coreseek, will also do a log analysis of the architecture Splunk products. Together to build our "Chinanetcloud smart city".
Please consciously revise the notes, thank you. Affirm that this group is a community of public welfare, we are willing to undertake some architectural design, construction and consulting business, for you and your business to improve the business structure.


This article is from the "Davideylee" blog, make sure to keep this source http://davideylee.blog.51cto.com/8703117/1440443

Lab-bill-sys_nginxtomcatloadbalance

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.