バンドルされているPgBouncerサービスでの作業

高可用性スタックの一部として、GitLab Premium には/etc/gitlab/gitlab.rbで管理できるPgBouncerがバンドルされています。 PgBouncer は、フェイルオーバーシナリオでサーバー間のデータベース接続をシームレスに移行するために使用されます。 さらに、HA 以外のセットアップで接続をプールするために使用することもでき、リソースの使用量を削減しながらレスポンスタイムを高速化します。

HAセットアップでは、内部ロードバランサ(TCP) 、各データベースノードに対して個別にPgBouncerノードを実行することを推奨します。

オペレーション

HA GitLabインストールの一部としてPgBouncerを実行する方法

このコンテンツは新しい場所に移動しました。

非HA GitLabインストールの一部としてPgBouncerを実行する場合

  1. コマンドでPGBOUNCER_USER_PASSWORD_HASHを生成します。gitlab-ctl pg-password-md5 pgbouncer

  2. コマンドでSQL_USER_PASSWORD_HASHを生成gitlab-ctl pg-password-md5 gitlab。 後で平文のSQL_USER_PASSWORDも入力する必要があります。

  3. データベース・ノードの/etc/gitlab/gitlab.rb

    postgresql['pgbouncer_user_password'] = 'PGBOUNCER_USER_PASSWORD_HASH'
    postgresql['sql_user_password'] = 'SQL_USER_PASSWORD_HASH'
    postgresql['listen_address'] = 'XX.XX.XX.Y' # Where XX.XX.XX.Y is the ip address on the node postgresql should listen on
    postgresql['md5_auth_cidr_addresses'] = %w(AA.AA.AA.B/32) # Where AA.AA.AA.B is the IP address of the pgbouncer node
    
  4. 走るgitlab-ctl reconfigure

    注:データベースがすでに実行されている場合は、再設定後にgitlab-ctl restart postgresqlを実行して再起動する必要があります。

  5. PgBouncerを実行しているノード上で、以下が設定されていることを確認してください。/etc/gitlab/gitlab.rb

    pgbouncer['enable'] = true
    pgbouncer['databases'] = {
      gitlabhq_production: {
        host: 'DATABASE_HOST',
        user: 'pgbouncer',
        password: 'PGBOUNCER_USER_PASSWORD_HASH'
      }
    }
    
  6. 走るgitlab-ctl reconfigure

  7. Pumaが稼動しているノードで、以下が設定されていることを確認します。/etc/gitlab/gitlab.rb

    gitlab_rails['db_host'] = 'PGBOUNCER_HOST'
    gitlab_rails['db_port'] = '6432'
    gitlab_rails['db_password'] = 'SQL_USER_PASSWORD'
    
  8. 走るgitlab-ctl reconfigure

  9. この時点で、インスタンスはPgBouncerを通してデータベースに接続するはずです。 問題がある場合は、トラブルシューティングのセクションを参照してください。

モニタリングの有効化

GitLab 12.0から導入されました

モニタリングを有効にする場合、全てのPgBouncerサーバーで有効にする必要があります。

  1. /etc/gitlab/gitlab.rb を作成/編集し、以下の設定を追加します:

    # Enable service discovery for Prometheus
    consul['enable'] = true
    consul['monitoring_service_discovery'] =  true
    
    # Replace placeholders
    # Y.Y.Y.Y consul1.gitlab.example.com Z.Z.Z.Z
    # with the addresses of the Consul server nodes
    consul['configuration'] = {
       retry_join: %w(Y.Y.Y.Y consul1.gitlab.example.com Z.Z.Z.Z),
    }
    
    # Set the network addresses that the exporters will listen on
    node_exporter['listen_address'] = '0.0.0.0:9100'
    pgbouncer_exporter['listen_address'] = '0.0.0.0:9188'
    
  2. sudo gitlab-ctl reconfigure を実行して設定をコンパイルします。

PgBouncerとの対話

管理コンソール

