Nginx+tomcat+memcached installation and configuration of dynamic request assignment for Web pages

Source: Internet
Author: User
Tags nginx server

         tomcat server is a free open source Web application server, which belongs to the lightweight application server , it is the first choice for developing and debugging JSP programs, which is widely used in small and medium-sized systems and concurrent access users, not many occasions.     

Memcached is a high-performance distributed memory object caching system for dynamic Web applications to mitigate database load. It improves the speed of dynamic, database-driven Web sites by caching data and objects in memory to reduce the number of times a database is read. Memcached is based on a stored key/value pairHashMap. ItsDaemon Process(daemon) is usedC But the client can write in any language and communicate with the daemon through the memcached protocol.

     iis like Web servers, with the ability to handle HTML pages, it's also a servlet and JSP container, and the standalone servlet container is the default mode for Tomcat. However, Tomcat handles static Html is inferior to Apache server.

650) this.width=650; "src=" Http://s5.51cto.com/wyfs02/M00/81/FB/wKiom1dGp4nRW7Z3AAHSsj1eFtg849.png "title=" 4.png " alt= "Wkiom1dgp4nrw7z3aahssj1eftg849.png"/>


Here we use Nginx as an HTTP server, when the external request is found in the JSP format dynamic page request, the Nginx server will request to connect to Tomcat above to perform the response, here memached as in-memory cache system is called here, Reduce the number of times the server accesses the database and increase the read speed by using the memached system.


Here the Nginx master server IP is: 172.25.9.1 host name: pt1.example.com

the IP of the two tomcat sub-servers is: 172.25.9.3 host name: pt3.example.com

172.25.9.3 Host Name: pt3.example.com

First, the configuration of the primary server:

The installation and configuration of Nginx source code is no longer described here, if necessary, please refer to http://ptallrights.blog.51cto.com/11151122/1775242


The following changes are made directly to the configuration file nginx.conf:

HTTP {

Upstream PT {#指定自定义模块名字为pt

Sticky #使用的算法为sticky

Server 172.25.9.3:8080; #一个子服务器为172.25.9.3, listening to port 8080.

Server 172.25.9.4:8080; #一个子服务器为172.25.9.4, listening to port 8080.

}

Include Mime.types;

Default_type Application/octet-stream;


Sendfile on;

Keepalive_timeout 65;

server {

Listen 80;

server_name localhost;

Location/{

root HTML;

Index index.php index.htmlindex.htm;

}

Error_page 502 503 504/50x.html;

Location =/50x.html {

root HTML;

}

Location/status {

Stub_status on;

Access_log off;

}

Location ~ \.jsp$ {

Proxy_pass http://pt; #当请求是jsp格式时, call the PT module

}

Location ~ \.php$ {

root HTML;

Fastcgi_pass 127.0.0.1:9000;

Fastcgi_index index.php;

Fastcgi_param Script_filename/scripts$fastcgi_script_name;

#fastcgi_param script_filename $document _root/$fastcgi _script_name;

Include fastcgi.conf;

}

}

server {

Listen 443 SSL;

server_name localhost;

Ssl_certificate Cert.pem;

Ssl_certificate_key Cert.pem;

Ssl_session_cache shared:ssl:1m;

Ssl_session_timeout 5m;

Ssl_ciphers high:!anull:! MD5;

Ssl_prefer_server_ciphers on;

Location/{

root HTML;

Index index.html index.htm;

}

}

server{

Listen 80;

server_name wwwnan.com alias Pt.com; #虚拟主机

Location/{

Proxy_pass http://pt;

}

}

server{

Listen 80;

server_name wwwnan1.com; #虚拟主机

Location/{

root/virualhost/wwwnan1.com;

Index index.html index.htm;

}

}

}


Most of the default parameters do not need to be changed, the main changes are as follows:

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M02/81/F9/wKioL1dGpnPSJVzyAAAm84KdQqk910.png "title=" 1.png " alt= "Wkiol1dgpnpsjvzyaaam84kdqqk910.png"/>

650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M01/81/FB/wKiom1dGpY7C8PgnAAAWuTgjk5o346.png "title=" 2.png " alt= "Wkiom1dgpy7c8pgnaaawutgjk5o346.png"/>

[Email protected] conf]# nginx-t

Nginx:the configuration file/usr/local/lnmp/nginx/conf/nginx.conf syntax is OK

Nginx:configuration file/usr/local/lnmp/nginx/conf/nginx.conf Test is successful

[Email protected] conf]# Nginx-s Reload

