-
[Redis] backup1, backup2... 그리고 Failed opening the RDB file crontab (in server root dir /etc) for saving: Read-only file systemRedis 2023. 11. 22. 10:15
현재 진행하고 있는 프로젝트에서 회원가입, 로그인 과정에 레디스를 사용하여 작업을 처리하고 있다.
그런데 배포 서버에 돌아가고 있는 레디스에 접속하여 키값들을 확인해보니, 존재해야 할 키값들이 온데 간데 없는 것이었다.
아래처럼 로컬 환경에서 설치하여 테스트한 레디스와 같이 "signupAuth"와 "autoLogin" 키값들이 보이지않았다.
그리고 처음보는 backup1, backup2 이런 값들이 들어있었다.
찾아보니 redis의 기본포트(6379)로 봇으로 특정되는 누군가가 flushall 명령어를 날려서 해당 레디스의 key값들을 삭제하려는 시도를 수행하면서 기존에 저장되어있던 데이터가 모두 삭제되고 backup1, backup2, backup3 .... 과 같은 백업 정보만 남은 것이다.
그래서 곧장 배포 서버에서 레디스 로그를 확인해보니
$ vi /var/log/redis/redis-server.log
다음과 같은 Failed opening the RDB file crontab (in server root dir /etc) for saving: Read-only file system 에러 로그가
수 없이 기록되어있었다.
찾아보니 기본적으로 Redis는 RDB 파일을 현재 디렉토리에 저장한다. Redis 작업 디렉토리의 변경에 악성 프로그램이 원인일 수 있으므로 Redis가 RDB 파일을 root이 소유한 디렉토리에 기록하려고 시도하고 이는 악성 스크립트 때문일 수 있다고 한다.
그래서 레디스를 내렸다가 다시 올릴려고 평소와 같이 sudo service redis-server stop 명령어를 통해
내릴려했는데, 동작되지도 않았다. (이때 매우 당황..)
그래서 어쩔 수 없이 kill -9로 내렸다.
$ netstat -tulpn $ kill -9 {redis-server의 PID}
해결방안
1. 기본 포트를 다른 포트로 바꾸기
2. redis에 접속 시 인증을 하도록 바꾼다.
나는 2번 방식을 택했다. 사실 프로젝트를 시작한지 얼마되서 초기 환경 세팅중이긴 했고
로컬에서는 redis에 비밀번호를 설정하지 않았던걸 서버에도 그대로 올려서 이러한 일이 발생한 것이였다.
이번 일을 계기로 잠시 안일해져있었던 보안에 대한 경각심이 다시 생기게 되었다.
Reference
https://copyprogramming.com/howto/redis-failed-opening-rdb-for-saving-permission-denied
'Redis' 카테고리의 다른 글
MacOS 로컬 환경에서 Docker Redis Cluster 설정 및 Springboot와 연동하기 (0) 2024.08.09 Redis 데이터 구조 (0) 2024.02.20