HA PEM using the SM architecture with Patroni#
このページでは、リファレンスアーキテクチャSMに従って高可用性HAPEM展開をインストールおよび構成するための詳細な手順を提供します。
この例では、クラスター管理にPatroniを使用し、PEMバックエンドデータベースとしてPostgreSQL 17を、プライマリにトラフィックをルーティングするメカニズムとしてマルチホスト文字列を使用します。私たちのオペレーティングシステムはRHEL 9 x86です。
他のオプションを理解するには、 High availability patterns for PEM deployment を参照してください。
また、 Deciding on an SSL model を参照して、インストールを開始する前にSSL証明書とキーを提供する方法を決定します。以下の例では、次のIPアドレスを使用します。
172.16.161.200-PEMバックエンドプライマリ
172.16.161.201-PEMバックエンドスタンバイ1
172.16.161.202-PEMバックエンドスタンバイ2
172.16.161.211-PEM Webアプリケーション1
172.16.161.212-PEM Webアプリケーション2
172.16.161.213-PEM Webアプリケーション3
172.16.161.111 - etcd-node-1
172.16.161.112 - etcd-node-2
172.16.161.113 - etcd-node-3
etcdを使用した分散コンセンサスストアの設定#
Patroniには分散コンセンサスストアDCSが必要です。 etcdを使用してDCSを設定している場合、この手順をスキップして、既存のDCSを使用できます。ここでは、 HA PEMアプリケーションクラスターとは別に、3つのホストに最小限の3ノードDCSを作成します。
各ノードで
PGDGリポジトリからetcdをインストールする
dnf install -y https://download.postgresql.org/pub/repos/yum/reporpms/EL-9-x86_64/pgdg-redhat-repo-latest.noarch.rpm
dnf --enablerepo=pgdg-rhel9-extras install -y etcd
/etc/etcd/etcd.confの内容を次のものに置き換え、<node-ip>およびnode-nameの適切な値を置き換えます。例、172.16.161.111、etcd-node-1。
#[Member]
ETCD_LISTEN_PEER_URLS="http://<node-ip>:2380"
ETCD_LISTEN_CLIENT_URLS="http://localhost:2379,http://<node-ip>:2379"
ETCD_NAME="<node-name>"
#[Clustering]
ETCD_INITIAL_ADVERTISE_PEER_URLS="http://<node-ip>:2380"
ETCD_INITIAL_CLUSTER="etcd-node-1=http://172.16.161.111:2380,etcd-node-2=http://172.16.161.112:2380,etcd-node-3=http://172.16.161.113:2380"
ETCD_ADVERTISE_CLIENT_URLS="http://<node-ip>:2379"
ETCD_INITIAL_CLUSTER_TOKEN="etcd-cluster-1"
ETCD_INITIAL_CLUSTER_STATE="new"
ポート
2380および2379がファイアウォールで開いていることを確認します。
firewall-cmd --zone=public --add-port=2380/tcp --permanent
firewall-cmd --zone=public --add-port=2379/tcp --permanent
firewall-cmd --reload
etcdサービスが再起動され有効になっていることを確認します。
systemctl enable etcd
systemctl restart etcd
EDBリポジトリの構成#
すべてのバックエンドおよびWebアプリケーションノードで、EDB Reposを構成します。詳細については、 Getting started with repositories を参照してください。
curl -1sLf https://downloads.enterprisedb.com/<token>/<repo>/setup.rpm.sh | bash
Patroniクラスターを作成する#
PEMをインストールする前に、バックエンドホストで動作するPatroniクラスターが必要です。このセクションでは、このようなクラスターを展開する手順を提供します。 Patroniクラスターをプロビジョニングする独自のプロセスがある場合、これらの手順に従う必要はありません。ただし、 sslutilsを使用する予定がある場合は、続行する前にクラスターにインストールされていることを確認する必要があります。
初期パッケージのインストールとPostgres構成#
特に記載がない限り、すべてのバックエンドノードで次の手順を実行します。
次のパッケージをインストールします。
PostgreSQLサーバーへの接続エラー PEMサーバーのバックエンドデータベース
dnf -qy module disable postgresql
dnf -y install postgresql17-server postgresql17-contrib edb-patroni
Postgresデータベースを初期化し、サービスを開始します。
PGSETUP_INITDB_OPTIONS="-E UTF-8" /usr/pgsql-17/bin/postgresql-17-setup initdb
systemctl start postgresql-17
systemctl enable postgresql-17
ファイアウォールでポート
5432を開きます。
firewall-cmd --zone=public --add-port=5432/tcp --permanent
firewall-cmd --reload
オプション sslutilsのインストール#
PEMが認証局として機能し、クライアント証明書を自動的に発行する場合、 オプション sslutilsのインストール を構成する必要があります。独自の証明書を提供する予定がある場合は、この手順をスキップできます。
すべてのバックエンドホストにsslutilsパッケージをインストールします。
dnf install sslutils_17
Patroniユーザーを作成する#
プライマリバックエンドホストのみで次の手順を実行します。
Patroniスーパーユーザー、レプリケーション、およびリワインドロールを作成します。スーパーユーザーとして次のSQLを実行します。
-- Patroni superuser
CREATE USER patroni_super WITH SUPERUSER ENCRYPTED PASSWORD your-password-here;
-- Patroni replication user
CREATE USER patroni_rep WITH REPLICATION ENCRYPTED PASSWORD your-password-here;
-- Patroni rewind user, if you intend to enable use_pg_rewind in your Patroni configuration
CREATE USER patroni_rew WITH ENCRYPTED PASSWORD your-password-here;
GRANT EXECUTE ON function pg_catalog.pg_ls_dir(text, boolean, boolean) TO patroni_rew;
GRANT EXECUTE ON function pg_catalog.pg_stat_file(text, boolean) TO patroni_rew;
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text) TO patroni_rew;
GRANT EXECUTE ON function pg_catalog.pg_read_binary_file(text, bigint, bigint, boolean) TO patroni_rew;
選択したパスワードを入力します。
プライマリでPatroniをセットアップする#
/etc/patroni/patroni.ymlでファイルを作成し、次のコンテンツを追加し、クラスターに一致するようにIPアドレスを調整し、必要なクラスターとノード名を指定します。
scope: cluster-name
name: node-name
restapi:
listen: 172.16.161.200:8008
connect_address: 172.16.161.200:8008
etcd3:
hosts:
- 172.16.161.111:2379
- 172.16.161.112:2379
- 172.16.161.113:2379
bootstrap:
dcs:
ttl: 30
loop_wait: 10
retry_timeout: 10
maximum_lag_on_failover: 1048576
postgresql:
use_pg_rewind: true
pg_hba:
- # Allow our Patroni users to connect as required
- host all patroni_super 127.0.0.1/32 scram-sha-256
- host replication patroni_rep 127.0.0.1/32 scram-sha-256
- host all patroni_rew 127.0.0.1/32 scram-sha-256
- host replication patroni_rep 172.16.161.200/32 scram-sha-256
- host all patroni_rew 172.16.161.200/32 scram-sha-256
- host replication patroni_rep 172.16.161.201/32 scram-sha-256
- host all patroni_rew 172.16.161.201/32 scram-sha-256
- host replication patroni_rep 172.16.161.202/32 scram-sha-256
- host all patroni_rew 172.16.161.202/32 scram-sha-256
- # This is the default config for this PG package
- local all all peer
- host all all 127.0.0.1/32 scram-sha-256
- host all all ::1/128 scram-sha-256
- local replication all peer
- host replication all 127.0.0.1/32 scram-sha-256
- host replication all ::1/128 scram-sha-256
initdb:
- encoding: UTF8
- data-checksums
postgresql:
listen: *:5432
connect_address: 172.16.161.200:5432
data_dir: /var/lib/pgsql/17/data
bin_dir: /usr/pgsql-17/bin
authentication:
replication:
username: patroni_rep
password: your-password-here
superuser:
username: patroni_super
password: your-password-here
rewind:
username: patroni_rew
password: your-password-here
parameters:
unix_socket_directories: /var/run/postgresql, /tmp
Postgresサービスを停止して無効にし、Patroniを起動します
systemctl disable --now postgresql-17
systemctl enable --now patroni
スタンバイノードのセットアップ#
各スタンバイノードで
Postgresのサービスを停止して無効にします。
systemctl disable --now postgresql-17
データベースサーバーのデータディレクトリを削除します。
rm -rf /var/lib/pgsql/17/data
/etc/patroni/patroni.ymlにPatroni構成ファイルを作成します。プライマリと同じコンテンツを使用しますが、次の変更を行います。bootstrapセクション全体を削除しますnameを各スタンバイの一意の名前に変更しますrestapiおよびpostgresql.connect_addressの下のIPアドレスを、構成しているスタンバイのアドレスに変更します。
Patroniを起動して有効にします。
systemctl enable --now patroni
これで、機能するPatroniクラスターができましたが、SSLまたはPEMに必要な特定のHBAルールはありません。次のセクションでこれらを構成します。
PEMインストール用のPatroniクラスターの準備#
HAモードでPEMをインストールする前に、クラスターが2つの要件を満たしていることを確認する必要があります。
PEMエージェントからPEMバックエンドデータベースへの接続に
cert認証方法を使用できるようにSSLが構成されます。HBAルールが適用され、エージェントとWebアプリケーションインスタンスがPEMバックエンドに接続できます。
SSLファイルの準備#
Generating SSL files for HA PEM backend hosts の指示に従ってください。
Patroniクラスターを変更してSSLおよびHBAルールを追加する#
バックエンドホストで、
patronictl edit-configを使用してクラスターの編集ツールを開きます。たとえば、前のセクションで構築されたクラスターのコマンドは次のとおりです。
patronictl -c /etc/patroni/patroni.yml edit-config
postgresql.parametersの下に次を追加します。
ssl: on
ssl_ca_file: root.crt
ssl_cert_file: server.crt
ssl_key_file: server.key
CRLがある場合は、次も設定します。
ssl_crl_file: root.crl
次のHBAルールを既存のルールの上の
postgresql.pg_hbaの top に追加し、クラスターと一致するようにIPアドレスを調整します。
- # Allow users of the web interface to connect to pem and postgres databases
- hostssl pem +pem_user 127.0.0.1/32 scram-sha-256
- hostssl postgres +pem_user 127.0.0.1/32 scram-sha-256
- hostssl pem +pem_user 172.16.161.211/32 scram-sha-256
- hostssl postgres +pem_user 172.16.161.211/32 scram-sha-256
- hostssl pem +pem_user 172.16.161.212/32 scram-sha-256
- hostssl postgres +pem_user 172.16.161.212/32 scram-sha-256
- hostssl pem +pem_user 172.16.161.213/32 scram-sha-256
- hostssl postgres +pem_user 172.16.161.213/32 scram-sha-256
- # Allow the PEM backend server agents to register and connect to send data to PEM server
- hostssl pem +pem_agent 127.0.0.1/32 cert
- hostssl pem +pem_admin 172.16.161.200/32 scram-sha-256
- hostssl pem +pem_agent 172.16.161.200/32 cert
- hostssl pem +pem_admin 172.16.161.201/32 scram-sha-256
- hostssl pem +pem_agent 172.16.161.201/32 cert
- hostssl pem +pem_admin 172.16.161.202/32 scram-sha-256
- hostssl pem +pem_agent 172.16.161.202/32 cert
- # Allow the PEM web app server agents to register and connect to send data to PEM server
- hostssl pem +pem_admin 172.16.161.211/32 scram-sha-256
- hostssl pem +pem_agent 172.16.161.211/32 scram-sha-256
- hostssl pem +pem_admin 172.16.161.212/32 scram-sha-256
- hostssl pem +pem_agent 172.16.161.212/32 scram-sha-256
- hostssl pem +pem_admin 172.16.161.213/32 scram-sha-256
- hostssl pem +pem_agent 172.16.161.213/32 scram-sha-256
- # Allow our superuser to connect to perform cluster configuration
- hostssl pem,postgres pemsuper 172.16.161.202/32 scram-sha-256
- hostssl pem,postgres pemsuper 172.16.161.201/32 scram-sha-256
- hostssl pem,postgres pemsuper 172.16.161.213/32 scram-sha-256
- hostssl pem,postgres pemsuper 172.16.161.211/32 scram-sha-256
- hostssl pem,postgres pemsuper 172.16.161.200/32 scram-sha-256
- hostssl pem,postgres pemsuper 172.16.161.212/32 scram-sha-256
- # Allow monitoring agents to connect to PEM
- # Specify a subnet that includes all your monitored servers
- # Duplicate these lines for multiple subnets
- hostssl pem +pem_user 0.0.0.0/0 scram-sha-256
- hostssl pem +pem_agent 0.0.0.0/0 cert
共通エージェントユーザーを使用する場合、PEMのインストール中に最初のエージェントが接続できるように1行追加します。この行は、必要に応じて後で削除できます。
- hostssl pem common_agent_user 127.0.0.1/32 cert
非SSLクラスターで開始した場合、既存のHBAルールを確認し、
hostルールをhostsslルールに変換して、必要に応じてクライアントに安全な接続を使用させることを検討します。
エージェントユーザーと証明書の準備#
独自のSSL証明書を提供する場合は、次の手順に従ってPEM展開の準備をします。 sslutilsを使用している場合、このセクションをスキップしてください。
プライマリで、共通エージェントユーザーを作成します。 template1
に対する接続権限を共通エージェントユーザーに付与します。
これは一時的にのみ必要で、後で取り消すことができます。
CREATE USER common_agent_user;
GRANT CONNECT ON DATABASE template1 TO common_agent_user;
このユーザーの証明書とキーペアを生成し、すべてのバックエンドおよびWebアプリケーションホストに保存します。
PEMは、3つのバックエンドと3つのフロントエンドホストにわたる展開に対して、一意の番号付けのPostgresユーザーagent1〜agent6を自動的に生成します。
この構成をサポートするには、6つの異なる証明書/キーペア特定のエージェントユーザーごとに1つを手動で生成し、各ホストが独自の一意のペアを持つようにそれらを配布する必要があります。
プライマリにPEMをインストールする#
プライマリホストでのみ次の手順を実行します。
PEMパッケージをインストールします。
dnf install edb-pem --allowerasing
パスワードを使用してログインできるスーパーユーザーを作成します。これは、PEMのインストールに使用するユーザーです。また、PEMバックエンドホストで実行されているエージェントのエージェントサーバーバインディングユーザーにもなります。
su - postgres -c "psql -c \"create role pemsuper login superuser password your-password-here;\""
PEMサーバーを構成するには、3つのバックエンドホストすべてのIPを指定するデータベースオプションオプション3を使用して構成スクリプトを実行します。プライマリの外部IPアドレスではなく、ループバックIPアドレスを提供します。
システムが高可用性HA用に正しくセットアップされていることを確認するには、次のフラグを含める必要があります。
``--replication-solution efm`` & ``--replication-role primary`` これらのフラグはスクリプトを強制的にHAモードに設定し、フェールオーバーマネージャーとの互換性を保証します。
``--skip-db-certificate`` これにより、 HA環境で証明書を手動で管理しているため、スクリプトがSSLを自動構成しようとするのを防ぎます。
sslutilsを使用する場合、 --use-existing-sslutils
を含める必要があります。これにより、スクリプトはデータベースSSLセットアップをスキップしますが、
sslutils拡張機能を利用してエージェント証明書の生成を処理します。
/usr/edb/pem/bin/configure-pem-server.sh -t 3 \
-ho 127.0.0.1,172.16.161.201,172.16.161.202 \
-p 5432 \
-su pemsuper \
--asb-host-name 127.0.0.1 \
--replication-solution patroni \
--replication-role primary \
--skip-db-certificate \
--use-existing-sslutils \
--db-install-path /usr/pgsql-17/ \
--db-unitfile patroni
共通エージェントユーザを使用する場合、ユーザ名と、そのユーザ用に生成された証明書とキーへのパスを提供する必要があります。
/usr/edb/pem/bin/configure-pem-server.sh -t 3 \
-ho 127.0.0.1,172.16.161.201,172.16.161.202 \
-p 5432 \
-su pemsuper \
--asb-host-name 127.0.0.1 \
--replication-solution patroni \
--replication-role primary \
--db-unitfile patroni \
--db-install-path /usr/pgsql-17/ \
--skip-db-certificate \
--use-agent-user common_agent_user \
--use-agent-sslcert /path/to/agent/cert \
--use-agent-sslkey /path/to/agent/key
このコマンドを実行した後、共通エージェントユーザーにpem_agentロールを付与し、template1
でのその権限を取り消します。
GRANT pem_agent to common_agent_user;
REVOKE CONNECT ON DATABASE template1 FROM common_agent_user;
+pem_agent
ルールと一致するため、必要に応じて、この段階で共通エージェントユーザーに追加したHBAルールを削除することもできます。
独自の証明書を使用する場合、 agent_idを1
として指定し、対応するagent1
ユーザー用に生成された証明書とキーへのパスを指定する必要があります。
/usr/edb/pem/bin/configure-pem-server.sh -t 3 \
-ho 127.0.0.1,172.16.161.201,172.16.161.202 \
-p 5432 \
-su pemsuper \
--asb-host-name 127.0.0.1 \
--replication-solution patroni \
--replication-role primary \
--db-unitfile patroni \
--db-install-path /usr/pgsql-17/ \
--skip-db-certificate \
--use-agent-sslcert /path/to/agent/cert \
--use-agent-sslkey /path/to/agent/key \
-aro agent_id=1
さまざまな追加の詳細の入力を求められます。構成オプションについては、 Configuring the PEM server on Linux を参照してください。
スタンバイにPEMをインストールする#
スタンバイホストのみで次の手順を実行します。
PEMパッケージをインストールします。
dnf install edb-pem --allowerasing
PEMサーバーを構成するには、データベースオプションオプション3を使用して構成スクリプトを実行し、ホストを仮想IPVIPに設定します。
高可用性HAモードを正しく有効にするには、次の特定のフラグを含める必要があります。
``--replication-solution efm`` 構成をEnterprise Failover ManagerEFMと統合します。
``--replication-role standby`` 内でのこのノードの初期ロールを指定しますHAクラスター
/usr/edb/pem/bin/configure-pem-server.sh -t 3 \
-ho 172.16.161.200,127.0.0.1,172.16.161.202 \
-p 5432 \
-su pemsuper \
--asb-host-name 127.0.0.1 \
--replication-solution patroni \
--replication-role standby \
--db-unitfile patroni \
--db-install-path /usr/pgsql-17/
共通エージェントユーザを使用する場合、ユーザ名と、そのユーザ用に生成された証明書とキーへのパスを提供する必要があります。
/usr/edb/pem/bin/configure-pem-server.sh -t 3 \
-ho 172.16.161.200,127.0.0.1,172.16.161.202 \
-p 5432 \
-su pemsuper \
--asb-host-name 127.0.0.1 \
--replication-solution patroni \
--replication-role standby \
--db-unitfile patroni \
--db-install-path /usr/pgsql-17/ \
--use-agent-user common_agent_user \
--use-agent-sslcert /path/to/agent/cert \
--use-agent-sslkey /path/to/agent/key
独自の証明書を使用する場合、agent_idを次の整数N
として指定し、証明書へのパスと、対応するagentN
ユーザー用に生成されたキーを指定する必要があります。
/usr/edb/pem/bin/configure-pem-server.sh -t 3 \
-ho 172.16.161.200,127.0.0.1,172.16.161.202 \
-p 5432 \
-su pemsuper \
--asb-host-name 127.0.0.1 \
--replication-solution patroni \
--replication-role standby \
--db-unitfile patroni \
--db-install-path /usr/pgsql-17/ \
--use-agent-sslcert /path/to/agent/cert \
--use-agent-sslkey /path/to/agent/key \
-aro agent_id=2
さまざまな追加の詳細の入力を求められます。構成オプションについては、 Configuring the PEM server on Linux を参照してください。
PEM Webアプリケーションの展開#
すべてのWebアプリケーションホストで次の手順を実行します。
PEMパッケージとPostgresクライアントバイナリ用をインストールします。
dnf install edb-pem postgresql17-server
すべてのサーバーのファイアウォールで次のポートを開きます。
PEMサーバーHTTPSの
8443
例
firewall-cmd --zone=public --add-port=8443/tcp --permanent
firewall-cmd --reload
PEM Webアプリケーションを構成します。プライマリとすべてのスタンバイを含むマルチホスト文字列をPEMサーバーアドレスとして提供します。
/usr/edb/pem/bin/configure-pem-server.sh -t 2 \
-ho 172.16.161.200,172.16.161.201,172.16.161.202 \
-p 5432 \
-su pemsuper \
--db-install-path /usr/pgsql-17/
共通エージェントユーザを使用する場合、ユーザ名と、そのユーザ用に生成された証明書とキーへのパスを提供する必要があります。
/usr/edb/pem/bin/configure-pem-server.sh -t 2 \
-ho 172.16.161.200,172.16.161.201,172.16.161.202 \
-p 5432 \
-su pemsuper \
--db-install-path /usr/pgsql-17/ \
--use-agent-user common_agent_user \
--use-agent-sslcert /path/to/agent/cert \
--use-agent-sslkey /path/to/agent/key
独自の証明書を使用する場合、agent_idを次の整数N
として指定し、証明書へのパスと、対応するagentN
ユーザー用に生成されたキーを指定する必要があります。
/usr/edb/pem/bin/configure-pem-server.sh -t 2 \
-ho 172.16.161.200,172.16.161.201,172.16.161.202 \
-p 5432 \
-su pemsuper \
--db-install-path /usr/pgsql-17/ \
--use-agent-sslcert /path/to/agent/cert \
--use-agent-sslkey /path/to/agent/key \
-aro agent_id=4
さまざまな追加の詳細の入力を求められます。 構成オプションについては、 Configuring the PEM server on Linux を参照してください。
configure-selinux.shスクリプトを実行して、PEMのSELinuxポリシーを構成します。
USE_NGINX=1 /usr/edb/pem/bin/configure-selinux.sh
これで、前に作成した
pemsuperスーパーユーザーを使用して、Webアプリケーションインスタンスにログインできます。インスタンス間でPEM Webアプリケーションのユーザー設定を同期することを選択した場合、 configuring each web application instance to use the backend for user settings によって今すぐセットアップを完了します。