2.3. HAProxy ロードバランサーと PostgreSQL データベースのセットアップ
次の手順を使用して、HAProxy ロードバランサーと PostgreSQL データベースをセットアップします。
前提条件
- Podman または Docker CLI がインストールされている。
手順
最初の 2 つのシステム
q01とq02に、HAProxy ロードバランサーと PostgreSQL データベースをインストールします。これにより、他のシステムで実行されている次のサービスのアクセスポイントおよびロードバランサーとして HAProxy が設定されます。- Red Hat Quay (B システムではポート 80 および 443)
- Redis (B システムではポート 6379)
- RADOS (C システムではポート 7480)
SELinux ですべての HAProxy ポートを開き、ファイアウォールで選択した HAProxy ポートを開きます。
# setsebool -P haproxy_connect_any=on # firewall-cmd --permanent --zone=public --add-port=6379/tcp --add-port=7480/tcp success # firewall-cmd --reload success
/etc/haproxy/haproxy.cfgを設定して、Red Hat Quay、Redis、および Ceph RADOS サービスを提供するシステムとポートを指すようにします。以下は、デフォルトと追加されたフロントエンドおよびバックエンド設定の例です。#--------------------------------------------------------------------- # common defaults that all the 'listen' and 'backend' sections will # use if not designated in their block #--------------------------------------------------------------------- defaults mode tcp log global option httplog option dontlognull option http-server-close option forwardfor except 127.0.0.0/8 option redispatch retries 3 timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s maxconn 3000 #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- frontend fe_http *:80 default_backend be_http frontend fe_https *:443 default_backend be_https frontend fe_redis *:6379 default_backend be_redis frontend fe_rdgw *:7480 default_backend be_rdgw backend be_http balance roundrobin server quay01 quay01:80 check server quay02 quay02:80 check server quay03 quay03:80 check backend be_https balance roundrobin server quay01 quay01:443 check server quay02 quay02:443 check server quay03 quay03:443 check backend be_rdgw balance roundrobin server ceph01 ceph01:7480 check server ceph02 ceph02:7480 check server ceph03 ceph03:7480 check backend be_redis server quay01 quay01:6379 check inter 1s server quay02 quay02:6379 check inter 1s server quay03 quay03:6379 check inter 1s新しい
haproxy.cfgファイルが配置されたら、次のコマンドを入力して HAProxy サービスを再起動します。# systemctl restart haproxy
次のコマンドを入力して、PostgreSQL データベースのフォルダーを作成します。
$ mkdir -p /var/lib/pgsql/data
/var/lib/pgsql/dataフォルダーに次の権限を設定します。$ chmod 777 /var/lib/pgsql/data
次のコマンドを入力して、PostgreSQL データベースを起動します。
$ sudo podman run -d --name postgresql_database \ -v /var/lib/pgsql/data:/var/lib/pgsql/data:Z \ -e POSTGRESQL_USER=quayuser -e POSTGRESQL_PASSWORD=quaypass \ -e POSTGRESQL_DATABASE=quaydb -p 5432:5432 \ registry.redhat.io/rhel8/postgresql-13:1-109注記コンテナーのデータは、ホストシステムの
/var/lib/pgsql/dataディレクトリーに保存されます。次のコマンドを入力して、使用可能な拡張機能をリスト表示します。
$ sudo podman exec -it postgresql_database /bin/bash -c 'echo "SELECT * FROM pg_available_extensions" | /opt/rh/rh-postgresql96/root/usr/bin/psql'
出力例
name | default_version | installed_version | comment -----------+-----------------+-------------------+---------------------------------------- adminpack | 1.0 | | administrative functions for PostgreSQL ...
次のコマンドを入力して、
pg_trgm拡張機能を作成します。$ sudo podman exec -it postgresql_database /bin/bash -c 'echo "CREATE EXTENSION IF NOT EXISTS pg_trgm;" | /opt/rh/rh-postgresql96/root/usr/bin/psql -d quaydb'
次のコマンドを入力して、
pg_trgmが作成されたことを確認します。$ sudo podman exec -it postgresql_database /bin/bash -c 'echo "SELECT * FROM pg_extension" | /opt/rh/rh-postgresql96/root/usr/bin/psql'
出力例
extname | extowner | extnamespace | extrelocatable | extversion | extconfig | extcondition ---------+----------+--------------+----------------+------------+-----------+-------------- plpgsql | 10 | 11 | f | 1.0 | | pg_trgm | 10 | 2200 | t | 1.3 | | (2 rows)
Postgres ユーザー
quayuserの権限を変更し、superuserロールを付与して、ユーザーにデータベースへの無制限のアクセスを許可します。$ sudo podman exec -it postgresql_database /bin/bash -c 'echo "ALTER USER quayuser WITH SUPERUSER;" | /opt/rh/rh-postgresql96/root/usr/bin/psql'
出力例
ALTER ROLE
システムで firewalld サービスがアクティブになっている場合は、次のコマンドを実行して、ファイアウォール経由で PostgreSQL ポートを使用できるようにします。
# firewall-cmd --permanent --zone=trusted --add-port=5432/tcp
# firewall-cmd --reload
オプション。
postgresCLI パッケージがインストールされていない場合は、次のコマンドを入力してインストールします。# yum install postgresql -y
psqlコマンドを使用して、PostgreSQL データベースへの接続をテストします。注記サービスにリモートでアクセスできることを確認するには、リモートシステムで次のコマンドを実行します。
# psql -h localhost quaydb quayuser
出力例
Password for user test: psql (9.2.23, server 9.6.5) WARNING: psql version 9.2, server version 9.6. Some psql features might not work. Type "help" for help. test=> \q