enix.postgresql_replication
enix.postgresql_replication
一个角色,用于在 Unix 主机上使用 Ansible 部署和配置 postgresql 复制集群。
要求
支持的目标:
- Debian 8 "Jessie"
- Debian 9 "Stretch"
角色变量
此角色预加载了几乎所有可用的默认值。您可以在主机/组变量、清单或剧本中覆盖每一个。有关配置的帮助,请查看 defaults/main.yml
中的注释默认值。所有提供的变量均以 postgresql_replication__
开头。
这个角色的工作方式与其他一些角色不同,为了使不同集群主机角色独立,我们使用 Ansible 组。在您的清单中需要定义三个不同的组,以便在相同清单中与不同集群一起使用,这些组是可配置的:
postgresql_replication__group
- 此集群的主要主机组,默认值:postgresql
postgresql_replication__group_master
- 仅应包括一个主机的主组,默认值:postgresql_master
postgresql_replication__group_replicas
- 包含副本主机的组,默认值:postgresql_replicas
您的清单最终应该是以下格式(yaml 格式示例):
all:
children:
postgresql:
children:
postgresql_master:
hosts:
db-01:
ansible_host: 185.145.251.12
postgresql_replicas:
hosts:
db-02:
ansible_host: 185.145.251.243
postgresql_replication__user
- 复制节点认证所用的用户名。默认值:replicate
。postgresql_replication__password
-postgresql_replication__user
的密码。在生产集群中更改默认值很重要。默认值:replicate
。postgresql_replication__waldir
- 用于存储从主节点发送到复制节点的 WAL 文件的目录。
发送服务器配置。有关正确值的详细信息,请参见 (https://www.postgresql.org/docs/11/runtime-config-replication.html#RUNTIME-CONFIG-REPLICATION-SENDER)。
postgresql_replication__walsenders
- 要启用的 wal 发送进程的数量。默认值:3
。postgresql_replication__walsegments
- 要保留的 wal 段数(每个 16MB)。默认值:64
。postgresql_replication__trigger_file
- 用于触发从属节点上主操作的文件。默认值:/tmp/MasterNow
postgresql_replication__bootstrap
- 非常重要。当该变量设置为"yesiwant"
时,部署将删除postgresql_replication__group_replicas
中定义的主机上的所有数据,并从主节点进行新鲜的pg_basebackup
。注意,如果启用此选项且没有正确设置组中的主机,您可能会完全破坏数据。
依赖关系
使用方法
使用 Ansible galaxy requirements.yml
- src: enix.postgresql_replication
并将其添加到您的剧本角色中:
- hosts: postgresql
roles:
- role: enix.postgresql_replication:
postgresql__version: 11
postgresql__global_config_options:
- option: listen_addresses
value: '*'
- option: log_min_duration_statement
value: 1000
postgresql__hba_entries:
- {type: local, database: all, user: postgres, auth_method: peer}
- {type: local, database: all, user: all, auth_method: peer}
- {type: host, database: all, user: all, address: "0.0.0.0/0", auth_method: md5}
- {type: hostssl, database: replication, user: "{{ postgresql_replication__user }}", address: "0.0.0.0/0", auth_method: md5}
postgresql__users:
- {name: "{{ postgresql_replication__user }}", password: "{{ postgresql_replication__password }}", role_attr_flags: "REPLICATION"}
您还可以作为剧本使用该角色。您将被询问要提供哪些主机,并且可以进一步使用 --extra-vars
配置该剧本。
$ ansible-playbook -i inventory --extra-vars='{...}' main.yml
待办事项
- 添加真正的 gitlab / travis CI
- 添加使用 molecule 的测试
更新日志
1.1.0
更新组名为 postgresql_master 和 postgresql_replicas。 符合 ansible 2.8+ 的组名要求。
1.0.0
初始版本。
许可证
GPLv2
作者信息
Laurent CORBES laurent.corbes@enix.fr - http://www.enix.io