Tomcat+redis+nginx configuration

A performance system developed for a client adopts the development method of java web and some frameworks such as spring mvc and mybatis. Compared with the secondary development of oracle ebs, this kind of development is more flexible. Although some problems were encountered when integrating with ebs, they were finally solved.

At the time of deployment, the customer required that colleagues should be able to bear one or two thousand people online, which should be enough relative to the total number of customers in the company (70,000 to 80,000 people). The second time of ebs is directly deployed on the application server of oracle ebs, and I have not paid much attention to the deployment of the program before. This time, the tomcat is deployed. Considering that a single tomcat can withstand about 500 online users, this time a small cluster deployment is adopted, 5 tomcats are used, and nginx is used by the reverse proxy.

Now the program is basically stable, and there are no major problems in the stress test. Take advantage of the time to sort out the deployment and configuration.

Prepare

apache tomcat 7.0.55

nginx 1.7.2

redis 2.8.9

The configuration environment uses three tomcats, three tomcats, redis and nginx are all on one machine, in order to facilitate testing and deployment.

Roughly the entire configuration architecture:

tomcat-nginx-redis

In this figure, nginx acts as a reverse proxy, randomly assigning client requests to three tomcat servers according to their weights, and redis acts as a shared session data server for three tomcats.

planning

say again

localhost:6379

nginx

localhost:80

tomcat

localhost:8081
localhost:8082
localhost:8083

configure

tomcat

Modify the conf/context.xml file in the tomcat folder and add the following configuration under the context node:

<Valve  className="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager className="com.radiadesign.catalina.session.RedisSessionManager"
     host="localhost" 
     port="6379"
     database="0" 
     maxInactiveInterval="60" />

The ports in the conf/server.xml file are modified sequentially according to the plan.

In addition, you need to add three jar files to the lib folder of tomcat. The versions of the jar files in this place may conflict. You need to try more when configuring. The version I have here is as follows, which has been verified to be available, and can be downloaded through the maven library.

tomcat-redis-session-manager-1.2-tomcat-7.jar

jedis-2.2.0.jar

commons-pool-1.6.jar

nginx

Modify the conf/nginx.conf file in the nginx file directory to:

#user  nobody;
worker_processes  1;

error_log  logs/error.log;

pid        logs/nginx.pid;

events {
	worker_connections  1024;
}


http {
	include       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  logs/access.log  main;

	sendfile        on;
	#tcp_nopush     on;

	#keepalive_timeout  0;
	keepalive_timeout  65;

	#gzip  on;

	upstream  localhost   {  
          server   localhost:8081 weight=1;  
          server   localhost:8082 weight=2;  
		  server   localhost:8083 weight=3; 
	}  

	server {
    	listen       80;
    	server_name  localhost;

    	#charset koi8-r;

    	#access_log  logs/host.access.log  main;

    	location / {
        	root   html;
        	index  index.html index.htm;
			proxy_pass        http://localhost;  
       	 	proxy_set_header  X-Real-IP  $remote_addr;  
        	client_max_body_size  100m;  
    	}

    	#error_page  404              /404.html;

    	# redirect server error pages to the static page /50x.html
    	#
    	error_page   500 502 503 504  /50x.html;
    	location = /50x.html {
        	root   html;
    	}

	}
}

The configuration of redis directly uses the default configuration, because it is only for testing, and there is no parameter optimization configuration like tomcat.

run

Start redis, nginx and three tomcats respectively.

say again

nginx

tomcat

test

In the webapps/ROOT directory of the three tomcats, add session.jsp respectively

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>shared session</title>
</head>
<body>
	<br>session id=<%=session.getId()%>
	<br>tomcat 3
</body>
</html>

Note: The markings under each tomcat are different

tomcat

tomcat

tomcat

From the screenshot, it can be seen that different tomcats are accessed respectively, but the obtained sessions are the same, indicating that the purpose of clustering has been achieved.

 

In this architecture, there is an obvious bottleneck, which is the database. Because the enterprise-level oracle database is used, there is no major problem in the stress test. However, as a follow-up area that can be optimized, the database must be separated from reading and writing.

 

Original: http://my.oschina.net/liting/blog/535273

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326911043&siteId=291194637