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.178linux.com/79479

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

相关推荐

  • tar ,cpio打包解压. shell脚本for,while,until循环. rpm包管理,循环的特殊用法. select循环菜单,函数function,rpm包查询,yum

    tar  tar -cf 路径+文件名字后续.tar  +路径 创建归档压缩 tar cf /testdir/etc.tar /etc/ tar cvf 可以查看解压过程 tar tvf 预览作用 tar xvf 解压文件  tar zcvf /testdir/etc2.tar.gz /etc/ 解压再压缩到指定路径,文件格式 …

    Linux干货 2016-08-21
  • N25-第一周博客作业

    1、描述计算机的组成及其功能:    没有听马哥视频之前,计算机的组成理解为主机+显示器;    听完视频之后,对计算机的组成分为硬件系统和软件系统。    硬件系统主要有:运算器、控制器、存储器、输入设备和输出设备;    软件系统主要有…

    Linux干货 2016-12-04
  • Elasticsearch 5.0 集群

    IT运维 www.chinasa.net 下载地址:https://www.elastic.co/downloads/elasticsearch 1、JDK 安装略过 node1 部署 2、Elasticsearch安装 #tar zxvf elasticsearch-5.0.0.tar.gz -C /opt/ #cd /opt #mv elast…

    系统运维 2016-12-27
  • debian8下安装配置部署zabbix3.0

    一、安装配置zabbix server     web server服务器:172.28.0.187     mysql服务器:172.28.0.237     1、安装web server(172.28.0.187)  &nbs…

    Linux干货 2016-05-07
  • 分布式存储 Mogilefs 部署

    MogileFS是一个开源的分布式存储的解决方案,主要工作组件由三部分组成:Tracker节点:生成映射表存储于DB,并用于接收客户端请求,通过查询数据库对客户端提供后端所存储的真实文件位置DB节点:主要存储数据的元数据信息,可以理解为客户端来获取数据文件时提供的Key和真实存在存储里面的文件名的对照表Storage节点:用于存储文件的节点。工作流程,tra…

    2017-03-04
  • 信息论的熵

    1.  前言    熵的概念最早起源于物理学,用于度量一个热力学系统的无序程度。    在信息论里则叫信息量,即熵是对不确定性的度量。从控制论的角度来看,应叫不确定性。信息论的创始人香农在其著作《通信的数学理论》中提出了建立在概率统计模型上的信息度量。他把信息定义为“用来消除不确定性的东西”。在信息世界,熵越…

    Linux干货 2016-03-27