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

相关推荐

  • 进程管理

    linux进程管理     内核的功能:进程管理、文件系统、网络管理、驱动程序、安全功能等     Pcrocess:运行中的程序的一个副本,是被载入内存中的一个指令集和         PID:进程…

    Linux干货 2016-09-12
  • 第一周 N28

    作业一

    2017-12-03
  • grub应用 (Blog 10)

    grub1.x 、grub2.x详解

    2017-11-27
  • Linux进程管理-初级

    Linux进程管理-初级 背景: 在学习完Linux进程管理后,发现这一块的知识点比较多,很多都是自己以前没有接触过的,而且这部分知识对今后的工作有很大帮助,在这里做个学习的总结,供以后复习。 进程介绍: 什么是进程 进程(Process):运行中的程序的一个副本,是被载入内存的一个指令集合,进程有进程ID(Process ID,PID),用来标记每个进程,…

    2017-08-26
  • Shell脚本编程—特殊用法(select)及函数、递归

    Shell脚本编程—特殊用法及函数   一、while的特殊用法: 1、使用格式: while read 变量名;do    循环体 done </PATH/TO/filename 注:依次从指定的文件中的内容逐行读取,并把读取到的每行赋值给变量。 2、例题: 扫描/etc/passwd文件每一行,如发现GECOS字段为空…

    Linux干货 2016-08-21
  • 迁移用户数据到独立分区

    Linux操作系统中,/home目录下为各个普通用户的家目录,主要用于存放用户的配置信息及相关文件。若安装操作系统时,采用了home目录与根目录处在同一分区的分区策略,那么随着用户数据较多,很有可能将分区空间耗尽,导致系统崩溃。所以最好是将用户数据所在目录放在一个独立的分区上,但由于/home目录下已有一些用户数据,要想将home目录建立在一个独立的分区上,…

    Linux干货 2017-08-13