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

相关推荐

  • LVM逻辑卷管理

    为什么要用LVM?     想象一个示例,如果我们给定的分区是50G,过段时间发现空间不够用,此时我们就要重新加一块新硬盘,重新分区格式化,将原来分区上的数据复制过来,再重新挂载,整个过程会非常麻烦,LVM可以很有效的解决这个问题 LVM简介     及逻辑卷(Logical V…

    Linux干货 2016-09-01
  • top,htop,ps,dstat命令的使用

    top top是一个动态显示过程,即可跟据用户的按键不断刷新当前状态,top命令提供了实时的对当前系统的状态监视。 top – 11:53:40 up 11 days, 13:32,  3 users,  load average:&nbs…

    Linux干货 2017-03-15
  • LAMP 编译安装基于2.4

    一 安装前准备 说明:     操作系统:CentOS 6.7 64位     MySQL数据库版本:mariadb-5.5.48-linux-x86_64.tar.gz     Apache 版本:httpd-2.4.12.tar.bz2…

    Linux干货 2016-11-21
  • heartbeartv2实现lamp高可用-week17

    3、基于heartbeat v2 crm实现HA LAMP组合;要求,部署wordpress,用于编辑的文章中的任何数据在节点切换后都能正常访问; 拓扑: 环境: CentOS6.6NFS: 172.16.0.34 输出mysql数据目录ntp: 172.16.0.31 时间服务器node1: 172.16.0.32 heartbeart+httpd+php…

    Linux干货 2017-05-23
  • Linux系统文件管理

    1、Linux的文件类型:       –:普通文件;       d:目录文件;       b:块设备:     &nbsp…

    Linux干货 2016-08-04
  • 《种一棵树最好的时间,是十年前,其次是现在。》

    选择一个处于不断发展中的行业,学习新知识就如逆水行舟,不能停止。

    Linux干货 2018-03-26