레디스는 인메모리 기반의 대표주자로, 캐시나 메시지 브로커 등 다양한 형태로 널리 사랑받고 있다. 영구적인 최종 저장소 형태로 사용하는 사례도 있기는 하나, 일반적으로는 유실되어도 크게 문제가 없거나 다른 원본 데이터로 빠르게 다시 구성할 수 있는 데이터들을 담아놓고 빠르게 처리하는 용도로 사용하게 된다.
오늘은 Redis를 설치하는 방법에 대해 매뉴얼을 살펴본다. 오늘은 Single 설치에 대해서만 다루며, Replication이나 Sentinel 구성에 대한 매뉴얼 문서는 후속 시리즈로 살펴볼 예정이다.

테스트 환경
테스트를 진행한 환경은 아래와 같다.
- ubuntu 20
- redis 6.2
다운로드
위 다운로드 페이지에서 stable release를 다운로드 받아보도록 한다. 현재 기준 6.2가 stable 버전이다.
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
설치
사전 작업 - 컴파일을 위한 관련 패키지 설치 필요
https://redis.io/topics/quickstart
내려받은 REDIS tar파일을 압축 해제 하여 컴파일을 해주어야 하는데, 컴파일을 하려면 gcc 등 컴파일러 패키지 설치 필요하다. 각각 필요한 패키지를 설치해도 되고, 현재 테스트 환경인 ubuntu20 환경에서는 아래 커멘드로 한번에 설치해도 무방하다.
sudo apt update
sudo apt install build-essential
참고: https://linuxize.com/post/how-to-install-gcc-on-ubuntu-20-04/
컴파일 처리
tar xzf redis-6.2.5.tar.gz
ln -s redis-6.2.5 redis ## 심볼릭 링크는 필수는 아니고 편의상 추가해줌
cd redis-6.2.5
make
레디스 서버 시작
이제 레디스 서버를 띄워보자.
src/redis-server
REDIS가 정상적으로 구동 되었다. 로그를 살펴보자.
23581:C 24 Sep 2021 16:58:18.711 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
23581:C 24 Sep 2021 16:58:18.711 # Redis version=6.2.5, bits=64, commit=00000000, modified=0, pid=23581, just started
23581:C 24 Sep 2021 16:58:18.711 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
23581:M 24 Sep 2021 16:58:18.712 * Increased maximum number of open files to 10032 (it was originally set to 1024).
23581:M 24 Sep 2021 16:58:18.712 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 23581
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
23581:M 24 Sep 2021 16:58:18.712 # Server initialized
23581:M 24 Sep 2021 16:58:18.712 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
23581:M 24 Sep 2021 16:58:18.713 * Ready to accept connections
찍힌 로그를 통해 추가적으로 할 작업을 체크해보자.
- config 파일 지정 필요
- open files 조정 필요
- overcommit_memory 조정 필요
- transparent_hugepage 설정
1) config 파일 지정
redis 베이스 경로에 마련된 redis.conf 샘플 파일을 이용하여 컨피그를 작성하고, 아래와 같이 컨피그를 갖고 레디스 서버를 다시 띄우도록 하자.
./src/redis-server ./redis.conf &
2) open files 조정
open files을 조정해주자.
필요에 따라 더 높게 조정해줄 수 있으며, 현재 테스트에서는 일단 위 로그에 찍힌 리밋 까지만 올려준다.
즉시 반영
ulimit -n 10032
영구 반영
vi /etc/security/limits.conf
redis soft nofile 10032
redis hard nofile 10032
참조: https://stackoverflow.com/questions/36880321/why-redis-can-not-set-maximum-open-file
3) overcommit_memory 조정
Make sure to set the Linux kernel overcommit memory setting to 1. Addvm.overcommit_memory = 1
to/etc/sysctl.conf
and then reboot or run the commandsysctl vm.overcommit_memory=1
for this to take effect immediately.
overcommit_memory 조정에 대한 부분도 로그에서 가이드가 있었으므로, 해당 내용을 따라준다.
즉시 반영
sysctl vm.overcommit_memory=1
영구 반영
vi /etc/sysctl.conf
vm.overcommit_memory = 1
4) transparent_hugepage 설정
Make sure Redis won't be affected by Linux kernel feature transparent huge pages, otherwise it will impact greatly both memory usage and latency in a negative way. This is accomplished with the following command: echo madvise > /sys/kernel/mm/transparent_hugepage/enabled
.
해당 테스트 서버에 이미 설정이 되어있어 이 부분이 로그로 남지 않았는데, 원래는 이 transparent_hugepage 설정도 초기에 설정해주어야 하는 가이드 내용이다. 이 부분도 설정되어있지 않다면 설정해준다.
위 부분들을 모두 설정해준 후, 다시 Redis Server를 띄워보자.
로그에 관련 Warning들이 사라진 것을 확인할 수 있다.
redis-cli로 레디스 접속해보기
redis-cli 클라이언트툴을 이용하면, redis server로 접속해볼 수 있다.
만일 redis.conf에 requirepass 지정을 해줬다면, auth password(지정한 패스워드)
커멘드로 통과하고 진입한다.
./src/redis-cli
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> info
# Server
redis_version:6.2.5
...생략...
redis 관련 주요 파일 살펴보기
- redis-server : Redis 서버is the Redis Server itself.
- redis-sentinel : Redis 센티넬 (모니터링, Failover에 활용)
- redis-cli : Redis command line 인터페이스 유틸리티
- redis-benchmark : Redis 성능 진단
(선택) PATH 지정
이 부분은 필수는 아니지만, 추후 사용 편의를 위해 redis base경로의 src 디렉토리를 PATH에 넣어주자. redis-cli 등 자주 사용하게 되는 프로그램을 경로를 모두 지정해주거나, 해당 경로에 들어가지 않고도 바로 실행할 수 있어 편리하다.
날짜 | 내용 |
---|---|
2021.09.25 | 최초 글 작성 |