Omnibus GitLabの一部として、PgBouncer管理コンソールに自動的に接続するためのコマンドgitlab-ctl pgb-console 。 コンソールとの対話方法の詳細については、PgBouncerのドキュメントを参照してください。

セッションを開始するには

# gitlab-ctl pgb-console
Password for user pgbouncer:
psql (11.7, server 1.7.2/bouncer)
Type "help" for help.

pgbouncer=#

パスワードはPGBOUNCER_USER_PASSWORDです。

インスタンスに関する基本的な情報を得るには、以下を実行します。

pgbouncer=# show databases; show clients; show servers;
        name         |   host    | port |      database       | force_user | pool_size | reserve_pool | pool_mode | max_connections | current_connections
---------------------+-----------+------+---------------------+------------+-----------+--------------+-----------+-----------------+---------------------
 gitlabhq_production | 127.0.0.1 | 5432 | gitlabhq_production |            |       100 |            5 |           |               0 |                   1
 pgbouncer           |           | 6432 | pgbouncer           | pgbouncer  |         2 |            0 | statement |               0 |                   0
(2 rows)

 type |   user    |      database       | state  |   addr    | port  | local_addr | local_port |    connect_time     |    request_time     |    ptr    | link
| remote_pid | tls
------+-----------+---------------------+--------+-----------+-------+------------+------------+---------------------+---------------------+-----------+------
+------------+-----
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44590 | 127.0.0.1  |       6432 | 2018-04-24 22:13:10 | 2018-04-24 22:17:10 | 0x12444c0 |
|          0 |
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44592 | 127.0.0.1  |       6432 | 2018-04-24 22:13:10 | 2018-04-24 22:17:10 | 0x12447c0 |
|          0 |
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44594 | 127.0.0.1  |       6432 | 2018-04-24 22:13:10 | 2018-04-24 22:17:10 | 0x1244940 |
|          0 |
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44706 | 127.0.0.1  |       6432 | 2018-04-24 22:14:22 | 2018-04-24 22:16:31 | 0x1244ac0 |
|          0 |
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44708 | 127.0.0.1  |       6432 | 2018-04-24 22:14:22 | 2018-04-24 22:15:15 | 0x1244c40 |
|          0 |
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44794 | 127.0.0.1  |       6432 | 2018-04-24 22:15:15 | 2018-04-24 22:15:15 | 0x1244dc0 |
|          0 |
 C    | gitlab    | gitlabhq_production | active | 127.0.0.1 | 44798 | 127.0.0.1  |       6432 | 2018-04-24 22:15:15 | 2018-04-24 22:16:31 | 0x1244f40 |
|          0 |
 C    | pgbouncer | pgbouncer           | active | 127.0.0.1 | 44660 | 127.0.0.1  |       6432 | 2018-04-24 22:13:51 | 2018-04-24 22:17:12 | 0x1244640 |
|          0 |
(8 rows)

 type |  user  |      database       | state |   addr    | port | local_addr | local_port |    connect_time     |    request_time     |    ptr    | link | rem
ote_pid | tls
------+--------+---------------------+-------+-----------+------+------------+------------+---------------------+---------------------+-----------+------+----
--------+-----
 S    | gitlab | gitlabhq_production | idle  | 127.0.0.1 | 5432 | 127.0.0.1  |      35646 | 2018-04-24 22:15:15 | 2018-04-24 22:17:10 | 0x124dca0 |      |
  19980 |
(1 row)

トラブルシューティング

PgBouncerを通して接続する際に何らかの問題が発生した場合、最初に確認するのはログです:

# gitlab-ctl tail pgbouncer

さらに、管理コンソールでshow databases の出力を確認できます。 出力では、gitlabhq_production データベースのhost フィールドに値が表示されるはずです。 さらに、current_connections は 1 より大きいはずです。

メッセージLOG: invalid CIDR mask in address

Geoドキュメントの修正案を参照してください。

メッセージLOG: invalid IP mask "md5": Name or service not known

Geoドキュメントの修正案を参照してください。