자체 인스턴스를 사용하는 Redis 복제 및 장애 조치
GitLab v19.5Offering: GitLab Self-Managed
요약
클라우드 공급자에서 GitLab을 호스팅한다면 Redis 용 관리형 서비스를 선택적으로 사용할 수 있습니다. 또는 Linux 패키지와 별개로 자체 Redis 인스턴스를 직접 관리할 수도 있습니다. 자체 Redis 인스턴스를 제공할 때의 요구 사항은 다음과 같습니다.
클라우드 공급자에서 GitLab을 호스팅한다면 Redis 용 관리형 서비스를 선택적으로 사용할 수 있습니다. 예를 들어 AWS는 Redis를 실행하는 ElastiCache를 제공합니다.
또는 Linux 패키지와 별개로 자체 Redis 인스턴스를 직접 관리할 수도 있습니다.
요구 사항#
자체 Redis 인스턴스를 제공할 때의 요구 사항은 다음과 같습니다.
- 필요한 최소 Redis 버전은 요구 사항 페이지에서 확인합니다.
- 단독 Redis 또는 Sentinel을 사용하는 Redis 고가용성 구성이 지원됩니다. Redis Cluster는 지원되지 않습니다.
- AWS ElastiCache 같은 클라우드 공급자의 관리형 Redis도 문제없이 동작합니다. 해당 서비스가 고가용성을 지원한다면 Redis Cluster 유형이 아닌지 확인합니다.
Redis 노드의 IP 주소 또는 호스트 이름, 포트, 그리고 필요하다면 비밀번호를 기록해 둡니다.
클라우드 공급자의 관리형 서비스로 사용하는 Redis#
-
요구 사항에 따라 Redis를 설정합니다.
-
/etc/gitlab/gitlab.rb파일에서 외부 Redis 서비스에 맞는 연결 정보로 GitLab 애플리케이션 서버를 구성합니다.단일 Redis 인스턴스를 사용하는 경우는 다음과 같습니다.
redis['enable'] = false gitlab_rails['redis_host'] = '<redis_instance_url>' gitlab_rails['redis_port'] = '<redis_instance_port>' # Required if Redis authentication is configured on the Redis node gitlab_rails['redis_password'] = '<redis_password>' # Set to true if instance is using Redis SSL gitlab_rails['redis_ssl'] = trueRedis Cache와 Persistent 인스턴스를 분리해 사용하는 경우는 다음과 같습니다.
redis['enable'] = false # Default Redis connection gitlab_rails['redis_host'] = '<redis_persistent_instance_url>' gitlab_rails['redis_port'] = '<redis_persistent_instance_port>' gitlab_rails['redis_password'] = '<redis_persistent_password>' # Set to true if instance is using Redis SSL gitlab_rails['redis_ssl'] = true # Redis Cache connection # Replace `redis://` with `rediss://` if using SSL gitlab_rails['redis_cache_instance'] = 'redis://:<redis_cache_password>@<redis_cache_instance_url>:<redis_cache_instance_port>' -
변경 사항을 적용하려면 재구성합니다.
sudo gitlab-ctl reconfigure
제거 정책 설정#
단일 Redis 인스턴스를 실행할 때는 제거 정책을 noeviction으로 설정해야 합니다.
Redis Cache와 Persistent 인스턴스를 분리해 실행한다면 Cache는 allkeys-lru를 사용하는 LRU(Least Recently Used) 캐시로 구성하고, Persistent는 noeviction으로 설정해야 합니다.
구성 방법은 클라우드 공급자나 서비스에 따라 다르지만, 일반적으로 다음 설정과 값으로 캐시를 구성합니다.
maxmemory-policy=allkeys-lrumaxmemory-samples=5
자체 Redis 서버를 사용하는 Redis 복제 및 장애 조치#
이 문서는 Linux 패키지에 포함된 Redis 대신 Redis를 직접 설치한 경우에 확장 가능한 Redis 구성을 설정하는 방법을 다룹니다. 다만 GitLab에 맞춰 최적화되어 있고 지원되는 최신 버전으로의 Redis 업그레이드까지 처리되므로 Linux 패키지를 사용하는 방식을 강력히 권장합니다.
또한 구성 파일 문서에
설명된 고급 Redis 설정에 따라
/home/git/gitlab/config/resque.yml에 대한 모든 참조를
재정의하도록 선택할 수도 있습니다.
Linux 패키지 Redis HA의 복제 및 장애 조치 문서에는 Redis 구성에 매우 중요한 정보가 담겨 있으므로 반드시 읽어야 합니다. 이 가이드를 진행하기 전에 해당 문서를 먼저 읽습니다.
새 Redis 인스턴스 설정을 진행하기 전에 다음 요구 사항을 확인합니다.
- 이 가이드의 모든 Redis 서버는 소켓 대신 TCP 연결을 사용하도록
구성해야 합니다. Redis가 TCP 연결을 사용하게 하려면 Redis 구성 파일에서
bind와port를 모두 정의해야 합니다. 모든 인터페이스(0.0.0.0)에 바인딩하거나 원하는 인터페이스의 IP를 지정할 수 있습니다 (예: 내부 네트워크의 IP). - Redis 3.2 부터는 외부 연결을 받으려면 비밀번호(
requirepass)를 정의해야 합니다. - Sentinel과 함께 Redis를 사용한다면 같은 인스턴스에서 복제본 비밀번호
정의(
masterauth)에도 동일한 비밀번호를 정의해야 합니다.
추가로 Linux 패키지를 사용하는 Redis 복제 및 장애 조치에 설명된 사전 요구 사항을 읽습니다.
1단계. 기본 Redis 인스턴스 구성#
Redis 기본 인스턴스의 IP가 10.0.0.1 이라고 가정합니다.
-
/etc/redis/redis.conf를 편집합니다.## Define a `bind` address pointing to a local IP that your other machines ## can reach you. If you really need to bind to an external accessible IP, make ## sure you add extra firewall rules to prevent unauthorized access: bind 10.0.0.1 ## Define a `port` to force redis to listen on TCP so other machines can ## connect to it (default port is `6379`). port 6379 ## Set up password authentication (use the same password in all nodes). ## The password should be defined equal for both `requirepass` and `masterauth` ## when setting up Redis to use with Sentinel. requirepass redis-password-goes-here masterauth redis-password-goes-here -
변경 사항을 적용하려면 Redis 서비스를 재시작합니다.
2단계. 복제본 Redis 인스턴스 구성#
Redis 복제본 인스턴스의 IP가 10.0.0.2 라고 가정합니다.
-
/etc/redis/redis.conf를 편집합니다.## Define a `bind` address pointing to a local IP that your other machines ## can reach you. If you really need to bind to an external accessible IP, make ## sure you add extra firewall rules to prevent unauthorized access: bind 10.0.0.2 ## Define a `port` to force redis to listen on TCP so other machines can ## connect to it (default port is `6379`). port 6379 ## Set up password authentication (use the same password in all nodes). ## The password should be defined equal for both `requirepass` and `masterauth` ## when setting up Redis to use with Sentinel. requirepass redis-password-goes-here masterauth redis-password-goes-here ## Define `replicaof` pointing to the Redis primary instance with IP and port. replicaof 10.0.0.1 6379 -
변경 사항을 적용하려면 Redis 서비스를 재시작합니다.
-
나머지 모든 복제본 노드에 대해 같은 단계를 반복합니다.
3단계. Redis Sentinel 인스턴스 구성#
Sentinel은 특수한 유형의 Redis 서버입니다. redis.conf에서 정의할 수 있는
기본 구성 옵션 대부분을 그대로 사용하며, 일부 전용 옵션은
sentinel 접두사로 시작합니다.
Redis Sentinel 이 IP 10.0.0.1 인 Redis 기본 인스턴스와 같은 인스턴스에
설치되어 있다고 가정합니다(일부 설정은 기본 인스턴스와 겹칠 수 있습니다).
-
/etc/redis/sentinel.conf를 편집합니다.## Define a `bind` address pointing to a local IP that your other machines ## can reach you. If you really need to bind to an external accessible IP, make ## sure you add extra firewall rules to prevent unauthorized access: bind 10.0.0.1 ## Define a `port` to force Sentinel to listen on TCP so other machines can ## connect to it (default port is `6379`). port 26379 ## Set up password authentication (use the same password in all nodes). ## The password should be defined equal for both `requirepass` and `masterauth` ## when setting up Redis to use with Sentinel. requirepass redis-password-goes-here masterauth redis-password-goes-here ## Define with `sentinel auth-pass` the same shared password you have ## defined for both Redis primary and replicas instances. sentinel auth-pass gitlab-redis redis-password-goes-here ## Define with `sentinel monitor` the IP and port of the Redis ## primary node, and the quorum required to start a failover. sentinel monitor gitlab-redis 10.0.0.1 6379 2 ## Define with `sentinel down-after-milliseconds` the time in `ms` ## that an unresponsive server is considered down. sentinel down-after-milliseconds gitlab-redis 10000 ## Define a value for `sentinel failover_timeout` in `ms`. This has multiple ## meanings: ## ## * The time needed to re-start a failover after a previous failover was ## already tried against the same primary by a given Sentinel, is two ## times the failover timeout. ## ## * The time needed for a replica replicating to a wrong primary according ## to a Sentinel current configuration, to be forced to replicate ## with the right primary, is exactly the failover timeout (counting since ## the moment a Sentinel detected the misconfiguration). ## ## * The time needed to cancel a failover that is already in progress but ## did not produce any configuration change (REPLICAOF NO ONE yet not ## acknowledged by the promoted replica). ## ## * The maximum time a failover in progress waits for all the replicas to be ## reconfigured as replicas of the new primary. However even after this time ## the replicas are reconfigured by the Sentinels anyway, but not with ## the exact parallel-syncs progression as specified. sentinel failover_timeout 30000 -
변경 사항을 적용하려면 Redis 서비스를 재시작합니다.
-
나머지 모든 Sentinel 노드에 대해 같은 단계를 반복합니다.
4단계. GitLab 애플리케이션 구성#
새 설치본과 기존 설치본 모두에서 언제든지 Sentinel 지원을 활성화하거나 비활성화할 수 있습니다. GitLab 애플리케이션 관점에서 필요한 것은 Sentinel 노드의 올바른 자격 증명뿐입니다.
모든 Sentinel 노드의 목록이 필요하지는 않지만, 장애가 발생하면 나열된 노드 중 최소 하나에는 접근할 수 있어야 합니다.
다음 단계는 GitLab 애플리케이션 서버에서 수행해야 하며, 이 서버에는 Redis 나 Sentinel 이 함께 있지 않은 것이 좋습니다.
-
resque.yml.example의 예시에 따라/home/git/gitlab/config/resque.yml을 편집하고, Sentinel 줄의 주석을 해제해 올바른 서버 자격 증명을 지정합니다.# resque.yaml production: url: redis://:redis-password-goes-here@gitlab-redis/ sentinels: - host: 10.0.0.1 port: 26379 # point to sentinel, not to redis port - host: 10.0.0.2 port: 26379 # point to sentinel, not to redis port - host: 10.0.0.3 port: 26379 # point to sentinel, not to redis port -
변경 사항을 적용하려면 GitLab을 재시작합니다.
기본 1대, 복제본 2대, Sentinel 3대로 구성한 최소 구성 예시#
이 예시에서는 모든 서버가 10.0.0.x 대역의 IP를 가진 내부 네트워크
인터페이스를 갖고 있고, 이 IP로 서로 연결할 수 있다고
가정합니다.
실제 운영 환경이라면 다른 머신의 무단 액세스를 막고 외부에서 들어오는 트래픽을 차단하도록 방화벽 규칙도 함께 설정하게 됩니다(인터넷).
이 예시에서 Sentinel 1은 Redis Primary와 같은 머신에, Sentinel 2는 Replica 1과 같은 머신에, Sentinel 3은 Replica 2와 같은 머신에 구성되어 있습니다.
각 머신과 할당된 IP의 목록과 설명은 다음과 같습니다.
10.0.0.1: Redis Primary + Sentinel 110.0.0.2: Redis Replica 1 + Sentinel 210.0.0.3: Redis Replica 2 + Sentinel 310.0.0.4: GitLab 애플리케이션
초기 구성 이후 Sentinel 노드가 장애 조치를 시작하면 Redis 노드가
재구성되고, 새 장애 조치가 다시 시작될 때까지 Primary가
한 노드에서 다른 노드로 영구히 바뀝니다(redis.conf에도
반영됩니다).
sentinel.conf도 마찬가지로 초기 실행 이후, 새 Sentinel 노드가
Primary 감시를 시작할 때, 또는 장애 조치로 다른 Primary 노드가
승격될 때 덮어써집니다.
Redis 기본 인스턴스와 Sentinel 1 구성 예시#
-
/etc/redis/redis.conf에 다음을 설정합니다.bind 10.0.0.1 port 6379 requirepass redis-password-goes-here masterauth redis-password-goes-here -
/etc/redis/sentinel.conf에 다음을 설정합니다.bind 10.0.0.1 port 26379 sentinel auth-pass gitlab-redis redis-password-goes-here sentinel monitor gitlab-redis 10.0.0.1 6379 2 sentinel down-after-milliseconds gitlab-redis 10000 sentinel failover_timeout 30000 -
변경 사항을 적용하려면 Redis 서비스를 재시작합니다.
Redis 복제본 1과 Sentinel 2 구성 예시#
-
/etc/redis/redis.conf에 다음을 설정합니다.bind 10.0.0.2 port 6379 requirepass redis-password-goes-here masterauth redis-password-goes-here replicaof 10.0.0.1 6379 -
/etc/redis/sentinel.conf에 다음을 설정합니다.bind 10.0.0.2 port 26379 sentinel auth-pass gitlab-redis redis-password-goes-here sentinel monitor gitlab-redis 10.0.0.1 6379 2 sentinel down-after-milliseconds gitlab-redis 10000 sentinel failover_timeout 30000 -
변경 사항을 적용하려면 Redis 서비스를 재시작합니다.
Redis 복제본 2와 Sentinel 3 구성 예시#
-
/etc/redis/redis.conf에 다음을 설정합니다.bind 10.0.0.3 port 6379 requirepass redis-password-goes-here masterauth redis-password-goes-here replicaof 10.0.0.1 6379 -
/etc/redis/sentinel.conf에 다음을 설정합니다.bind 10.0.0.3 port 26379 sentinel auth-pass gitlab-redis redis-password-goes-here sentinel monitor gitlab-redis 10.0.0.1 6379 2 sentinel down-after-milliseconds gitlab-redis 10000 sentinel failover_timeout 30000 -
변경 사항을 적용하려면 Redis 서비스를 재시작합니다.
GitLab 애플리케이션 구성 예시#
-
/home/git/gitlab/config/resque.yml을 편집합니다.production: url: redis://:redis-password-goes-here@gitlab-redis/ sentinels: - host: 10.0.0.1 port: 26379 # point to sentinel, not to redis port - host: 10.0.0.2 port: 26379 # point to sentinel, not to redis port - host: 10.0.0.3 port: 26379 # point to sentinel, not to redis port -
변경 사항을 적용하려면 GitLab을 재시작합니다.
문제 해결#
Redis 문제 해결 가이드를 참고합니다.