http--tomcat--memcached配置

來源:互聯網
上載者:User

標籤:memcached   cached   uri   環境   lang   eve   ext   yum   client   

兩個tomcat節點:172.16.100.7(tomcatA.magedu.com),172.16.100.8(tomcatB.magedu.com)

兩個memcached節點:172.16.100.9, 172.16.100.10

一個負載平衡節點:172.16.100.6

Clients-->172.16.100.6-->(tomcatA, tomcatB)

與tomcat結合,將會話存在memcached中

1 安裝memcached 

yum  install   memcached  -y

啟動memcached服務

2 配置tomcat

  1 安裝tomcat 和jdk

  2  將對應的類檔案複製到tomcat類檔案中

下載如下jar檔案至各tomcat節點的tomcat安裝目錄下的lib目錄中,其中的${version}要換成你所需要的版本號碼,tc${6,7,8}要換成與tomcat版本相同的版本號碼。

memcached-session-manager-${version}.jar   2.1.1

memcached-session-manager-tc${6,7,8}-${version}.jar   tc7-2.1.1

 spymemcached-${version}.jar     2.1.1

msm-javolution-serializer-${version}.jar    2.1.1

 javolution-${version}.jar

放在/usr/share/java/tomcat/

 

memcached-session-manager項目地址,

http://code.google.com/p/memcached-session-manager/,

https://github.com/magro/memcached-session-manager

 

分別在兩個tomcat上的某host上定義一個用於測試的context容器,並在其中建立一個會話管理器,如下所示:

 

  <Context path="/test" docBase="/usr/local/tomcat/webapps/test" reloadable="true">

        <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"

               memcachedNodes="n1:172.16.100.9:11211,n2:172.16.100.10:11211"

                failoverNodes="n1"

                requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"

         transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"

              />

      </Context>

分別為兩個提供測試頁面

tomcatA:

# mkdir -pv /usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}

# vim /usr/local/tomcat/webapps/test/index.jsp

<%@ page language="java" %>

<html>

  <head><title>TomcatA</title></head>

  <body>

    <h1><font color="red">TomcatA.magedu.com</font></h1>

    <table align="centre" border="1">

      <tr>

        <td>Session ID</td>

    <% session.setAttribute("magedu.com","magedu.com"); %>

        <td><%= session.getId() %></td>

      </tr>

      <tr>

        <td>Created on</td>

        <td><%= session.getCreationTime() %></td>

     </tr>

    </table>

  </body>

</html>

tomcatB:

# mkdir -pv /usr/local/tomcat/webapps/test/WEB-INF/{classes,lib}

# vim /usr/local/tomcat/webapps/test/index.jsp、

<%@ page language="java" %>

<html>

  <head><title>TomcatB</title></head>

  <body>

    <h1><font color="blue">TomcatB.magedu.com</font></h1>

    <table align="centre" border="1">

      <tr>

        <td>Session ID</td>

    <% session.setAttribute("magedu.com","magedu.com"); %>

        <td><%= session.getId() %></td>

      </tr>

      <tr>

        <td>Created on</td>

        <td><%= session.getCreationTime() %></td>

     </tr>

    </table>

  </body>

</html>

在172.16.100.6上配置反向 Proxy的負載平衡內容,類似如下所示:  http

在設定檔中添加  vim  ./conf.d/ilinux.conf

<Proxy balancer://tomcat>

    BalancerMember  http://172.16.100.7:8080 loadfactor=1

    BalancerMember  http://172.16.100.8:8080 loadfactor=1

    ProxySet  lbmethod=byrequests

</Proxy>

 

ProxyVia Off

ProxyRequests Off

ProxyPass / balancer://tomcat/

ProxyPassReverse / balancer://tomcat/

<Proxy *>

          Order Allow,Deny

          Allow From all

</Proxy>

 

<Location />

          Order Allow,Deny

    Allow From all

</Location>

啟動http服務

訪問:測試結果,在瀏覽器中訪問http://172.16.100.6/test,結果如下所示,其session ID在負載平衡環境中保持不變。

 

http--tomcat--memcached配置

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.