歡迎您光臨本站 註冊首頁

Tomcat5.5集群配置(FOR WINDOWS)

←手機掃碼閱讀     火星人 @ 2014-03-04 , reply:0

Tomcat5.5集群配置(FOR WINDOWS)

一 安裝
下載和安裝 JRE 1.5 最新版 (1.5.07)
下載和安裝 Tomcat 最新版 (5.5.23),假定安裝目錄為 D:\Tomcat5.5
D:\Tomcat5.5 目錄下的全部內容複製到 D:\Tomcat5.5.2
二 啟動腳本
1 D:\Tomcat5.5\bin\startup.bat
"D:\Program\Java\jdk1.5.0_07\bin\java.exe" -jar .\bootstrap.jar -Dcatalina.home="D:\Tomcat5.5" -Dcatalina.base="D:\Tomcat5.5" -Djava.endorsed.dirs="D:\Tomcat5.5\common\endorsed" -Djava.io.tmpdir="D:\Tomcat5.5\temp" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="D:\Tomcat5.5\conf\logging.properties" start

2 D:\Tomcat5.5.2\bin\startup.bat
"D:\Program\Java\jdk1.5.0_07\bin\java.exe" -jar .\bootstrap.jar -Dcatalina.home="D:\Tomcat5.5.2" -Dcatalina.base="D:\Tomcat5.5.2" -Djava.endorsed.dirs="D:\Tomcat5.5\common\endorsed" -Djava.io.tmpdir="D:\Tomcat5.5.2\temp" -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.util.logging.config.file="D:\Tomcat5.5.2\conf\logging.properties" start

三 修改server.xml
1 兩台伺服器將<Engine name="Catalina" defaultHost="localhost">注視掉並改為
<!--Engine name="Catalina" defaultHost="localhost"-->
2 把 Server/Service/Engine/Host 下的 Cluster 結點前後的註釋符(<!-- 和 -->)刪除;
3 埠更改
修改新實例的伺服器配置文件 (D:\Tomcat5.5.2\conf\server.xml),把其中的 Server/Service/Connector 的埠更改,以避免和第一個衝突(8005 -> 9005 8080 -> 9080 8009 -> 9009 8443 -> 9443)
修改 Cluster/Receiver 結點的 tcpListenPort 埠(此埠用於 Session 複製),以避免和第一個衝突(4001 -> 4002)
註:Tomcat Cluster 默認使用多播來建立成員關係,即兩個實例的多播的地址和埠一樣,就可以互相認為是同一個 Cluster 的成員
四 默認tomcat訪問路徑為D:\Tomcat5.5\webapps\ROOT\index.jsp
修改D:\Tomcat5.5\webapps\ROOT\WEB-INF\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
  contributor license agreements.  See the NOTICE file distributed with
  this work for additional information regarding copyright ownership.
  The ASF licenses this file to You under the Apache License, Version 2.0
  (the "License"); you may not use this file except in compliance with
  the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
-->

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

  <display-name>TomcatDemo</display-name>
  <distributable/>

<!-- JSPC servlet mappings start -->


<!-- JSPC servlet mappings end -->

</web-app>
另外一台伺服器配置一樣

五 修改D:\Tomcat5.5\webapps\ROOT\index.jsp
<%@ page contentType="text/html; charset=gb2312" import="java.util.*"%>
<html><head><title>Cluster App Test</title></head>
<body>
Server Info: <%out.print(request.getLocalAddr() + " : " + request.getLocalPort());%>
<%
out.println("<br> ID " + session.getId());

// 如果有新的 Session 屬性設置
String dataName = request.getParameter("dataName");
if (dataName != null && dataName.length() > 0) {
  String dataValue = request.getParameter("dataValue");
  session.setAttribute(dataName, dataValue);
}

out.print("<b>Session 列表</b>");

Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
  String name = (String)e.nextElement();
  String value = session.getAttribute(name).toString();
  out.println( name + " = " + value);
  }
%>
<form action="index.jsp" method="POST">
  名稱:<input type=text size=20 name="dataName">
  <br>
  值:<input type=text size=20 name="dataValue">
  <br>
  <input type=submit>
  </form>
</body>
</html>
六 啟動兩台Tomcat伺服器,分別雙擊
D:\Tomcat5.5\bin\startup.bat
D:\Tomcat5.5.2\bin\startup.bat
七 訪問並測試
在 IE 中打開第一個實例中的 TomcatDemo (http://localhost:8080/),在 Form 里隨便設置一個 Session 屬性,如 MyName = foo
將 IE 地址欄中的地址修改為第二個實例中的 TomcatDemo(http://localhost:9080/),刷新,就可以看到注意到 SessionID 不變, MyName 的屬性值已有了
《解決方案》

樓主,請教一下:
    那用戶訪問時,肯定不可以像你這樣,輸入  地址:埠

   我想知道用戶訪問tomcat集群時,是如何指定要訪問的對象.

    是不是還要在這兩個集群伺服器前面加一個地址對應 或者轉換的設備.

[火星人 ] Tomcat5.5集群配置(FOR WINDOWS)已經有456次圍觀

http://coctec.com/docs/service/show-post-31626.html