美文网首页
NAT集群部署solo之session server

NAT集群部署solo之session server

作者: 芷_念 | 来源:发表于2017-09-07 19:07 被阅读0次

    使用Nginx做代理服务器,部署solo,使用session server做会话黏滞

    拓扑图

    环境

    tomcatA    172.16.253.108
    tomcatB    172.16.253.105
    memcachedA 172.16.253.108
    memcachedB 172.16.253.105
    代理服务器 172.16.253.191
    

    在Tomcat主机上搭建httpd服务,使httpd代理本机Tomcat应用,Nginx代理Tomcat

    搭建Tomcat和Httpd服务器

    TomcatA

    [root@TomcatA ~]# yum -y install java-1.8.0-openjdk*
    [root@TomcatA ~]# yum -y install tomcat-lib tomcat tomcat-webapps tomcat-docs-webapp tomcat-admin-webapps
    [root@TomcatA ~]# iptables -F
    [root@TomcatA ~]# setenforce  0
    [root@TomcatA ~]# systemctl start tomcat
    
    配置Tomcat测试页
    [root@TomcatA ~]# mkdir /data/webapps/ROOT/{classes,lib,WEB-INF} -pv
    [root@TomcatA ~]# vim /data/webapps/ROOT/index.jsp 
        <%@ page language="java" %>
        <html>
            <head><title>TomcatB</title></head>
                <body>
                <h1><font color="blue">TomcatB.magedu.com</font></h1>
                <table align="center" border="1">
                    <tr>
                        <td>Session ID</td>
                    <% session.setAttribute("magedu.com","magedu.com"); %>
                        <td><%= session.getId() %></td>
                    </tr>
                    <tr>
                        <td>Created on</td>
                        <td><%= session.getCreationTime() %></td>
                    </tr>
                </table>
            </body>
        </html>
    [root@TomcatA ~]# vim /etc/tomcat/server.xml
        <Engine name="Catalina" defaultHost="www.cxjing1.com">
        </Host>
            <Host name="www.cxjing1.com"  appBase="/data/webapps"
            unpackWARs="true" autoDeploy="true">
        </Host>
    [root@TomcatA ~]# systemctl restart tomcat
    
    搭建Httpd
    [root@TomcatA ~]# yum -y install httpd
    [root@TomcatA ~]# vim /etc/httpd/conf.d/tomcat.conf
        <VirtualHost *:80>
            ServerName www.cxjing1.com
            ProxyRequests Off
            ProxyVia Off
            ProxyPreserveHost Off
            <Proxy *>
                Require all granted
            </Proxy>
            ProxyPass / http://172.16.253.108:8080/
            ProxyPassReverse / http://172.16.253.108:8080/
            <Location />
                Require all granted
            </Location>
        </VirtualHost>
    [root@TomcatA ~]# systemctl start httpd
    

    TomcatB

    [root@TomcatB ~]# yum -y install java-1.8.0-openjdk*
    [root@TomcatB ~]# yum -y install tomcat-lib tomcat tomcat-webapps tomcat-docs-webapp tomcat-admin-webapps
    [root@TomcatB ~]# iptables -F
    [root@TomcatB ~]# setenforce  0
    [root@TomcatB ~]# systemctl start tomcat
    
    配置Tomcat测试页
    [root@TomcatB ~]# mkdir /data/webapps/ROOT/{classes,lib,WEB-INF} -pv
    [root@TomcatB ~]# vim /data/webapps/ROOT/index.jsp 
        <%@ page language="java" %> 
        <html>
            <head><title>TomcatA</title></head>
                <body>
                <h1><font color="red">TomcatA.magedu.com</font></h1>
                <table align="center" border="1">
                    <tr>
                        <td>Session ID</td>
                    <% session.setAttribute("magedu.com","magedu.com"); %>
                        <td><%= session.getId() %></td>
                    </tr>
                    <tr>
                        <td>Created on</td>
                        <td><%= session.getCreationTime() %></td>
                    </tr>       
                </table>
            </body>
        </html>
    [root@TomcatB ~]# vim /etc/tomcat/server.xml
        <Engine name="Catalina" defaultHost="www.cxjing2.com">
        </Host>
            <Host name="www.cxjing2.com"  appBase="/data/webapps"
            unpackWARs="true" autoDeploy="true">
        </Host>
    [root@TomcatB ~]# systemctl restart tomcat
    
    搭建Httpd
    [root@TomcatB ~]# yum -y install httpd
    [root@TomcatB ~]# vim /etc/httpd/conf.d/tomcat.conf
        <VirtualHost *:80>
            ServerName www.cxjing2.com
            ProxyRequests Off
            ProxyVia Off
            ProxyPreserveHost Off
            <Proxy *>
                Require all granted
            </Proxy>
            ProxyPass / http://172.16.253.108:8080/
            ProxyPassReverse / http://172.16.253.108:8080/
            <Location />
                Require all granted
            </Location>
        </VirtualHost>
    [root@TomcatB ~]# systemctl start httpd 
    

    Haproxy代理

    [root@nginx ~]# yum -y install haproxy
    [root@nginx ~]# vim /etc/hosts
    172.16.253.108 www.cxjing1.com
    172.16.253.105 www.cxjing2.com
    172.16.250.127 www.cxjing.com
    [root@nginx ~]# vim /etc/nginx/nginx.conf
        http {
            upstream appsrvs {
                server www.cxjing1.com:8080;
                server www.cxjing2.com:8080;
            }
            server {
                listen 80;
                server_name www.cxjing.com;
                index index.jsp index.html;
                location / {
                    proxy_pass http://appsrvs/;
                }
            }
        }
    [root@nginx ~]# nginx -t
    [root@nginx ~]# systemctl start nginx
    

    安装后端memcached服务集群

    程序下载
    https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration

    下载相关程序到Tomcat主机的/usr/share/java/tomcat目录下

    javolution-5.4.3.1.jar
    memcached-session-manager-1.8.3.jar
    memcached-session-manager-tc7-1.8.3.jar
    msm-javolution-serializer-1.8.3.jar 
    spymemcached-2.11.1.jar /usr/share/java/tomcat
    

    memcachedA

    [root@TomcatA ~]# yum -y install memcached
    [root@TomcatA ~]# systemctl start memcached.service 
    [root@TomcatA ~]# ss -ntl
    

    memcachedB

    [root@TomcatB ~]# yum -y install memcached
    [root@TomcatB ~]# systemctl start memcached.service 
    [root@TomcatB ~]# ss -ntl
    

    配置Tomcat连接memcached服务端

    TomcatA

    [root@TomcatA ~]# vim /etc/tomcat/server.xml 
        <Engine name="Catalina" defaultHost="www.cxjing1.com" jvmRoute="tcA">
         <Host name="www.cxjing1.com"  appBase="/data/webapps"
            unpackWARs="true" autoDeploy="true">
            <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
                memcachedNodes="n1:172.16.253.108:11211,n2:172.16.253.105:11211"
                failoverNodes="n1"
                requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
                transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
            />
        </Host>
    [root@TomcatB ~]# systemctl restart tomcat
    

    TomcatB

    [root@TomcatB ~]# vim /etc/tomcat/server.xml
        <Engine name="Catalina" defaultHost="localhost" jvmRoute="tcB">
        </Host>
       <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
        <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
            memcachedNodes="n1:172.16.253.108:11211,n2:172.16.253.105:11211"
            failoverNodes="n1"
            requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
            transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
          />
    </Host>
    [root@TomcatB ~]# systemctl restart tomcat
    

    部署solo

    [root@TomcatA ~]# vim /etc/tomcat/server.xml
    <Engine name="Catalina" defaultHost="localhost" jvmRoute="tcA">
    <Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">
     <Context path="/solo-2.2.0" docBase="solo-2.2.0" reloadable="true">
          <Manager className="de.javakaffee.web.msm.MemcachedBackupSessionManager"
            memcachedNodes="n1:172.16.253.108:11211,n2:172.16.253.105:11211"
            failoverNodes="n1"
            requestUriIgnorePattern=".*\.(ico|png|gif|jpg|css|js)$"
            transcoderFactoryClass="de.javakaffee.web.msm.serializer.javolution.JavolutionTranscoderFactory"
        />
    </Context>
    [root@TomcatA ~]# vim /etc/tomcat/tomcat-users.xml
    <role rolename="manager-gui"/>  \\启用manager-gui管理组
    <user username="tomcat" password="tomcat" roles="manager-gui"/> \\添加用户到manager-gui管理组中,用户为tomcat,密码为tomcat
    [root@jing ~]# systemctl restart tomcat
    

    浏览器访问http://172.16.253.105:8080/进入Manager App管理界面

    配置Tomcat的服务代理
    [root@TomcatB webapps]# vim /etc/httpd/conf.d/tomcat.conf 
        <VirtualHost *:80>
            ServerName www.cxjing2.com
            ProxyRequests Off
            ProxyVia On
            ProxyPreserveHost On
            <Proxy *>
                Require all granted
            </Proxy>
            ProxyPass / http://172.16.253.105:8080/solo-2.2.0/
            ProxyPassReverse / http://172.16.253.105:8080/solo-2.2.0/
            <Location />
                Require all granted
            </Location>
        </VirtualHost>
    [root@TomcatB webapps]# systemctl restart httpd
    
    修改solo的服务器配置文件
    [root@TomcatB ~]# vim  /usr/share/tomcat/webapps/solo-2.2.0/WEB-INF/classes/latke.properties
        serverHost=172.16.253.105 \\本机Tomcat的IP
    [root@TomcatB ~]# systemctl restart tomcat
    [root@TomcatB ~]# ss -ntl
    

    TomcatB配置同TomcatA一致

    client测试访问

    相关文章

      网友评论

          本文标题:NAT集群部署solo之session server

          本文链接:https://www.haomeiwen.com/subject/hkfwjxtx.html