발걸음/오류창고
Redis 외부접속 오류(feat. protected mode)
리꾸므
2022. 9. 22. 23:08
문제 발생
ubuntu에 redis를 설치하고 bind까지 0.0.0.0으로 변경해주었는데 로컬서버에서 ubuntu에있는 redis로 연결했을때 오류가 발생했다.
오류
DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user.
In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions:
1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent.
2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server.
3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a an authentication password for the default user.
NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
원인
호스트를 개방해줘도 redis에 protected mode가 가동중이기때문에 외부 접속이 안된다.
해결
해결방안은 크게
1. redis가 설치된 우분투 사용 곧 외부접속이 아닌 내부접속 사용
2. 보호모드 사용 중지
3. redis 비밀번호를 설정하여 외부접속
보호모드 중지는
sudo vi /etc/redis/redis.conf를 ubuntu에 쳐서
redis.conf를 vi편집기로 실행한다음 protecte mode yes를 protecte mode no로 바꾸면 된다.
나는 3번째 방법으로 갔는데, 보호모드를 중지시키는것은 아무리 가벼운 프로젝트라 하여도 보안적으로 옳지않다고 생각했기때문이다.
비밀번호변경은 보호모드 중지와 비슷하다.
sudo vi /etc/redis/redis.conf로 redis.conf내부를 변경해주면 되는데
- /requirepass로 찾고 i를 눌러 입력모드를 찾은다음
- #requirepass foodbred 부분을 requirepass (원하는비밀번호 ex: requirepass asdfqwer)로 편집
- esc 한번 눌러서 입력모드에서 읽기모드로 변경 후 :wq로 저장하여 빠져나오면 끝!
편집하는방법이 헷갈릴경우 일지에서 26번째 발걸음을 읽어볼것!