NAT集群部署solo之session server

author:JevonWei
版权声明:原创作品


使用Nginx做代理服务器,部署solo,使用session server做会话黏滞
拓扑图
NAT集群部署solo之session server_第1张图片
环境

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" %>
    
        TomcatB
            
            

TomcatB.magedu.com

<% session.setAttribute("magedu.com","magedu.com"); %>
Session ID<%= session.getId() %>
Created on <%= session.getCreationTime() %>
[root@TomcatA ~]# vim /etc/tomcat/server.xml [root@TomcatA ~]# systemctl restart tomcat 搭建Httpd [root@TomcatA ~]# yum -y install httpd [root@TomcatA ~]# vim /etc/httpd/conf.d/tomcat.conf ServerName www.jevon1.com ProxyRequests Off ProxyVia Off ProxyPreserveHost Off Require all granted ProxyPass / http://172.16.253.108:8080/ ProxyPassReverse / http://172.16.253.108:8080/ Require all granted [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" %> 
    
        TomcatA
            
            

TomcatA.magedu.com

<% session.setAttribute("magedu.com","magedu.com"); %>
Session ID<%= session.getId() %>
Created on <%= session.getCreationTime() %>
[root@TomcatB ~]# vim /etc/tomcat/server.xml [root@TomcatB ~]# systemctl restart tomcat 搭建Httpd [root@TomcatB ~]# yum -y install httpd [root@TomcatB ~]# vim /etc/httpd/conf.d/tomcat.conf ServerName www.jevon2.com ProxyRequests Off ProxyVia Off ProxyPreserveHost Off Require all granted ProxyPass / http://172.16.253.108:8080/ ProxyPassReverse / http://172.16.253.108:8080/ Require all granted [root@TomcatB ~]# systemctl start httpd

Haproxy代理

[root@nginx ~]# yum -y install haproxy
[root@nginx ~]# vim /etc/hosts
172.16.253.108 www.jevon1.com
172.16.253.105 www.jevon2.com
172.16.250.127 www.danran.com
[root@nginx ~]# vim /etc/nginx/nginx.conf
    http {
        upstream appsrvs {
            server www.jevon1.com:8080;
            server www.jevon2.com:8080;
        }
        server {
            listen 80;
            server_name www.danran.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 
    
     
        
    
[root@TomcatB ~]# systemctl restart tomcat

TomcatB

[root@TomcatB ~]# vim /etc/tomcat/server.xml
    
    
   
    

[root@TomcatB ~]# systemctl restart tomcat

部署solo

[root@TomcatA ~]# vim /etc/tomcat/server.xml


 
      

[root@TomcatA ~]# vim /etc/tomcat/tomcat-users.xml
  \\启用manager-gui管理组
 \\添加用户到manager-gui管理组中,用户为tomcat,密码为tomcat
[root@danran ~]# systemctl restart tomcat

浏览器http://172.16.253.105:8080/进入Manager App管理界面
NAT集群部署solo之session server_第2张图片
NAT集群部署solo之session server_第3张图片
选择solo应用的war文件部署
NAT集群部署solo之session server_第4张图片

配置Tomcat的服务代理
[root@TomcatB webapps]# vim /etc/httpd/conf.d/tomcat.conf 
    
        ServerName www.jevon2.com
        ProxyRequests Off
        ProxyVia On
        ProxyPreserveHost On
        
            Require all granted
        
        ProxyPass / http://172.16.253.105:8080/solo-2.2.0/
        ProxyPassReverse / http://172.16.253.105:8080/solo-2.2.0/
        
            Require all granted
        
    
[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)