Tomcat及Tomcat集群

Tomcat集群實現的三種方式

配置

Tomcat1

配置環境
ip a add 192.168.88.101/24 dev ens33
yum install ntpdate -y
ntpdate 172.16.0.1

安裝java
yum install java-1.8.0-openjdk-devel -y

安裝tomcat
yum install tomcat -y
yum install -y tomcat-admin-webapps tomcat-docs-webapp tomcat-webapps
mkdir /var/lib/tomcat/webapps/{ROOT,test}/{WEB-INF,META-INF,classes,lib} -pv

配置tomcat用戶認證
vim /etc/tomcat/tomcat-users.xml
    <role rolename="admin-gui"/>
    <role rolename="manager-gui"/>
    <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/>

配置頁面內容
vim /var/lib/tomcat/webapps/test/index.jsp
    <html>
            <head><title>Tomcat1</title></head>
            <body>
                    <h1><font color="blue">Tomcat1.ez.com</font></h1>
                    <table align="centre" border="1">
                            <tr>
                                    <td>Session ID</td>
                                    <% session.setAttribute("ez.com","ez.com"); %>
                                    <td><%= session.getId() %></td>
                            </tr>
                            <tr>
                                    <td>Created on</td>
                                    <td><%= session.getCreationTime() %></td>
                            </tr>
                    </table>
            </body>
    </html>

Tomcat2

配置環境
ip a add 192.168.88.102/24 dev ens33
yum install ntpdate -y
ntpdate 172.16.0.1

安裝java
yum install java-1.8.0-openjdk-devel -y

安裝tomcat
yum install tomcat -y
yum install -y tomcat-admin-webapps tomcat-docs-webapp tomcat-webapps
mkdir /var/lib/tomcat/webapps/{ROOT,test}/{WEB-INF,META-INF,classes,lib} -pv

配置tomcat用戶認證
vim /etc/tomcat/tomcat-users.xml
    <role rolename="admin-gui"/>
    <role rolename="manager-gui"/>
    <user username="tomcat" password="tomcat" roles="admin-gui,manager-gui"/>

配置頁面內容
vim /var/lib/tomcat/webapps/test/index.jsp
    <html>
            <head><title>Tomcat2</title></head>
            <body>
                    <h1><font color="blue">Tomcat2.ez.com</font></h1>
                    <table align="centre" border="1">
                            <tr>
                                    <td>Session ID</td>
                                    <% session.setAttribute("ez.com","ez.com"); %>
                                    <td><%= session.getId() %></td>
                            </tr>
                            <tr>
                                    <td>Created on</td>
                                    <td><%= session.getCreationTime() %></td>
                            </tr>
                    </table>
            </body>
    </html>

NT-Nginx環境集群

配置環境
ip a add 192.168.88.11/24 dev ens33
yum install ntpdate -y
ntpdate 172.16.0.1

安裝Nginx
yum install nginx -y

配置負載
vim /ect/nginx/nginx.conf
    upstream tcsrvs {
        server 192.168.88.101:8080;
        server 192.168.88.102:8080;
        }
    ...
        location / {
            proxy_pass http://tcsrvs;
        }
    ...

systemctl start nginx

AT-httpd-http反代集群

配置環境
ip a add 192.168.88.11/24 dev ens33
yum install ntpdate -y
ntpdate 172.16.0.1

安裝httpd-配置http協議反向代理
yum install -y httpd
vim /etc/httpd/conf.d/tc.conf
    <Proxy balancer://tcsrvs>
       BalancerMember http://192.168.88.101:8080
       BalancerMember http://192.168.88.102:8080
    </Proxy>
    <VirtualHost *:80>
       Proxyvia On
       ProxyRequests Off
       <Proxy *>
            Require all granted
       </Proxy>
       ProxyPass / balancer://tcsrvs/
       ProxyPassReverse / balancer://tcsrvs/
       <Location />
            Require all granted
       </Location>
    </VirtualHost>
systemctl start httpd

AT-httpd-ajp反代集群

