linux tomcat叢集配置筆記

來源:互聯網
上載者:User

趁最後一天假期,配置linux環境下的apache叢集,鞏固下,免的以後用到又忘記,網上東拼息湊,環境弄好後,整到blog,以便以後用到。

參考來源:http://www.linuxidc.com/Linux/2011-03/32859.htm

我用的版本:

httpd-2.2.21.tar.gz

apache-tomcat-6.0.32.tar.gz

jdk-6u26-linux-i586.bin

jdk,和tomcat 環境配置忽略

a.在 /opt目錄新增apache目錄並將httpd-2.2.21.tar.gz copy到改目錄中.

cd /opt 

mkdir apache

tar zxf  httpd-2.2.21.tar.gz 

cd httpd-2.2.21

然後配置 httped prefix

./configure --prefix=/opt/web/apache2 --enable-mods-shared=most # --prefix後面的紅色路徑可以根據實際情況自訂

然後螢幕會顯示一大堆配置資訊,完成後

make #開始編譯

make install #編譯後,進入安裝階段

cd /opt/solft/apache2/bin

./apachectl -k start #啟動apache服務 

如果如下提示資訊,代表成功了

httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName

在瀏覽器中輸入http://127.0.0.1/ 就可以看到 It works!b.開始安裝 mod_proxy.so和mod_proxy_ajp.so,mod_proxy_balancer.so模組cd /opt/apache/httpd-2.2.21/modules/proxy/opt/web/apache2/bin/apxs -i -a -c mod_proxy.c proxy_util.c/opt/web/apache2/bin/apxs -i -a -c mod_proxy_ajp.c ajp*.c/opt/web/apache2/bin/apxs -i -a -c mod_proxy_balancer.cc.配置httpd.confvim /opt/web/apache2/conf/httpd.confProxyPass /images ! ProxyPass /css ! ProxyPass /js !

ProxyRequests Off
ProxyPass /examples balancer://mycluster/ stickysession=JSESSIONID

ProxyPassReverse /examples balancer://mycluster/ stickysession=JSESSIONID
<Proxy balancer://mycluster>
     BalancerMember ajp://192.168.1.102:8009/examples/ route=worker1 loadfactor=1

     BalancerMember ajp://192.168.1.102:8909/examples/ route=worker2 loadfactor=1

</Proxy>
SetHandler balancer-manager

#上面ip連接埠紅色部分與apache-tomcat-x.x.x/config/server.xml  中<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 中的連接埠保持一直

d.編輯tomcat1/apache-tomcat-6.0.32/config/server.xml

server.xml檔案,如果tomcat在不同機器上,則不需要修改,本人環境是本機上測試.所以其中的一個tomcat的連接埠一定要修改

需要修改的地方(紅色部分)

<Connector port="8080" protocol="HTTP/1.1"
             connectionTimeout="20000"
             redirectPort="8443" />

<Server port="8005" shutdown="SHUTDOWN">

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

把這段資訊<Engine name="Catalina" defaultHost="localhost"/>

用下面的配置資訊覆蓋,如果在本機中紅色連接埠需要修改,jvmRoute參數不能一樣

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1"/>

 <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster" channelSendOptions="8">
          <Manager className="org.apache.catalina.ha.session.DeltaManager"
                   expireSessionsOnShutdown="false"
                   notifyListenersOnReplication="true"/>

          <Channel className="org.apache.catalina.tribes.group.GroupChannel">
            <Membership className="org.apache.catalina.tribes.membership.McastService"
                        address="228.0.0.4"
                        port="45564"
                        frequency="500"
                        dropTime="3000"/>
            <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                      address="192.168.1.102"
                      port="4000"
                      autoBind="100"
                      selectorTimeout="5000"
                      maxThreads="6"/>

            <Sender className="org.apache.catalina.tribes.transport.ReplicationTransmitter">
              <Transport className="org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
            </Sender>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
            <Interceptor className="org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
          </Channel>

          <Valve className="org.apache.catalina.ha.tcp.ReplicationValve" filter=""/>
          <Valve className="org.apache.catalina.ha.session.JvmRouteBinderValve"/>

    <Deployer className="org.apache.catalina.ha.deploy.FarmWarDeployer"
                    tempDir="/tmp/war-temp/"
                    deployDir="/tmp/war-deploy/"
                    watchDir="/tmp/war-listen/"
                    watchEnabled="false"/>
          <ClusterListener className="org.apache.catalina.ha.session.JvmRouteSessionIDBinderListener"/>
          <ClusterListener className="org.apache.catalina.ha.session.ClusterSessionListener"/>
     </Cluster>

e.配置tomcat.x.x.x/webapps/examples/WEB-INF/web.xml,加上紅色部分,以支援seesion複製

在<webapp>

   ...........

.........

<distributable/>

</webapp>

最後.複製tomcat下webapps下的檔案到 /opt/web/apache2/htdocs

cp –R  /opt/web/tomcat1/apache-tomcat-6.0.32/webapps/* /opt/web/apache2/htdocs

到這裡負載平衡和session複配置已經完成

開始啟動 apache2

cd /opt/web/apache2/bin

./apachectl -k start

啟動2個tomcat

cd /opt/web/tomcat2/apache-tomcat-6.0.32/bin

./start.sh

cd /opt/web/tomcat1/apache-tomcat-6.0.32/bin

./start.sh

測試session 複製

http://192.168.1.102/examples/servlets/servlet/SessionExample

查看負載平衡

http://192.168.1.102/balancer-manager

但是有個問題,如果session有很多個物件,而對象又不停的變化,這就使得seesion會消耗很大效能.

網上查了下,可以用memcached來做緩衝應用.有時間再把這個整理下

轉自:http://www.cnblogs.com/montya/archive/2011/10/07/2190688.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.