正式なドキュメントは英語版であり、この日本語訳はAI支援翻訳により作成された参考用のものです。日本語訳の一部の内容は人間によるレビューがまだ行われていないため、翻訳のタイミングにより英語版との間に差異が生じることがあります。最新かつ正確な情報については、英語版をご参照ください。

Redisのレプリケーションとフェイルオーバーにより、独自のインスタンスを提供します

  • プラン: Free、Premium、Ultimate
  • 提供形態: GitLab Self-Managed

GitLabをクラウドプロバイダーでホストしている場合、オプションでRedisのマネージドサービスを使用できます。たとえば、AWSはRedisを実行するElastiCacheを提供しています。

または、Linuxパッケージとは別に、独自のRedisインスタンスを管理することもできます。

要件

以下は、独自のRedisインスタンスを提供するための要件です:

  • 要件ページで必要なRedisの最小バージョンを確認してください。
  • スタンドアロンRedisまたはSentinelによるRedisHigh Availabilityがサポートされています。Redisクラスターはサポートされていません。
  • AWS ElastiCacheなどのクラウドプロバイダーからのマネージドRedisは正常に動作します。これらのサービスがHigh Availabilityをサポートしている場合は、Redisクラスタータイプではないことを確認してください。

RedisノードのIPアドレスまたはホスト名、ポート、およびパスワード(必要な場合)をメモしておきます。

クラウドプロバイダーでのマネージドサービスとしてのRedis

  1. 要件に従ってRedisを設定します。

  2. /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'] = true

    個別のRedisキャッシュと永続的なインスタンスを使用する場合:

    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>'
  3. 変更を有効にするには、再構成してください:

    sudo gitlab-ctl reconfigure

削除ポリシーの設定

単一のRedisインスタンスを実行している場合、削除ポリシーはnoevictionに設定する必要があります。

個別のRedisキャッシュと永続的なインスタンスを実行している場合、キャッシュはLeast Recently Used cache(LRU)としてallkeys-lruで設定し、永続的はnoevictionに設定する必要があります。

この設定はクラウドプロバイダーまたはサービスによって異なりますが、一般的に次の設定と値はキャッシュを設定します:

  • maxmemory-policy = allkeys-lru
  • maxmemory-samples = 5

独自のRedisサーバーによるRedisレプリケーションとフェイルオーバー

これは、Linuxパッケージに付属しているバンドルを使用せずに、Redisを自分でインストールした場合にスケーラブルなRedis設定を構成するためのドキュメントです。ただし、Linuxパッケージを使用すると、GitLab用に最適化され、サポートされている最新バージョンにRedisをアップグレードするため、強くお勧めします。

また、設定ファイルドキュメントに概説されている高度なRedis設定に従って、/home/git/gitlab/config/resque.ymlへのすべての参照をオーバーライドすることもできます。

LinuxパッケージRedis HAのレプリケーションとフェイルオーバーに関するドキュメントを読むことの重要性をいくら強調してもしすぎることはありません。これはRedisの設定に非常に貴重な情報を提供するからです。このガイドに進む前に読んでください。

新しいRedisインスタンスのセットアップに進む前に、いくつかの要件を以下に示します:

  • このガイドのすべてのRedisサーバーは、ソケットの代わりにTCP接続を使用するように設定する必要があります。TCP接続を使用するようにRedisを設定するには、Redis設定ファイルでbindportの両方を定義する必要があります。すべてのインターフェース(0.0.0.0)にバインドするか、目的のインターフェースのIP(たとえば、内部ネットワークからのもの)を指定できます。
  • Redis 3.2以降では、外部接続を受信するにはパスワード(requirepass)を定義する必要があります。
  • RedisとSentinelを使用している場合は、同じインスタンス内のレプリカパスワード定義(masterauth)にも同じパスワードを定義する必要があります。

さらに、Linuxパッケージを使用したRedisレプリケーションとフェイルオーバーで説明されている前提条件をお読みください。

ステップ1.プライマリRedisインスタンスの設定

