티스토리 뷰
today'work
spring boot app과 redis cluster를 docker로 사용할 때 Redis connection failed 발생
msna 2023. 7. 19. 01:59- 발생문제
- redis cluster를 docker로 기동하고 있는데, spring boot app을 docker로 기동해야하는 필요가 생김.
- redis cluster는 localhost로 연결하고 있었는데, spring boot app이 docker가 되면서 redis cluster의 컨테이너명("redis-cluster")으로 변경함.
- 로그를 보면 redis에 연결에 성공하는 로그도 보이나, 연결 실패도 발생함.
- 연결 성공 로그
{"level":"DEBUG","message":"Connecting to Redis at redis-cluster:6379: Success","stackTrace":""}
-
-
- 연결 실패 로그
-
{"level":"ERROR", "message":"Application run failed", "stackTrace":"org.springframework.context.ApplicationContextException: Failed to start bean 'springSessionRedisMessageListenerContainer'; nested exception is org.springframework.data.redis.listener.adapter.RedisListenerExecutionFailedException: org.springframework.data.redis.RedisConnectionFailureException: Redis connection failed; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to [redis://*********@redis-cluster, redis://*********@redis-cluster:6380, redis://*********@redis-cluster:6381]; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Redis connection failed; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to [redis://*********@redis-cluster, redis://*********@redis-cluster:6380, redis://*********@redis-cluster:6381]\n \tat org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:181)\n Caused by: org.springframework.data.redis.listener.adapter.RedisListenerExecutionFailedException: org.springframework.data.redis.RedisConnectionFailureException: Redis connection failed; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to [redis://*********@redis-cluster, redis://*********@redis-cluster:6380, redis://*********@redis-cluster:6381]; nested exception is org.springframework.data.redis.RedisConnectionFailureException: Redis connection failed; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to [redis://*********@redis-cluster, redis://*********@redis-cluster:6380, redis://*********@redis-cluster:6381]\n \tat org.springframework.data.redis.listener.RedisMessageListenerContainer.lazyListen(RedisMessageListenerContainer.java:275)\nCaused by: org.springframework.data.redis.RedisConnectionFailureException: Redis connection failed; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to [redis://*********@redis-cluster, redis://*********@redis-cluster:6380, redis://*********@redis-cluster:6381]\n \tat org.springframework.data.redis.connection.lettuce.LettuceExceptionConverter.convert(LettuceExceptionConverter.java:66)\nCaused by: io.lettuce.core.RedisConnectionException: Unable to connect to [redis://*********@redis-cluster, redis://*********@redis-cluster:6380, redis://*********@redis-cluster:6381]\n \tat io.lettuce.core.RedisConnectionException.create(RedisConnectionException.java:78)\nCaused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /127.0.0.1:6381\n Caused by: java.net.ConnectException: finishConnect(..) failed: Connection refused\n \tat io.netty.channel.unix.Errors.newConnectException0(Errors.java:155)\n"}
- 해결방법
- 기존에 localhost가 동작했으니 "host.internal.docker"를 이용 => 정확한 이유는 모르겠지만 실패.
- spring boot app이 redis cluster의 네트워크를 이용하도록 설정
- 기존 docker-compose:
services:
spring-boot-app:
ports:
- 8888:8888
redis-cluster:
container_name: redis-cluster
command: redis-server /conf/redis.conf
image: redis:alpine
ports:
- 6379:6379
- 6380:6380
- 6381:6381
-
- 변경 docker-compose:
services:
spring-boot-app:
network_mode: service:redis-cluster
redis-cluster:
container_name: redis-cluster
command: redis-server /conf/redis.conf
image: redis:alpine
ports:
- 6379:6379
- 6380:6380
- 6381:6381
- 8888:8888
- 마무리
- 좋은 해결방법인지는 모르겠지만 어차피 검증서버는 redis가 잘 움직이고 있으므로 더 찾아보지 않고 이걸로 종결.
'today'work' 카테고리의 다른 글
파일(PDF, 이미지)에서 QR코드 인식하기 (1) | 2023.10.29 |
---|---|
컴파일 시 Lombok Builder 클래스를 못 찾는 에러 (0) | 2023.09.28 |
postgreSQL에서 Input/output error 발생 (0) | 2023.07.24 |
PostgreSQL ROW LOCK걸기(FOR UPDATE, SKIP LOCKED) (0) | 2023.07.20 |
로그파일 index 자리수 변환하기 (0) | 2023.07.19 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- reverse integer
- Postgresql #MultiTruncate
- palindrome number
- lombok #maven build #sym
- excel table
- spring-integration
- Two Sum
- Maven LF #메이븐 개행문자
- yaml
- 로그테스트 #콘솔로그테스트 #System.out
- multipleIntegrationFlow
- excel to markdown
- cannotResolveSymbol
- leetcode
- springintegration #파일감시 #디렉토리감시 #파일완료검사
- AWS #X-Ray
- logback #logstash #LoggingEventCompositeJsonEncoder #로그JSON
- 로그파일인덱스
- SnakeYAML
- Python #Powertools
- PostgreSQL #FOR UPDATE #SKIP LOCKED
- json
- add two numbers
- PostgreSQL #sequnceName
- QR코드읽기 #ReadQRCode
- spring #redis #redis-cluster
- aws #aws region #aws credential #aws region provider #aws credential provier
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
글 보관함