利用memcached实现CAS单点登录集群部署

发布时间:2020-07-07 13:30:13 作者:guoxingzhi
来源:网络 阅读:447

前言:利用memcached实现CAS单点登录集群部署
参考信息:https://github.com/magro/memcached-session-manager/wiki/SetupAndConfiguration https://code.google.com/archive/p/memcached-session-manager/wikis/SetupAndConfiguration.wiki

应用名称 端口 版本 主机IP
Nginx 8088 1.0.1 192.168.7.2
CAS-TomcatA 8089 7.0.35 192.168.7.3
n1:libevent 2.1.8 192.168.7.3
n1:memcached 22322 1.5.12 192.168.7.3
n1:magent 12000 1.5.12 192.168.7.3
CAS-TomcatB 8089 7.0.35 192.168.7.4
n2:libevent 2.1.8 192.168.7.4
n2:memcached 22322 1.5.12 192.168.7.4
n2:magent 12000 1.5.12 192.168.7.4

步骤

    主要只有三个步骤:
        1.安装memcached并配置magent代理
        2.session共享的配置
        3.TicketRegistry内存数据剥离的配置

一:安装memcached并配置magent代理

    192.168.7.3和192.168.7.4两个节点下都要安装memcached和magent,安装步骤只用192.168.7.3举例。

二:session共享的配置

    session共享完全由tomcat来实现,不必修改web应用。本文忽略Nginx实现负载的相关配置。

利用memcached实现CAS单点登录集群部署
利用memcached实现CAS单点登录集群部署

三:将TicketRegistry内存数据写入memcached

1.在cas的tomcat容器中添加一下jar包
    tomcat的路径:/webapps/cas_sso/WEB-INF/lib/
        asm-5.0.3.jar
        cas-server-integration-memcached-3.5.1.jar
        kryo-3.0.3.jar
        minlog-1.3.0.jar
        reflectasm-1.10.1.jar
        spymemcached-2.12.0.jar
2.修改ticketRegistry.xml文件
    文件在Tomact中的路径:/webapps/cas_sso/WEB-INF/spring-configuration/ticketRegistry.xml
    备份ticketRegistry.xml,并创建新的ticketRegistry.xml文件,内容如下:
            <?xml version="1.0" encoding="UTF-8"?>
            <!--

                    Licensed to Jasig under one or more contributor license
                    agreements. See the NOTICE file distributed with this work
                    for additional information regarding copyright ownership.
                    Jasig licenses this file to you under the Apache License,
                    Version 2.0 (the "License"); you may not use this file
                    except in compliance with the License.  You may obtain a
                    copy of the License at the following location:

                        http://www.apache.org/licenses/LICENSE-2.0

                    Unless required by applicable law or agreed to in writing,
                    software distributed under the License is distributed on an
                    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
                    KIND, either express or implied.  See the License for the
                    specific language governing permissions and limitations
                    under the License.

            -->
            <beans xmlns="http://www.springframework.org/schema/beans"
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xmlns:util="http://www.springframework.org/schema/util" 
                xmlns:p="http://www.springframework.org/schema/p"
                xsi:schemaLocation="http://www.springframework.org/schema/beans 
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                http://www.springframework.org/schema/util
                http://www.springframework.org/schema/util/spring-util-3.1.xsd">
            <bean id="ticketRegistry" class="org.jasig.cas.ticket.registry.MemCacheTicketRegistry">
                    <constructor-arg index="0">
                        <bean class="net.spy.memcached.spring.MemcachedClientFactoryBean"
                                    p:servers="192.168.7.3:12000,192.168.7.4:12000"
                                    p:protocol="BINARY"
                                    p:locatorType="ARRAY_MOD"
                                    p:failureMode="Redistribute"
                                    p:transcoder-ref="serialTranscoder">
                            <property name="hashAlg">
                                <util:constant static-field="net.spy.memcached.DefaultHashAlgorithm.FNV1A_64_HASH" />
                            </property>
                        </bean>
                    </constructor-arg>
                    <constructor-arg index="1" value="36000" />
                    <constructor-arg index="2" value="2" />
                </bean>

                <bean id="serialTranscoder" class="net.spy.memcached.transcoders.SerializingTranscoder"
                        p:compressionThreshold="2048" />
            </beans>
参数说明:
    <constructor-arg index="0">:memcached的地址,多个用逗号隔开。
    <constructor-arg index="1">:TGT超时时间(秒)
    <constructor-arg index="1">:ST超时时间(秒)

3.重启应用测试
使用Nginx做负载,代理两个CAS服务端。
1.通过浏览器访问Nginx单点登录登陆后,通过日志查看访问到哪个CAS节点,将该节点stop。
2.再次通过浏览器访问Nginx,查看是否需要登录,正常情况是不需要登录的。成功后标识session共享成功。
3.通过浏览器进行cas客户端访问,如果没有跳转单点,则TGT数据保存到memcached共享成功。

后续:memcached的安全

使用memcached应用时,只需要能连接上主机端口就能用,如果放到互联网上,这是很不安全的操作。使用memcached时,不要使用默认端口,换个1024以上的端口。针对于这个安全一般有三个解决方案,但每一种都有各自的局限性,可以根据自己的业务来做选择。
1.双网卡:应用服务选择外网的网卡,memcached使用内网的网卡。
2.设置防火墙:使用主机的iptables进行白名单放行,阻止非信任的访问请求。
3.memcached开启SASL认证。1.4.3版本后支持此功能。

附件信息
链接: https://pan.baidu.com/s/1aihl_abcNguh9QVNSAWwNA 提取码: 7r1r

推荐阅读:
  1. memcached群集
  2. Memcached集群

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

memcached安装 magent安装 cas集群部署

上一篇:在laravel中使用Symfony的Crawler组件分析HTML

下一篇:三大框架开发时,spring配置文件出现异常

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》