위의 과제를 진행하면서 한 인스턴스에 각각 다른 버전의 Redis를 설치해주어야 했습니다.
Redis의 기본 포트는 6379이기 때문에, 두 Redis의 포트가 겹치지 않도록 포트 번호를 변경해 설치되도록 진행해보겠습니다!
아래 과정대로 진행해줍니다.
# Redis 소스 코드 다운로드 및 압축 해제
$ wget http://download.redis.io/releases/redis-x.x.x.tar.gz
$ tar xzf redis-x.x.x.tar.gz
$ cd redis-x.x.x
# redis.conf 파일 열고 포트 번호 변경
$ vi redis.conf
# port 6379 -> port 6378
# Redis 서버 컴파일 및 설치
$ make
$ make install
# 변경된 포트 번호로 Redis 서버 실행
$ src/redis-server redis.conf
Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
구글링을 하면 금방 해결할 수 있지만 어떤 의미를 가지는지 한번 자세히 알아보겠습니다.
메시지를 읽어보면 어떤 내용인지, 어떻게 해야 되는지 친절하게 적혀 있기 때문에 하나씩 진행해보겠습니다!
설치 환경
NHN Cloud
CentOS 7.9
Redis 7.0.11
1. config 파일 지정
문제
Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf
warning 메시지 그대로 config 파일이 세부적으로 지정되어 있지 않아서 default config를 사용하고 있음을 알 수 있습니다.
해결 방법
메시지에서 알려주는대로 아래처럼 config 파일을 지정해서 실행합니다.
src/redis-server redis.conf
2. TCP backlog 설정값 오류
문제
WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
리눅스 설정(/proc/sys/net/core/somaxconn)은 128로 되어 있는데 redis.conf의 TCP backlog는 511로 설정되어 있기 때문에 리눅스 설정 값을 증가하라는 메시지입니다.
backlog란? 물리적 네트워크 포트에서 패킷을 쌓아두는 커널의 큐 크기
TCP backlog란? Redis 서버의 초당 클라이언트 연결 수
somaxconn이란? socket max connection의 약자로 네트워크 연결 최대 수
somaxconn 값 확인하기
$ sysctl -a | grep somaxconn
net.core.somaxconn = 128
해결 방법
sysctl.conf 파일의 somaxconn 값을 변경해줍니다.
$ sudo vi /etc/sysctl.conf
net.core.somaxconn = 4096
설정이 영구적으로 적용되게 하기 위해서 인스턴스를 재부팅하거나 아래 명령어를 실행해줍니다.
$ sudo sysctl net.core.somaxconn=4096
3. Memory overcommit 미설정
문제
WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
Memory overcommit이 반드시 실행되어야 한다고 적혀있습니다.
메모리가 부족하면 백그라운드 저장이나 복제가 실패할 수 있고, 장애가 발생할 수 있습니다.
해결 방법
sysctl.conf 파일의 vm.overcommit_memory 값을 1로 변경해줍니다.
$ sudo vi /etc/sysctl.conf
vm.overcommit_memory = 1
설정이 영구적으로 적용되게 하기 위해서 인스턴스를 재부팅하거나 아래 명령어를 실행해줍니다.
✔️ 이 글에서 진행할 것들 1. Redis 설치 2. Node Exporter 설치 3. Redis Exporter 설치 4. Prometheus 설치 5. Prometheus에 Exporter 연결 6. Grafana 설치 7. Grafana에 Prometheus 연결 8. Grafana에 대시보드 생성 9. Alertmanager 설치 및 Dooray! 인커밍 훅 알림 설정
monitored 인스턴스에 node exporter와 설치한 redis 버전별로 redis exporter를 설치합니다.
monitoring 인스턴스에 prometheus를 설치하고 exporter들을 연결합니다.
monitoring 인스턴스에 grafana를 설치하고 prometheus를 연결해주면, 최종적으로 exporter에서 수집되는 메트릭을 시각화해서 grafana로 확인할 수 있습니다.
이 과정을 아래에서 하나씩 진행해보겠습니다 :)
설치 환경
NHN Cloud
CentOS 7.9
Redis 6.2.9, 7.0.11
Node Exporter 1.5.0
Redis Exporter
Prometheus 2.44.0
Grafana Enterprise 9.5.2
Alertmanager 0.25.0
구성도
Redis Server에 Node Exporter와 설치한 Redis 버전 별로 Redis Exporter를 설치합니다.
wget https://go.dev/dl/go1.20.4.linux-amd64.tar.gz
sudo tar xfz go1.20.4.linux-amd64.tar.gz -C /usr/local
sudo vi /etc/profile
###golang
export PATH=$PATH:/usr/local/go/bin
source /etc/profile
go version
# go version go1.20.4 linux/amd64
우리 팀에서 하고 있는 DB 모니터링 방법 중 하나는 프로메테우스와 그라파나를 이용하는 것이다. DBMS variables 비교 사이트에서 다뤘던 Redis, MySQL, PostgreSQL 중 하나씩 맡아서 직접 모니터링을 구축해보는 시간을 갖게 되었고, Redis를 담당하게 되었다.
NHN 면접에서 어떤 메트릭을 어떻게 모니터링 할 수 있을 지에 대한 질문을 받아보기도 했었고, 늘 해보고 싶던 부분이어서 이번 기회에 확실히 알고 넘어가야겠다! 아자 💪
과제 요구사항은 다음과 같다. 일단 다 처음이기 때문에 주신 내용을 이해하는게 먼저..! 하나씩 스터디하면서 차근차근 설치해봐야겠다 :)