📎

얼마전 고객사 인프라 구성이 변경됨에 따라 다중 was에 대한 세션 클러스터링을 적용할 필요가 있었습니다.

원래 세션 클러스터링 적용은 크게 어려운 작업이 아니지만, 낮은 버전의 스프링 프레임워크 기반 그리고 AWS ElastiCache for Redis에 “전송 및 저장 중 암호화“가 설정된 상황에서는 기존에 알려진 방법만으로는 동작하지않는 문제가 존재했습니다.

이러한 특수 조건에서 세션 클러스터링이 정상적으로 동작할 수 있기까지 참 많은 시행착오가 있었지만, 그 방법만 간략히 정리해보았습니다.

목표

Spring framework 애플리케이션에서 Redis를 통한 세션 클러스터링

작업 환경

  • AWS ElastiCache for Redis 포트 : 6480

  • AWS ElastiCache for Redis 저장 중 암호화, 전송 중 암호화 설정 : 모두활성화

  • Spring Framework Version : 4.3.7

    (※ 스프링 프레임워크 최신버전에서는 보다 쉬운 세션클러스터링 방법 존재)

설정 방법

  • 세션클러스터링을 위해 jar 파일 설치

https://github.com/redisson/redisson/blob/master/redisson-tomcat/README.md 접속 →

redisson-all-3.22.1.jar, redisson-tomcat-8-3.22.1.jar 다운로드 →

설치되어있는 tomcat 폴더 내 lib 폴더 안으로 이동

  • {tomcat_base}/context.xml > Context 태그 안에 아래 내용 적용
<Manager className="org.redisson.tomcat.RedissonSessionManager"
          configPath="${catalina.base}/conf/redisson.yaml" readMode="REDIS"/>
<ResourceLink name="bean/redisson" global="bean/redisson"
      type="org.redisson.api.RedissonClient" />
<Manager className="org.redisson.tomcat.JndiRedissonSessionManager"
      readMode="REDIS"
      jndiName="bean/redisson" />
  • {tomcat_base}/server.xml > GlobalNamingResources 태그 안에 아래 내용 적용
<Resource name="bean/redisson"
                  auth="Container"
                  factory="org.redisson.JndiRedissonFactory"
                  configPath="${catalina.base}/conf/redisson.yaml"
                  closeMethod="shutdown"/>
  • {tomcat_base}/conf/redisson.yaml (파일 신규 생성)
singleServerConfig:
  idleConnectionTimeout: 10000
  connectTimeout: 10000
  timeout: 10000
  retryAttempts: 20
  retryInterval: 2000
  password: null
  subscriptionsPerConnection: 5
  clientName: null
  # "rediss://" 스키마 사용
  address: "{생성된 AWS ElastiCache for Redis의 Endpoint}:6480"
  # SSL 설정 추가
  sslEnableEndpointIdentification: false
  sslProvider: "JDK"
  subscriptionConnectionMinimumIdleSize: 1
  subscriptionConnectionPoolSize: 50
  connectionMinimumIdleSize: 24
  connectionPoolSize: 64
  database: 2
  dnsMonitoringInterval: 5000
threads: 0
nettyThreads: 0
codec: !<org.redisson.codec.Kryo5Codec> {}
transportMode: "NIO"

각 WAS에 위와 같은 설정을 완료 후 재시작하면 세션클러스터링이 정상적으로 동작하는것을 확인할 수 있습니다.