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 15:11
下一篇 2017-07-08 18:20

相關推薦

  • CentOS啟動流程排錯

    grub legacy配置文件:/boot/grub/grub.conf     default=#: 設定默認啟動的菜單項;落單項(title)編號從0開始      timeout=#:指定菜單項等待選項選擇的時長     &…

    Linux干貨 2016-09-13
  • 學習宣言

    失敗是留給不堅持的人·······

    Linux干貨 2016-12-27
  • N25第二周作業

    1、Linux上的文件管理類命令都有哪些其常用的使用方法及其相關示例演示。 cp(copy) 復制,mv(move)移動或者更名,mkdir(創建目錄,-p可以同時創建父目錄),rm(刪除目錄,-r 可以遞歸操作,rmdir(刪除空目錄)刪除文件或者目錄,建議建立一個臨時回收站,否則誤刪或者短時間內還需要的文件),touch,file,stat, …

    Linux干貨 2016-12-25
  • 文件查看及查找命令

    cat  查看一個文件   -E: 顯示行結束符$   -n: 對顯示出的每一行進行編號   -A:顯示所有控制符   -b:非空行編號   -s:壓縮連續的空行成一行   -T:顯示制表符 常用:cat -An /et…

    Linux干貨 2017-04-08
  • 網絡及TCP

    為什么要使用分層網絡模型     降低復雜性     標準化接口     簡化模塊化設計     確保技術的互操作性     加快發展速度  &nbs…

    2017-05-08
  • 18-系統啟動故障修復-實踐

    說明:重啟時可以選擇性在vmlinuz所在行末尾添加 selinux=0;或者直接編輯/etc/selinus/config文件,更改 SELINUX=disabled 關閉SELINUX??梢员苊獯驑撕?,節省啟動時間 以下操作都需要進入bootloader引導加載項修改內核啟動參數,在vmlinuz所在行末尾添加一個啟動選項 如何進入bootloader引…

    2017-04-02
欧美性久久久久