[Email protected] conf]# Nginx

second, under the face of two tomcat server configuration (the same steps):

to Configure Tomcat, proceed as follows:

1. Installing the JDK

SH Jdk-6u26-linux-x64.bin #安装jdk

MV jdk1.6.0_26//usr/local/lnmp/#生成的jdk目录移动至/usr/local/lnmp/

Ln-s jdk1.6.0_2 Java #做一个软连接


2. Install the Tomcat server:

Tar zxf apache-tomcat-7.0.37.tar.gz

Tar zxf apache-tomcat-7.0.37.tar.gz-c/usr/local/lnmp/

Ln-s Apache-tomcat-7.0.37/tomcat

3. Configure Environment variables

Vim/etc/profile

Export Java_home=/usr/local/lnmp/java

Exportclasspath=.: $JAVA _home/lib: $JAVA _home/jre/lib

Export path= $PATH: $JAVA _home/bin

Source/etc/profile


There are 4 official recommendations for the session's serialization scheme :

1. Java serialization

2. Msm-kryo-serializer

3. Msm-javolution-serializer

4. Msm-xstream-serializer


one of the best-performing serialization scenarios is Kryo, in this article we use the Kryo method

Place the following packages in the/usr/local/lnmp/tomcat/lib directory

Kryo-1.03.jar

Kryo-serializers-0.8.jar

Memcached-2.5.jar

Memcached-session-manager-1.5.1.jarmemcached-session-manager-tc7-1.5.1.jar

Minlog-1.2.jar

Msm-kryo-serializer-1.5.1.jar

Reflectasm-0.9.jar

Vim/usr/local/lnmp/tomcat/conf/context.xml

<Context>

......

<managerclassname= "De.javakaffee.web.msm.MemcachedBackupSessionManager"

Memcachednodes= "n1:192.168.0.91:11211,n2:192.168.0.92:11211"

failovernodes= "N1"

# on Node2 This entry is set to "n2"

Requesturiignorepattern= ". *\. (ICO|PNG|GIF|JPG|CSS|JS) $ "

Transcoderfactoryclass= "De.javakaffee.web.msm.serializer.kryo.KryoTranscoderFactory"

/>

</Context>

Tail-f Logs/catalina.out # View information

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/81/FB/wKiom1dGqNmzpi8uAAGxDYzVJs0246.png "title=" 3.png " alt= "Wkiom1dgqnmzpi8uaagxdyzvjs0246.png"/>


start Tomcat

#/usr/local/lnmp/tomcat/bin/startup.sh # Launch Tomcat service

#/usr/local/lnmp/tomcat/bin/shutdown.sh # Close Tomcat service


third, installation memcached

Yum Install Memcached-y

/etc/init.d/memcached start

This is just a simple use of the memcached service, but it is more specific to use.


Iv. test page and test

The following is the test page , saved to /usr/local/lnmp/tomcat/webapps/root/test.jsp<% @page contenttype= "text/html; CHARSET=GBK "%>

<%@ page import= "java.util.*"%>

<body>

Server Info:

<%

Out.println (REQUEST.GETLOCALADDR () + ":" + request.getlocalport () + "<br>");%>

<%

Out.println ("<br> ID" +session.getid () + "<br>");

String dataname =request.getparameter ("Dataname");

if (dataname! = null &&dataname.length () > 0) {

String datavalue =request.getparameter ("DataValue");

Session.setattribute (Dataname, DataValue);

}

Out.print ("<b>Sessionlist</b>");

Enumeration E = Session.getattributenames ();

while (E.hasmoreelements ()) {

String name = (string) e.nextelement ();

String value =session.getattribute (name). toString ();

OUT.PRINTLN (name + "=" +value+ "<br>");

SYSTEM.OUT.PRINTLN (name + "=" + value);

}

%>

<form action= "test.jsp" method= "POST" >

Name:<input type=text size=20name= "Dataname" >

<br>

Key:<input type=text size=20name= "DataValue" >

<br>

<input type=submit>

</form>

</body>


access to http://pt1.example.com/test.jsp, when different host accesses are scheduled to be processed on different Tomcat instances

requests from the same host are handled by the same Tomcat instance , where you drop the currently responding Tomcat Real

example , Nginx automatically dispatches the user's request to another Tomcat instance , and the session is not discarded.


This article is from the "ptallrights" blog, make sure to keep this source http://ptallrights.blog.51cto.com/11151122/1783496

Nginx+tomcat+memcached installation and configuration of dynamic request assignment for Web pages

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.