nginx+tomcat+memcached Load Balancer Configuration complete process (multi-party summary, pro-Test available)

Source: Internet
Author: User
Tags uuid

nginx+tomcat+memcached Load Balancer Configuration complete process:


Objective:


Nginx realizes The load balance of Tomcat and uses memcached to realize session sharing.



    1. Configure TOMCAT,JDK First

Put jdk,Tomcat into the site /opt directory

Installing the JDK

Cd/optchmod 755 jdk-6u45-linux-x64-rpm.bin./jdk-6u45-linux-x64-rpm.binjava-version//Inspection version

Installing Tomcat

TAR-ZXF apache-tomcat-6.0.45.tar.gz CD apache-tomcat-6.0.45/bin chmod 755 startup.sh./startup.sh


To install the jar Package:

Paste directly into the Tomcat file lib directory

Jar Package See attachment


Here is the method of installing jdk1.7,1.8, we use JDK 1.8 So we can also provide JDK version 1.8,JDK 1.7 to the official website can be

J DK 1.7,JDK 1.8

RPM-IVH jdk-7u80-linux-x64.rpm RPM-IVH jdk-8u77-linux-x64.rpm


Tomcat Log Status

Tail-f/opt/apache-tomcat-6.0.45/logs/catalina.out


Note:

Proceed to this step: then we first open tomcat

http://localhost:8080///localhost refers to your current IP address.

Confirmation page can appear Tom Cat, prove the success of the launch,

Focus: Now take a snapshot, named Tomcat


So:

2. Installing Nginx


1. Yum Install epel-release 2.   Yum install Nginx 3. Turn off SELinux vi/etc/selinux/config #改为 selinux=disabled 4. Service Nginx Start//start service Nginx restart//Restart service Nginx status//View status


Note:

Proceed to this step: then we first open tomcat

http://localhost:8080///localhost refers to your current IP address.

Then remove: 8080 that is: http://localhost/

Confirmation page can appear written with Nginx, prove the success of the start,

Focus: Now take a snapshot, named Nginx



So:

3.Memcached Installation:

Yum install-y telnetyum install-y memcached service memcached start//start service memcached restart//Restart service me mcached Status//view state


Note:

Proceed to this step: then we first open tomcat

http://localhost/(note no 8080)

Confirm that the page is still tomcat rather than nginx, proving that the launch was successful,

Focus: Take a snapshot at this moment, named memcached


Final:


4. Modify The nginx.config file:

Vi/etc/nginx/nginx.conf

user  nginx;worker_processes  1;error_log  /var/log/nginx/error.log warn; pid        /var/run/nginx.pid;events {     worker_connections  2048;} http {    include       /etc/nginx/mime.types;     default_type  application/octet-stream;    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  /var/log/nginx/access.log  main;    sendfile         on;     #tcp_nopush      on;    keepalive _timeout  65;     #gzip   on;         upstream puppetmaster { server 192.168.230.128:8080;  server  192.168.230.133:8080;        }         server {                 listen 80;                 location / {                         # #设置跳转到puppetmaster负载均衡         &nbsP;                proxy_pass  http://puppetmaster;                         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;                         proxy_set_header X-Client-Verify  $ssl _client_verify;                          proxy_set_header X-SSL-Subject  $ssl _client_s_dn;                          proxy_set_header X-SSL-Issuer  $ssl _client_i_dn;                          proxy_buffer_size 10m;                         proxy_buffers 1024 10m;                          proxy_busy_buffers_size 10m;                         proxy_temp_file_write_size 10m;                          proxy_read_timeout 120;                 }location /status { stub_status on;access_log    off;allow all;}         }}


Need to pay attention here

Upstream puppetmaster {server 192.168.230.128:8080;        #server 192.168.230.133:8080; }

The two addresses here refer to your two different Tomcat addresses, #表示注销, meaning you only need to add the current Tomcat address, and another Tomcat's current address on another Tomcat

You only need to add the current Tomcat IP address to


5.

Modify Apache-tomcat-6.0.45/conf/context.xml File:


Cd/opt VI Apache-tomcat-6.0.45/conf/context.xml


Add the following to the <context></context> tag in the configuration file:

<manager classname= "De.javakaffee.web.msm.MemcachedBackupSessionManager" memcachednodes= "N1 : 192.168.230.128:11211 "sticky=" false "sessionbackupasync=" false "sessionbackuptimeout=" "Transcod" erfactoryclass= "De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory" customconverter= " De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory "/>


Need to pay attention here

Memcachednodes= "n1:192.168.230.128:11211"

This is the first Tomcat IP address as N1, where both Tomcat is configured as the first N1 address



Note 650) this.width=650; "src=" Http://img.baidu.com/hi/tsj/t_0003.gif "alt=" T_0003.gif "/> Give you a look: Here you need to completely clone the second tomcat or reinstall the above steps, and then with the above configuration, need to change the place I have commented on the above, so you have the same configuration but the IP address is different two tomcat, in addition to the configuration file Nginx.config The IP address needs to be changed.



Finally write a index.jsp to test


Index.jsp Please see attached, I will write a good index.jsp into a war package, a war packet called Bbb.war, the war package into the WebApps of Tomcat, you can directly access Http://localhost/bbb.war can be accessed as a result



650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M02/85/DF/wKioL1etN_nSHpJfAAAuegFCbBo965.png-wh_500x0-wm_3 -wmp_4-s_576943858.png "title=" qq picture 20160812104002.png "style=" Float:none; "alt=" Wkiol1etn_ Nshpjfaaauegfcbbo965.png-wh_50 "/>



So: The above results need to refresh the page, if the session is not hit, the UUID is a change, indicating that you have a problem with the configuration, please take a snapshot step by step to eliminate the problem, if the following, the page does not have a session Miss ID, while refreshing the page UUID does not change, For example, it proves that nginx+tomcat+memcached load balancer is successfully implemented



650) this.width=650; "Src=" Http://s4.51cto.com/wyfs02/M01/85/DF/wKioL1etN_mzobu8AAA6om3W6Ds006.png-wh_500x0-wm_3 -wmp_4-s_1103752742.png "title=" qq picture 20160812103958.png "style=" Float:none; "alt=" Wkiol1etn_ Mzobu8aaa6om3w6ds006.png-wh_50 "/>

Failure please return snapshot step by step error 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0004.gif "alt=" J_0004.gif "/> Additional attachments uploaded to Nginx+ tomcat+memcached Load Balancer Configuration attachment 650) this.width=650; "src=" Http://img.baidu.com/hi/tsj/t_0022.gif "alt=" T_0022.gif "/>


This article from the "Inside" blog, reproduced please contact the author!

nginx+tomcat+memcached Load Balancer Configuration complete process (multi-party summary, pro-Test available)

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.