RedisプライマリインスタンスのIPが10.0.0.1であると仮定します:

  1. Redisをインストール

  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.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
  3. 変更を有効にするには、Redisサービスを再起動します。

ステップ2.レプリカRedisインスタンスの設定

RedisレプリカインスタンスのIPが10.0.0.2であると仮定します:

  1. Redisをインストール

  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
  3. 変更を有効にするには、Redisサービスを再起動します。

  4. 他のすべてのレプリカノードに対して、手順を繰り返します。

ステップ3.Redis Sentinelインスタンスの設定

Sentinelは、特別なタイプのRedisサーバーです。これは、redis.confで定義できる基本的な設定オプションのほとんどを継承し、特定のオプションはsentinelのプレフィックスで始まります。

Redis Sentinelが、IP 10.0.0.1を持つRedisプライマリと同じインスタンスにインストールされていると仮定します(一部の設定はプライマリとオーバーラップする可能性があります):

  1. Redis Sentinelをインストール

  2. /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 produced 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
  3. 変更を有効にするには、Redisサービスを再起動します。

  4. 他のすべてのSentinelノードに対して、手順を繰り返します。

ステップ4.GitLabアプリケーションの設定

新規または既存のインストールで、Sentinelサポートをいつでも有効または無効にできます。GitLabアプリケーションの観点からは、必要なのはSentinelノードの正しい認証情報だけです。

すべてのSentinelノードのリストは必要ありませんが、フェイルオーバーが発生した場合に、リストされている少なくとも1つにアクセスする必要があります。

次の手順は、理想的には同じマシンにRedisまたはSentinelがないGitLabアプリケーションサーバーで実行する必要があります:

  1. 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
  2. 変更を反映させるため、GitLabを再起動します。

プライマリ1つ、レプリカ2つ、Sentinel3つによる最小設定の例

この例では、すべてのサーバーに10.0.0.xの範囲のIPを持つ内部ネットワークインターフェースがあり、これらのIPを使用して相互に接続できることを前提としています。

実際の使用では、他のマシンからの不正アクセスを防ぐためにファイアウォールルールを設定し、外部からのトラフィック(インターネット)をブロックします。

この例では、Sentinel 1Redis Primary(Redisプライマリ)と同じマシンに、Sentinel 2Replica 1(レプリカ1)と同じマシンに、Sentinel 3Replica 2(レプリカ2)と同じマシンに設定されています。

machine(マシン)と割り当てられたIPのリストと説明を次に示します:

  • 10.0.0.1: Redisプライマリ+ Sentinel 1
  • 10.0.0.2: Redisレプリカ1 + Sentinel 2
  • 10.0.0.3: Redisレプリカ2 + Sentinel 3
  • 10.0.0.4: GitLabアプリケーション

初期設定後、Sentinelノードによってフェイルオーバーが開始された場合、Redisノードは再設定され、新しいフェイルオーバーが再度開始されるまで、プライマリは(redis.confを含む)あるノードから別のノードに完全に変更されます。

新しいSentinelノードがプライマリの監視を開始した後、またはフェイルオーバーが別のプライマリノードをプロモートした後、初期実行後にオーバーライドされるsentinel.confでも同じことが起こります。

RedisプライマリおよびSentinel 1の設定例

  1. /etc/redis/redis.confで:

    bind 10.0.0.1
    port 6379
    requirepass redis-password-goes-here
    masterauth redis-password-goes-here
  2. /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
  3. 変更を有効にするには、Redisサービスを再起動します。

Redisレプリカ1およびSentinel 2の設定例

  1. /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
  2. /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
  3. 変更を有効にするには、Redisサービスを再起動します。

Redisレプリカ2およびSentinel 3の設定例

  1. /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
  2. /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
  3. 変更を有効にするには、Redisサービスを再起動します。

GitLabアプリケーションの設定の例

  1. /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
  2. 変更を反映させるため、GitLabを再起動します。

トラブルシューティング

Redisトラブルシューティングガイドを参照してください。