Apache + multiple Tomcat + memcached shared session (Windows)

Source: Internet
Author: User

Refer:

Http://lgdvsehome.blog.51cto.com/3360656/878164

Nginx + Tomcat + memcached cluster session sharing (Windows) load balancing and cluster configuration based on mod_proxy + Apache 2.2.16 + Tomcat 7

1. Environment

Apache + 2 Tomcat + memcached servers

2. Specific Configuration

A)Modify the Apache HTTP server configuration file HTTP. conf. Load three models first. The Code is as follows:

Loadmodule proxy_module modules/mod_proxy.so
Loadmodule proxy_ajp_module modules/mod_proxy_ajp.so
Loadmodule proxy_balancer_module modules/mod_proxy_balancer.so

Add the following code at the end of the configuration file (the configuration is somewhat different from the previous article ):

Proxypass/balancer: // tomcatcluster/

Proxypassreverse/balancer: // tomcatcluster/  
  
<Proxy balancer: // tomcatcluster> 
Balancermember AJP: // localhost: 8009 route = 
Balancermember AJP: // localhost: 9009 route = B
</Proxy>

B)Next, modify the Tomcat server. xml file as follows:

<! -- Define
An AJP 1.3 connector on port 8009 -->
        <Connectorport = "8009"
                              Enablelookups= "False" redirectport = "8443" protocol = "AJP/1.3"/>

The port is the port set in the preceding <proxy> and the route is also configured. The Code is as follows:
<! -- Define the top level container in our container
Hierarchy -->
    <Enginename = "Catalina" defaulthost = "localhost" jvmroute = "A">

Jvmroute must be the same as the preceding settings.

C) Modify Tomcat's context. xml.

<Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager" memcachedNodes="n1:localhost:11211" requestUriIgnorePattern=".*/.(png|gif|jpg|css|js)$" sessionBackupAsync="false" sessionBackupTimeout="100"transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory" copyCollectionsForSerialization="false"/>

Jar package:

Memcached-2.6.jar? Name = spymemcached-2.8.4.jar)

Javolution-5.4.3.1.jar

Memcached-session-manager-1.5.1.jar

Memcached-session-manager-tc7-1.5.1.jar

Msm-javolution-serializer-1.5.1.jar

Msm-kryo-serializer-1.5.1.jar

Msm-xstream-serializer-1.5.1.jar

The above jar packages can be found at http://code.google.com/p/memcached-session-manager/downloads/list.

D)To install the memcached server, see

Http://blog.csdn.net/shuzui1985/article/details/7907889

3. Write test code

Index. jsp

<%@ page contentType="text/html; charset=GBK" %><%@ page import="java.util.*" %>

4. Test.

During the first access, the returned result shows that the attribute in the session is null and the attribute is set. At the same time, N1 indicates the node of the session on the memcached server and B indicates the Tomcat server node.

Then shut down server B, which is the default second custom server mytomcat6.

For example, if the session ID is not changed in the previous section, it is changed to a from Tomat server, but the initial setting test is read from the session attribute.

Access http: // localhost/balance again. For example, it has been accumulated.

Enable server B and access http: // localhost/balance,

All right, the above test results show that the session has achieved cluster sharing. When one of the servers goes down, failover can be implemented.

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.