레디스 세션 매니저 다운로드 및 설정
[root@ip-172-31-86-130 ~]# cd /usr/share/tomcat/
[root@ip-172-31-86-130 tomcat]# mkdir download
[root@ip-172-31-86-130 tomcat]# cd download/
--2020-07-31 14:23:04-- https://github.com/ran-jit/tomcat-cluster-redis-session-manager/releases/download/2.0.4/tomcat-cluster-redis-session-manager.zip
Resolving github.com (github.com)... 52.78.231.108
Connecting to github.com (github.com)|52.78.231.108|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/54272419/c2323ca8-5dd4-11e8-9e90-052fe48c96dd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200731%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200731T142305Z&X-Amz-Expires=300&X-Amz-Signature=8aee34e9247501fcfe00a14d07aee0fce04ae4be2a3f0d69226f3b5b9d3990c3&X-Amz-SignedHeaders=host&actor_id=0&repo_id=54272419&response-content-disposition=attachment%3B%20filename%3Dtomcat-cluster-redis-session-manager.zip&response-content-type=application%2Foctet-stream [following]
--2020-07-31 14:23:05-- https://github-production-release-asset-2e65be.s3.amazonaws.com/54272419/c2323ca8-5dd4-11e8-9e90-052fe48c96dd?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20200731%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20200731T142305Z&X-Amz-Expires=300&X-Amz-Signature=8aee34e9247501fcfe00a14d07aee0fce04ae4be2a3f0d69226f3b5b9d3990c3&X-Amz-SignedHeaders=host&actor_id=0&repo_id=54272419&response-content-disposition=attachment%3B%20filename%3Dtomcat-cluster-redis-session-manager.zip&response-content-type=application%2Foctet-stream
Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.107.236
Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.107.236|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 740661 (723K) [application/octet-stream]
Saving to: ‘tomcat-cluster-redis-session-manager.zip’
100%[======================================================================================================>] 740,661 742KB/s in 1.0s
2020-07-31 14:23:06 (742 KB/s) - ‘tomcat-cluster-redis-session-manager.zip’ saved [740661/740661]
[root@ip-172-31-86-130 download]# unzip tomcat-cluster-redis-session-manager.zip
Archive: tomcat-cluster-redis-session-manager.zip
creating: tomcat-cluster-redis-session-manager/conf/
inflating: tomcat-cluster-redis-session-manager/conf/redis-data-cache.properties
creating: tomcat-cluster-redis-session-manager/lib/
inflating: tomcat-cluster-redis-session-manager/lib/commons-logging-1.2.jar
inflating: tomcat-cluster-redis-session-manager/lib/commons-pool2-2.4.2.jar
inflating: tomcat-cluster-redis-session-manager/lib/jedis-2.9.0.jar
inflating: tomcat-cluster-redis-session-manager/lib/tomcat-cluster-redis-session-manager-2.0.4.jar
inflating: tomcat-cluster-redis-session-manager/readMe.txt
[root@ip-172-31-86-130 download]# cp tomcat-cluster-redis-session-manager/lib/* ../lib/
[root@ip-172-31-86-130 download]# cp tomcat-cluster-redis-session-manager/conf/* ../conf/
권한 변경 tomcat 하위폴더
root@ip-10-20-45-39:/opt# chown -R tomcat: tomcat/
톰캣 설정 변경
[root@ip-172-31-86-130 download]# vim /usr/share/tomcat/conf/redis-data-cache.properties
—주의사항: 레디스 엔드포인트로 변경하고 설정에 맞게 비밀번호등 변경 필요, 아무설정도 하지 않았다면 엔드포인트만 변경
============== 파일내용 ==============
#-- Redis data-cache configuration
#- redis hosts ex: 127.0.0.1:6379, 127.0.0.2:6379, 127.0.0.2:6380, ....
redis.hosts= <ElastiCache-Endpoint.cache.amazonaws.com> :6379
#- redis password (for stand-alone mode)
#redis.password=
#- set true to enable redis cluster mode
redis.cluster.enabled=false
#- redis database (default 0)
#redis.database=0
#- redis connection timeout (default 2000)
#redis.timeout=2000
=================================
[root@ip-172-31-86-130 download]# vim /usr/share/tomcat/conf/web.xml
============== 파일내용 변경==============
<session-config>
<session-timeout>60</session-timeout>
</session-config>
=====================================
[root@ip-172-31-86-130 download]# cat /usr/share/tomcat/conf/context.xml
— 주의사항: <Context> </Context> 사이에 <Valve className="tomcat.request.session.redis.SessionHandlerValve" />
<Manager className="tomcat.request.session.redis.SessionManager" />넣어주면 됨
============== 파일내용 변경==============
<Context>
<!-- Default set of monitored resources -->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<!-- Uncomment this to disable session persistence across Tomcat restarts -->
<!--
<Manager pathname="" />
-->
<!-- Uncomment this to enable Comet connection tacking (provides events
on session expiration as well as webapp lifecycle) -->
<!--
<Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
-->
<Valve className="tomcat.request.session.redis.SessionHandlerValve" />
<Manager className="tomcat.request.session.redis.SessionManager" />
</Context>
=====================================
테스트 페이지 준비
mkdir sample
[root@ip-172-31-86-130 download]# cd /var/lib/tomcat/webapps/sample/
/opt# chown -R tomcat: tomcat/
[root@ip-172-31-86-130 sample]# wget https://s3.ap-northeast-2.amazonaws.com/youngwoo.lab/download/tomcat_session_test_jsp/tomcat_session_test.jsp
--2020-07-31 14:40:34-- https://s3.ap-northeast-2.amazonaws.com/youngwoo.lab/download/tomcat_session_test_jsp/tomcat_session_test.jsp
Resolving s3.ap-northeast-2.amazonaws.com (s3.ap-northeast-2.amazonaws.com)... 52.219.58.117
Connecting to s3.ap-northeast-2.amazonaws.com (s3.ap-northeast-2.amazonaws.com)|52.219.58.117|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2922 (2.9K) [binary/octet-stream]
Saving to: ‘tomcat_session_test.jsp’
100%[======================================================================================================>] 2,922 --.-K/s in 0s
2020-07-31 14:40:34 (172 MB/s) - ‘tomcat_session_test.jsp’ saved [2922/2922]
[root@ip-172-31-86-130 sample]# ls
META-INF WEB-INF hello.jsp images index.html session_check.jsp tomcat_session_test.jsp
## 꼭 파일 변경할 것
mv tomcat_session_test.jsp index.jsp
서비스 재시작
[root@ip-172-31-86-130 download]# systemctl restart tomcat
여기까지 모든 톰캣 서버에 동일하게 진행했나요?!
진행 했다면 세션유지 테스트로 넘어가고, 아니라면 모든 톰캣서버에 동일하게 진행합니다.!
세션 유지 확인테스트
재시작되는데 시간이 소요되므로 약 5분~10분후 확인 권장
크롬 시크릿창에서 ELB경로/sample/tomcat_session_test.jsp 확인
아래 사진처럼 Server IP는 바뀌지만 SessionID가 안바뀌면 정상입니다! 😁
https://aws-solutions.tistory.com/5
'REDIS' 카테고리의 다른 글
[AWS] REDIS 외부에서 생성된 백업을 사용하여 새 클러스터 시드 (0) | 2021.08.25 |
---|---|
[Redis] Persistance - 데이터 저장 (0) | 2021.08.25 |
[Redis] 레디스 설정 (0) | 2021.08.25 |
[성공] Ubuntu 20.04 : Redis 설치하는 방법, 예제, 명령어 (0) | 2021.06.16 |
AWS EC2 인스턴스 Redis 설치 (0) | 2021.06.16 |
댓글