配置環境
ip a add 192.168.88.11/24 dev ens33
yum install ntpdate -y
ntpdate 172.16.0.1

安裝httpd-配置ajp協議反向代理
yum install -y httpd
vim /etc/httpd/conf.d/tc.conf
    <Proxy balancer://tcsrvs>
       BalancerMember ajp://192.168.88.101:8009
       BalancerMember ajp://192.168.88.102:8009
    </Proxy>
    <VirtualHost *:80>
       Proxyvia On
       ProxyRequests Off
       <Proxy *>
            Require all granted
       </Proxy>
       ProxyPass / balancer://tcsrvs/
       ProxyPassReverse / balancer://tcsrvs/
       <Location />
            Require all granted
       </Location>
    </VirtualHost>
systemctl start httpd

Session集群配置

配置

tomcat1

修改tomcat配置
vim /etc/tomcat/server.xml
      <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.51.111.251"
                                    port="45564"
                                    frequency="500"
                                    dropTime="3000"/>
                    <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                                    address="192.168.88.101"
                                    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>

修改頁面配置
cp /etc/tomcat/web.xml /var/lib/tomcat/webapps/test/WEB-INF/
vim /var/lib/tomcat/webapps/test/WEB-INF/web.xml
    <distributable/>

tomcat2

修改tomcat配置
vim /etc/tomcat/server.xml
      <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.51.111.251"
                                    port="45564"
                                    frequency="500"
                                    dropTime="3000"/>
                    <Receiver className="org.apache.catalina.tribes.transport.nio.NioReceiver"
                                    address="192.168.88.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>

修改頁面配置
cp /etc/tomcat/web.xml /var/lib/tomcat/webapps/test/WEB-INF/
vim /var/lib/tomcat/webapps/test/WEB-INF/web.xml
    <distributable/>

原創文章,作者:easyTang,如若轉載,請注明出處:http://www.www58058.com/79479

(1)
easyTangeasyTang
上一篇 2017-07-08
下一篇 2017-07-08

相關推薦

  • 第四周作業

    正則表達式練習

    Linux干貨 2017-12-25
  • Apache運行機制剖析

    1. B/S交互過程 瀏覽器(Browser)和服務器(Web Server)的交互過程:   1、  瀏覽器向服務器發出HTTP請求(Request)。 2、  服務器收到瀏覽器的請求數據,經過分析處理,向瀏覽器輸出響應數據(Response)。 3、  瀏覽器收到服務器的響應數據,經過分析處理,將最終結果顯示在瀏覽…

    Linux干貨 2015-04-10
  • AWK實現求和、平均數、最小值、最大值

    1.簡單的按列求和]$ cat test123125126]$ awk ‘{sum += $1}END {print sum}’ test2.對符合某些條件的行,按列求和]$ cat  testaaa 123bbb 125aaa 123aaa 123ccc 126對文件test中 第一列為aaa的行求和]$ awk &#82…

    Linux干貨 2017-04-09
  • 高效運維最佳實踐(03):Redis集群技術及Codis實踐

    前言 誠如開篇文章所言,高效運維包括管理的專業化和技術的專業化。前兩篇我們主要在說些管理相關的內容,本篇說一下技術專業化。希望讀者朋友們能適應這個轉換,謝謝。 互聯網早在幾年前就已進入Web 2.0時代,對后臺支撐能力的要求,提高了幾十倍甚至幾百倍。在這個演化過程中,緩存系統扮演了舉足輕重的角色。 運維進化到今天,已經不是重復造輪子的時代。所以,我們在架構優…

    Linux干貨 2015-04-03
  • vsftpd

    vsftpd:     程序環境:         配置文件:/etc/vsftpd/vsftpd.conf         主程序:/usr/sbin/vsf…

    Linux干貨 2016-12-05
  • 文本工具

    本文將介紹Linux下使用Shell處理文本時最常用的工具:find、grep、xargs、sort、uniq、tr、cut、paste、wc、sed、awk;提供的例子和參數都是最常用和最為實用的

    2017-11-25
欧美性久久久久