Instance configuration
======================

これは、クラスターインスタンスでの展開プロセスをカスタマイズするために使用できるTPA設定の概要です。

 :ref:`an overview of configuring a cluster <Cluster configuration>` もあり、クラスター変数とインスタンス変数を一緒に使用して、簡潔でレビューが簡単な\ ``config.yml``
を書く方法を説明します。

システムレベルの構成
--------------------

TPAが最初に行うことは、Pythonがブートストラップされ、Ansibleモジュールディストリビューション固有のプロセスを実行する準備ができていることを確認することです。次に、
 :ref:`configures Postgres <#postgres>` する前に、さまざまなシステムレベルの構成タスクを完了します。

-  :ref:`Distribution support <Distribution support>` 

-  :ref:`TPA Python環境のセットアップ <TPA Python環境のセットアップ>`  ``preferred_python_version``

-  :ref:`Environment variables <Environment>`  例 ``https_proxy``

パッケージリポジトリ
^^^^^^^^^^^^^^^^^^^^

 :ref:`pre-deploy hook <TPA hooks>` を使用できます

パッケージリポジトリが構成される前にタスクを実行します。

-  :ref:`Configure YUM repositories <Configuring YUM repositories>` 

(RHEL、Rocky、およびAlmaLinuxの場合)

-  :ref:`Configure APT repositories <Configuring APT repositories>` 

DebianおよびUbuntuの場合

-  :ref:`Configure 2ndQuadrant and EDB repositories <How TPA uses 2ndQuadrant and EDB repositories>` 

任意のシステムで

-  :ref:`Configure a local package repository <Creating and using a local repository>` 

パッケージをターゲットインスタンスにシップするため

 :ref:`post-repo hook <TPA hooks>` を使用できます

パッケージリポジトリの構成後にタスクを実行します。たとえば、パッケージをインストールする前に、リポジトリ構成の問題を修正するために使用できます。

パッケージのインストール
^^^^^^^^^^^^^^^^^^^^^^^^

リポジトリが構成されると、パッケージは展開のさまざまな段階でインストールされます。システムパッケージのバッチから始めます。

-  :ref:`Install non-Postgres packages <Installing packages>` 

例、 acl、openssl、sysstat

Postgresおよびその他のコンポーネントたとえば、
Barman、repmgr、pgbouncerは、クラスター構成に従って個別にインストールされます。
 :ref:`その他のコンポーネント <その他のコンポーネント>` を参照してください。

その他のシステムレベルのタスク
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

-  :ref:`Create and mount file systems <Filesystem configuration>`  RAID、LUKSセットアップを含む

-  :ref:`Upload artifacts <Uploading artifacts>`  ファイル、ディレクトリ、tarアーカイブ

-  :ref:`Set sysctl values <Setting sysctl values>` 

-  :ref:`Configure /etc/hosts <Configuring /etc/hosts>` 

-  :ref:`Manage ssh_known_hosts entries <Managing SSH host keys>` 

-  :ref:`Add system locale <Locale>` 

Postgres
--------

Postgres構成は、repmgrやpgbouncerなどの他のコンポーネントの構成とインターリーブされる拡張プロセスです。最初の手順は、Postgresをインストールすることです。

バージョンの選択
^^^^^^^^^^^^^^^^

 :ref:`configure options <Cluster configuration>` を使用してPostgresフレーバーとバージョンを選択するか、
``config.yml`` で\ ``postgres_version``
を設定して、インストールするPostgresメジャーバージョンを指定します。

作業用クラスターをセットアップするために必要な作業はこれだけです。ここで説明するその他はすべてオプショナル。必要に応じて、展開のあらゆる面を制御できますが、デフォルトは注意深く選択され、開始点として合理的なクラスターを提供します。

インストール
^^^^^^^^^^^^

デフォルトの\ ``postgres_installation_method``
では、アーキテクチャのニーズに応じて、選択したPostgresのバージョンのパッケージをさまざまな拡張機能とともにインストールします。

-  :ref:`Install Postgres and Postgres-related packages <Installing Postgres-related packages>` 

例、 pglogical、 BDRなど

-  :ref:`Build and install Postgres and extensions from source <Postgres source installation>` 

開発およびテスト用

どのインストール方法を選択するかにかかわらず、TPAは最小限の労力で同じクラスター構成を提供できます。

構成
^^^^

-  :ref:`Configure the postgres Unix user <The postgres Unix user>` 

-  :ref:`Run initdb to create the PGDATA directory <Running initdb>` 

-  :ref:`Configure pg_hba.conf <pg_hba.conf>` 

-  :ref:`Configure pg_ident.conf <pg_ident.conf>` 

-  :ref:`Configure postgresql.conf <postgresql.conf>` 

 :ref:`postgres-config hook <TPA hooks>` を使用できます

Postgres構成ファイルがインストールされた後にタスクを実行するにはたとえば、追加の構成ファイルをインストールします。

Postgresの構成が配置されると、TPAは、アーキテクチャの詳細に従って、
Barman、repmgr、pgbouncer、haproxyなどの他のコンポーネントをインストールおよび構成します。

その他のコンポーネント
----------------------

-  :ref:`Configure Barman <Barman>` 

-  :ref:`Configure pgbouncer <Configuring pgbouncer>` 

-  :ref:`Configure haproxy <Configuring haproxy>` 

-  :ref:`Configure HARP <Configuring HARP>` 

-  :ref:`Configure EFM <Configuring EFM>` 

サービスの構成と開始
^^^^^^^^^^^^^^^^^^^^

TPAは、各サービスのsystemdサービスユニットファイルをインストールします。
Postgresのサービスの名前は\ ``postgres.service`` です。
``systemctl start postgres`` を使用して起動し、
``systemctl stop postgres`` を使用して停止できます。

クラスターを初めて展開する場合、TPAはこの時点でPostgresサービスを開始します。既存のクラスターで、関連する構成の変更がある場合、TPAは必要に応じてPostgresサービスをリロードまたは再起動します。変更がなく、Postgresが既に実行されている場合、サービスは放置されます。
Postgresが既存のクラスターで実行されていない場合、TPAはそれを起動します。

いずれの場合も、このステップの最後にPostgresは実行されています。

Postgresを起動した後
--------------------

-  :ref:`Create Postgres users <The postgres Unix user>` 

-  :ref:`Create Postgres tablespaces <Creating Postgres tablespaces>` 

-  :ref:`Create Postgres databases <Creating Postgres databases>` 

-  :ref:`Configure pglogical replication <pglogical configuration>` 

-  :ref:`Configure .pgpass <Configuring .pgpass>` 

 :ref:`postgres-config-final hook <TPA hooks>` を使用できます

起動後のPostgres構成が完了した後にタスクを実行するためたとえば、
SQLクエリを実行してオブジェクトを作成またはデータをロードするため。

-  :ref:`Configure BDR <EDB Postgres Distributed configuration>` 

 :ref:`post-deploy hook <TPA hooks>` を使用できます

展開プロセスが完了した後にタスクを実行します。
