Implementation of Tomcat load balancing with Nginx reverse proxy in Centos6.5 system

Source: Internet
Author: User
Tags openldap nginx reverse proxy

    1. View the kernel and system parameters and versions of the current system.

[Email protected] ~]# uname-alinux node1 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 03:15:09 UTC-x86_64 x86_64 x86_64 Gnu/linux[[email protected] ~]# Cat/etc/issuecentos release 6.5 (Final) Kernel \ r on an \m

2. Install Nginx.

1) Install the GCC compiler and related tools and dependent libraries.

[Email protected] ~]# yum-y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype Freetype-dev El libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel Curl Curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel OpenSSL openssl-devel openldap openldap-devel NS S_ldap openldap-clients openldap-servers Pcre

2) Compile and install the Pcre library.

PCRE (perl Compatible Regular Expressions) is a Perl library that includes regular Perl-compatible expressions. The main function of Pcre is to make Nginx support HTTP rewrite module.

Creates a directory that specifies the placement of the compressed package.

[[email protected] ~]# mkdir-p/taokey/tools[[email protected] ~]# cd/taokey/tools/[[email protected] tools]# TAR-ZXF p Cre-8.33.tar.gz[[email protected] pcre-8.33]#/configure[[email protected] pcre-8.33]# make && make install[[ Email protected] nginx-1.5.8]#/configure--with-http_stub_status_module--with-http_ssl_module--prefix=/data/ Nginx[[email protected] nginx-1.5.8]# make && make install

Note: The installation successfully started Nginx, you may encounter the following error,

[Email protected] nginx-1.5.8]#/data/nginx/sbin/nginx-t/data/nginx/sbin/nginx:error while loading GKFX libraries: Libpcre.so.1:cannot open Shared object file:no such file or directory

Workaround:

[Email protected] ~]# cd/lib64/[[email protected] lib64]# ln-s libpcre.so.0.0.1 libpcre.so.1

3) Start Nginx again to see the next process and port.

[[Email protected] lib64]# /data/nginx/sbin/nginx -tnginx: the configuration  file /data/nginx/conf/nginx.conf syntax is oknginx: configuration file  /data/nginx/conf/nginx.conf test is successful[[email protected] lib64]# / data/nginx/sbin/nginx [[email protected] lib64]# ps -ef | grep  nginxroot      8991     1  0 16:43  ?         00:00:00 nginx: master process /data/ nginx/sbin/nginxnobody    8992  8991  0 16:43 ?         00:00:00 nginx: worker process root       8994  1907  0 16:44 pts/1    00:00:00  grep nginx[[email protected] lib64]# netstat -anpt | grep nginxtcp         0      0 0.0.0.0:80                   0.0.0.0:*                    LISTEN       8991/nginx

3. Configure the Nginx Web reverse proxy to achieve two Tomcat load balancing:

The Nginx configuration file is as follows:[[email protected] ~]# cat /data/nginx/conf/nginx.confuser  root; worker_processes  1; #error_log   logs/error.log  info;pid  /data/nginx/ logs/nginx.pid;worker_rlimit_nofile 65535;events {    use epoll;     worker_connections 65535;    multi_accept on;} http {    include       mime.types;     default_type  application/octet-stream;    charset    utf-8;    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  logs/access.log   main;    sendfile       on;     tcp_nopush     on;    keepalive_timeout  60;     server_tokens  off;    limit_rate_after 3m;     limit_rate 512k;     tcp_nodelay on;     client_header_buffer_size 256k;    large_client_header_buffers 4 256k ;        # define nginx proxy module         proxy_http_version 1.1;         proxy_connect_timeout 60;        proxy_read_timeout 60;         proxy_send_timeout 60;        proxy_ buffer_size   16k;        proxy_buffers        4 64k;        proxy_busy_buffers_ Size     128k;        proxy_temp_file_write_ size 128k;        proxy_headers_hash_max_size 51200;         proxy_headers_hash_bucket_size 6400;      # Define Gzip compression module    gzip on;     gzip_vary on;    gzip_min_length  1k;     gzip_buffers    &Nbsp;4 16k;    gzip_http_version 1.0;    gzip_comp_level  2;    gzip_types       text/plain  application/x-javascript text/css application/xml;    # define  realserver pool    upstream  taokey.com {         ip_hash;        server 192.168.1.15:8080   max_fails=0  weight=5;        server  192.168.1.19:8080  max_fails=0  weight=5;   }    server  {        listen       80;         server_name  taoyake.cn www.taoyake.cn;         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_pass  http://taokey.com;                 expires 1d;                  access_log   logs/host.access.log  main;        }        &nbSp;       # define 404 502 503 504 error  page        error_page   404               /404.html;         error_page   500 502 503 504  /50x.html;         location = /50x.html {             root   html;         }    }}


This article from the "Years in the passing, shining still in" blog, please be sure to keep this source http://taokey.blog.51cto.com/4633273/1615547

Implementation of Tomcat load balancing with Nginx reverse proxy in Centos6.5 system

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.