Tomcat Cluster +nginx+redis Service Setup

Source: Internet
Author: User

As the company's new business suddenly comes up, a single Tomcat instance can not meet the needs of business development, only by building a cluster to solve the problem. So there is the following content:

1.Redis Saving Session Information

In order to save the session information is available in the cluster, so the session information can not be saved in Tomcat, because if so, in order to realize the session information sharing must be through the session copy of the way to synchronize the session between Tomcat information, This is more laborious and performance-intensive, so choose to use Redis to save and share session information.

Installation of 1.1Redis

Many tutorials, do not repeat. (http://www.redis.cn/)

1.2Tomcat configuration Modification to save session information using Redis

Only one Redis scenario is considered below, and additional processing is required if you need to configure Redis's master-slave and cluster.

1.2.1context.xml Modifications (located under the Conf directory)
 <  valve  classname  = "Com.radiadesign.catalina.session.RedisSessionHandlerValve"  />  <  manager  classname  = "Com.radiadesign.catalina.session.RedisSessionManager"  Span style= "color: #ff0000;" > host  = "localhost"   Port= "6379"   database  = "0"   Maxinactiveinterval  = " />  

The classname in the above configuration file needs to be consistent with the path information of the Tomcat-redis-session-manager package, which can be obtained via GitHub (https://github.com/jcoleman/ Tomcat-redis-session-manager), the package gets itself, not obtained from the MAVEN repository.

1.2.2server.xml Modifications (located under the Conf directory)

Modify the service listener and shutdown ports.

1.3 Required Jar package files (placed in the Lib directory below Tomcat)

As you can see from the GitHub address above, Tomcat-redis-session-manager, Redis's client Operations tool Jedis, and commons-pool2 support are also required. But the actual operation process found also need commons-logging-1.2\commons-pool-1.6, tomcat-juli-7.0.69 support. Note the corresponding version information problem, if the Jedis version information is too high error, the following is my corresponding JAR package list.

2.Tomcat Cluster deployment

2.1 You can first simply test whether the above Tomcat information has completed the session information is saved in Redis. Very simple, write a page after the successful, print out the corresponding session information, shut down Tomcat Restart in this visit, to determine whether the session information is consistent, it is consistent that the session information was successfully saved in the Redis, otherwise there is no

2.2 Copy multiple of the above Tomcat, and change the corresponding service port number information

3.Nginx

Because there are multiple instances of Tomcat, in order for each instance to be able to serve normally, a unified request processing portal is required, and then the service is processed by request distribution, that is, load balancing and forwarding. Because of some other special needs, to ensure that each service and IP relationship, through the Ip_hash as a load balancing policy processing.

Installation of 3.1Nginx (CentOS)

First step: Download the stable version of Nginx, unzip

Step two: yum-y install gcc gcc-c++ make libtool zlib zlib-devel OpenSSL openssl-devel pcre pcre-devel

Step three: Enter the unzip directory./configure--with-http_ssl_module

Fourth step: Make & make install

You can refer to the article (http://www.cnblogs.com/skynet/p/4146083.html)

3.2Nginx responsible for balanced configuration 3.2.1 Find the installation path of Nginx (default):/usr/local/nginx 3.2.2 Modify the configuration file conf/nginx.conf
   #设定负载均衡的服务器列表ip_hash     Upstream Backend {        server 127.0.0.1:8080;        Server 127.0.0.1:8081;        Server 127.0.0.1:8082;        Server 127.0.0.1:8083;        Ip_hash;   }
        Listen       ;        server_name  localhost;        #charset Koi8-r;        #access_log  logs/host.access.log  main;        Location/{            root   html;            Index  index.html index.htm;            Proxy_pass http://backend;        }

The use of Nginx configuration files is not explained here. The first configuration needs to indicate the load server address and the use of a load balancing policy.

4. Provision of services

4.1 Starting the Redis service

4.2 Putting the service to start Tomcat one by one

4.3 Start nginx Service

4.4 Services are available as normal.

5. Improvements and explanations

This is just to provide a simple idea and implementation of building a tomcat cluster, there are a lot of perfect places, for the high availability and stability of the service need to do a lot of work, will later add the service slowly.

Tomcat Cluster +nginx+redis Service Setup

Related Article

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.