Basic Environment:
redis-2.8
apache-tomcat-6.0.41
nginx1.6.2
1,redis configuration 1, configuring the Redis access password
Find the redis.conf in the Redis directory and unpack the Requirepass comment (this property is used to set the password).
Such as:
Requirepass Root
2, Start Redis
Start Redis in a way that Redis's directory is running
Redis-server/root/redis-2.8.9/redis.conf &
2,tomcat Preparing for Work 1, preparing the Tomcat application server
Deploy an app to Tomcat that will contain the files that need to be statically processed, such as IMG, stored separately under a folder, such as static. Store user-generated media files in a common directory, such as/data/media. After the use of Nginx configuration processing.
2, add Tomcat and Redis to do session shared jar package
Adding the jar packages required for session sharing under Tomcat's own LIB requires attention to the version of Tomcat.
Commons-pool-1.6.jar
Jedis-2.1.0.jar
Tomcat-redis-session-manager-1.2-tomcat-6.jar
3. Modify the Context.xml configuration of Tomcat
Locate the Context.xml profile in the Conf directory of Tomcat and add it under tags <Context>:
<!--using Redis for session sharing--
<Valve classname="com.radiadesign.catalina.session.RedisSessionHandlerValve" />
<Manager classname="Com.radiadesign.catalina.session.RedisSessionManager"
host="127.0.0.1"
port="6379"
password="Root"
database="0"
maxinactiveinterval="3600"/>
The provided configuration does not have the Password property by default. We can view the Tomcat-redis-session-manager-1.2-tomcat-6.jar source code, the password attribute that can be found in Redissessionmanager.class. get "" SPRINGMVC integrated mybatis Framework source code Bootstrap
650) this.width=650; "Src=" http://img.blog.csdn.net/20141221162759241?watermark/2/text/ ahr0cdovl2jsb2cuy3nkbi5uzxqvc29pbg92ztc=/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/dissolve/70/gravity/ Center "style=" border:0px; "/>
4. Copy Tomcat to modify the ports for each tomcat
After configuring the Tomcat and Redis shared configuration, we can copy this tomcat to multiple copies and then modify the Tomcat port, for example:
Tomcat1:server port= "8005", Connector port= "8080", AJP Connector port= "8009"
Tomcat2:server port= "8006", Connector port= "8081", AJP Connector port= "8010"
Tomcat3:server port= "8007", Connector port= "8082", AJP Connector port= "8011"
3,nginx configuration 1, annotations default access
In the Ngix nginx/conf.d/there is a default.conf, will be inside the listen default_server to:
Listen 80;
2, add the application server that needs the load
Create a conf in the nginx/conf.d/of Ngix, such as test.conf. Add the upstream pool configuration section inside, and fill in the following addresses for each server that needs to be loaded:
Upstream pool{
Server 127.0.0.1:8080;
Server 127.0.0.1:8081;
Server 127.0.0.1:8082;
}
3, configure access domain name
Continue to add in test.conf:
server {
Listen default_server;
server_name www.test.cn;
gzip on;
Gzip_min_length 1k;
Gzip_buffers 4 16k;
Gzip_http_version 1.0;
Gzip_comp_level 2;
Gzip_types text/plain application/x-javascript text/css application/xml;
Gzip_vary on;
Location/{
Proxy_set_header Host $host;
Proxy_set_header x-forwarded-for $remote _addr;
Proxy_connect_timeout 3;
Proxy_send_timeout 30;
Proxy_read_timeout 30;
Proxy_pass Http://pool;
}
Error_page 502 503 504/50x.html;
Location =/50x.html{
Root/home/workspace/server/apache-tomcat-6.0.41-8080/webapps/test;
}
if ($host! = ' www.test.cn ') {
Rewrite ^/(. *) $ http://www.test.cn/$1 permanent;
}
}
4. Configure static resource access
server {
Listen 80;
server_name static.test.cn;
location/static {
Root/home/workspace/server/apache-tomcat-6.0.41-8080/webapps/test;
}
Location/media {
Root/home/workspace/file;
}
}
5. Modify the size of the request body
Adding the Client_max_body_size property to http {}, this property affects a lot of places, such as uploading.
Client_max_body_size 100m;
4, start Nginx and Tomcat, test
Test Load Balancing:
Start Nginx and all Tomcat, then log in to the Web page, and then start another tomcat and close the previous one. See if you can still access it. Turn on all Tomcat tools to launch a large number of requests to see if the request was distributed to each tomcat.
Test session Sharing:
Start Nginx and a tomcat, then log in to the Web page, then start another tomcat and close the previous one. Check to see if you are still logged in.
Nginx-tomcat load balancing redis-session sharing, static resource separation