mirror of
https://gitea.0xace.cc/ansible-playbooks/patroni.git
synced 2025-06-29 01:23:07 +00:00
first commit
This commit is contained in:
149
vars/patroni.yaml
Normal file
149
vars/patroni.yaml
Normal file
@ -0,0 +1,149 @@
|
||||
# pgbouncer configuration
|
||||
pgbouncer_client_tls_key_file: "/etc/patroni/ssl/cert.key"
|
||||
pgbouncer_client_tls_cert_file: "/etc/patroni/ssl/cert.crt"
|
||||
pgbouncer_systemd_user: "postgres"
|
||||
pgbouncer_systemd_group: "postgres"
|
||||
pgbouncer_postgresql_major_version: "{{ patroni_postgresql_major_version }}"
|
||||
pgbouncer_postgresql_superuser_username: "{{ patroni_superuser_username }}"
|
||||
pgbouncer_postgresql_superuser_password: "{{ patroni_superuser_password }}"
|
||||
pgbouncer_auth_hba_file: "{{ patroni_postgresql_data_dir }}/pg_hba.conf"
|
||||
|
||||
# HAProxy configuration
|
||||
haproxy_listen_port:
|
||||
master: 5000
|
||||
replicas: 5001
|
||||
replicas_sync: 5002
|
||||
replicas_async: 5003
|
||||
stats: 9000
|
||||
haproxy_maxconn:
|
||||
global: 100000
|
||||
master: 10000
|
||||
replica: 10000
|
||||
haproxy_timeout:
|
||||
client: "60m"
|
||||
server: "60m"
|
||||
|
||||
haproxy_config_override: |
|
||||
global
|
||||
maxconn {{ haproxy_maxconn.global }}
|
||||
log /dev/log local0
|
||||
log /dev/log local1 notice
|
||||
chroot /var/lib/haproxy
|
||||
stats socket /var/lib/haproxy/stats mode 660 level admin expose-fd listeners
|
||||
stats timeout 30s
|
||||
user haproxy
|
||||
group haproxy
|
||||
daemon
|
||||
|
||||
defaults
|
||||
mode tcp
|
||||
log global
|
||||
retries 2
|
||||
timeout queue 5s
|
||||
timeout connect 5s
|
||||
timeout client {{ haproxy_timeout.client }}
|
||||
timeout server {{ haproxy_timeout.server }}
|
||||
timeout check 15s
|
||||
|
||||
listen stats
|
||||
mode http
|
||||
bind *:{{ haproxy_listen_port.stats }}
|
||||
stats enable
|
||||
stats uri /
|
||||
|
||||
listen master
|
||||
bind *:{{ haproxy_listen_port.master }}
|
||||
maxconn {{ haproxy_maxconn.master }}
|
||||
option tcplog
|
||||
option httpchk OPTIONS /master
|
||||
http-check expect status 200
|
||||
default-server inter 3s fastinter 1s fall 3 rise 4 on-marked-down shutdown-sessions
|
||||
{% for server in groups.patroni %}
|
||||
server {{ server }} {{ server }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_listen_port }} check-ssl verify none
|
||||
{% endfor %}
|
||||
|
||||
listen replicas
|
||||
bind *:{{ haproxy_listen_port.replicas }}
|
||||
maxconn {{ haproxy_maxconn.replica }}
|
||||
option tcplog
|
||||
option httpchk OPTIONS /replica
|
||||
balance roundrobin
|
||||
http-check expect status 200
|
||||
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
|
||||
{% for server in groups.patroni %}
|
||||
server {{ server }} {{ server }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_listen_port }} check-ssl verify none
|
||||
{% endfor %}
|
||||
|
||||
listen replicas_sync
|
||||
bind *:{{ haproxy_listen_port.replicas_sync }}
|
||||
maxconn {{ haproxy_maxconn.replica }}
|
||||
option tcplog
|
||||
option httpchk OPTIONS /sync
|
||||
balance roundrobin
|
||||
http-check expect status 200
|
||||
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
|
||||
{% for server in groups.patroni %}
|
||||
server {{ server }} {{ server }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_listen_port }} check-ssl verify none
|
||||
{% endfor %}
|
||||
|
||||
listen replicas_async
|
||||
bind *:{{ haproxy_listen_port.replicas_async }}
|
||||
maxconn {{ haproxy_maxconn.replica }}
|
||||
option tcplog
|
||||
option httpchk OPTIONS /async
|
||||
balance roundrobin
|
||||
http-check expect status 200
|
||||
default-server inter 3s fastinter 1s fall 3 rise 2 on-marked-down shutdown-sessions
|
||||
{% for server in groups.patroni %}
|
||||
server {{ server }} {{ server }}:{{ pgbouncer_listen_port }} check port {{ patroni_restapi_listen_port }} check-ssl verify none
|
||||
{% endfor %}
|
||||
|
||||
keepalived_config_override: |
|
||||
global_defs {
|
||||
router_id {{ patroni_cluster_name }}
|
||||
}
|
||||
vrrp_track_process haproxy {
|
||||
process haproxy
|
||||
quorum 1
|
||||
delay 2
|
||||
}
|
||||
vrrp_instance VRRP_1 {
|
||||
state MASTER
|
||||
virtual_router_id {{ keepalived_vip.split('.')[-1][-3:] }}
|
||||
priority {{ ansible_default_ipv4.address.split('.')[-1][-3:] }}
|
||||
interface {{ ansible_default_ipv4.interface }}
|
||||
unicast_src_ip {{ ansible_default_ipv4.address }}
|
||||
unicast_peer {
|
||||
{% for peer in groups.patroni %}
|
||||
{{ peer if peer != ansible_default_ipv4.address }}
|
||||
{% endfor %}
|
||||
}
|
||||
virtual_ipaddress {
|
||||
{{ keepalived_vip }}/32 dev {{ ansible_default_ipv4.interface }}
|
||||
}
|
||||
track_process {
|
||||
haproxy
|
||||
}
|
||||
}
|
||||
|
||||
# Backup and restore options
|
||||
patroni_postgresql_archive_command: "{{ 'http_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ 'https_proxy=' ~ wal_g_https_proxy ~ ' ' if wal_g_https_proxy is defined else 'https_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ wal_g_pg_binary_name ~ ' --config ' ~ wal_g_pg_home_dir ~ '/' ~ wal_g_config_name ~ ' wal-push %p' if patroni_wal_g_install else '' }}"
|
||||
patroni_postgresql_restore_command: "{{ 'http_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ 'https_proxy=' ~ wal_g_https_proxy ~ ' ' if wal_g_https_proxy is defined else 'https_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ wal_g_pg_binary_name ~ ' --config ' ~ wal_g_pg_home_dir ~ '/' ~ wal_g_config_name ~ ' wal-fetch %f %p' if patroni_wal_g_install else '' }}"
|
||||
patroni_cluster_bootstrap_command: "{{ 'http_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ 'https_proxy=' ~ wal_g_https_proxy ~ ' ' if wal_g_https_proxy is defined else 'https_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ wal_g_pg_binary_name ~ ' --config ' ~ wal_g_pg_home_dir ~ '/' ~ wal_g_restore_config_name ~ ' backup-fetch ' ~ patroni_postgresql_data_dir ~ ' ' ~ patroni_wal_g_restore_backup_name }}"
|
||||
# "restore_command" written to recovery.conf when configuring follower (create replica)
|
||||
patroni_cluster_restore_command: "{{ 'http_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ 'https_proxy=' ~ wal_g_https_proxy ~ ' ' if wal_g_https_proxy is defined else 'https_proxy=' ~ wal_g_http_proxy ~ ' ' if wal_g_http_proxy is defined else '' }}{{ wal_g_pg_binary_name ~ ' --config ' ~ wal_g_pg_home_dir ~ '/' ~ wal_g_restore_config_name ~ ' wal-fetch %f %p' if patroni_wal_g_restore_from_backup else '' }}"
|
||||
patroni_wal_g_create_replica_methods:
|
||||
- {option: "command", value: "{{ patroni_cluster_bootstrap_command }}"}
|
||||
- {option: "no_params", value: "True"}
|
||||
patroni_basebackup_create_replica_methods:
|
||||
- {option: "max-rate", value: "1000M"}
|
||||
- {option: "checkpoint", value: "fast"}
|
||||
|
||||
# WAL-G options
|
||||
wal_g_pg: "{{ patroni_wal_g_install }}"
|
||||
wal_g_pg_binary_name: "wal-g-pg"
|
||||
wal_g_config_name: ".walg.json"
|
||||
wal_g_restore_config_name: ".walg-restore.json"
|
||||
wal_g_pg_home_dir: "{{ patroni_postgresql_home_dir }}"
|
||||
wal_g_pg_data_dir: "{{ patroni_postgresql_home_dir }}/{{ patroni_postgresql_major_version }}/{{ patroni_postgresql_cluster_name }}"
|
||||
wal_g_pg_major_version: "{{ patroni_postgresql_major_version }}"
|
Reference in New Issue
Block a user