Created
December 24, 2020 11:50
-
-
Save PeterGriffitz/5347fe26b9839f54e2eed1fe6626e0ef to your computer and use it in GitHub Desktop.
Floitet-Patroni-Zookeeper-Part1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "3.4" | |
networks: | |
patroni_patroni: | |
external: true | |
services: | |
patroni1: | |
image: patroni-test | |
networks: [ patroni_patroni ] | |
ports: | |
- 5441:5432 | |
- 8091:8091 | |
hostname: patroni1 | |
volumes: | |
- /patroni1:/data/patroni | |
environment: | |
PATRONI_API_CONNECT_PORT: 8091 | |
REPLICATION_NAME: replicator | |
REPLICATION_PASS: replpass | |
SU_NAME: postgres | |
SU_PASS: supass | |
POSTGRES_APP_ROLE_PASS: appass | |
deploy: | |
replicas: 1 | |
placement: | |
constraints: [node.hostname == floitet] | |
patroni2: | |
image: patroni-test | |
networks: [ patroni_patroni ] | |
ports: | |
- 5442:5432 | |
- 8092:8091 | |
hostname: patroni2 | |
volumes: | |
- /patroni2:/data/patroni | |
environment: | |
PATRONI_API_CONNECT_PORT: 8091 | |
REPLICATION_NAME: replicator | |
REPLICATION_PASS: replpass | |
SU_NAME: postgres | |
SU_PASS: supass | |
POSTGRES_APP_ROLE_PASS: appass | |
deploy: | |
replicas: 1 | |
placement: | |
constraints: [node.hostname == floitet] | |
patroni3: | |
image: patroni-test | |
networks: [ patroni_patroni ] | |
ports: | |
- 5443:5432 | |
- 8093:8091 | |
hostname: patroni3 | |
volumes: | |
- /patroni3:/data/patroni | |
environment: | |
PATRONI_API_CONNECT_PORT: 8091 | |
REPLICATION_NAME: replicator | |
REPLICATION_PASS: replpass | |
SU_NAME: postgres | |
SU_PASS: supass | |
POSTGRES_APP_ROLE_PASS: appass | |
deploy: | |
replicas: 1 | |
placement: | |
constraints: [node.hostname == floitet] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3.7' | |
services: | |
zoo1: | |
image: zookeeper:3.4 | |
hostname: zoo1 | |
ports: | |
- 2191:2181 | |
networks: | |
- patroni | |
environment: | |
ZOO_MY_ID: 1 | |
ZOO_SERVERS: server.1=0.0.0.0:2888:3888 server.2=zoo2:2888:3888 server.3=zoo3:2888:3888 | |
deploy: | |
replicas: 1 | |
placement: | |
constraints: | |
- node.hostname == floitet | |
restart_policy: | |
condition: any | |
zoo2: | |
image: zookeeper:3.4 | |
hostname: zoo2 | |
networks: | |
- patroni | |
ports: | |
- 2192:2181 | |
environment: | |
ZOO_MY_ID: 2 | |
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=0.0.0.0:2888:3888 server.3=zoo3:2888:3888 | |
deploy: | |
replicas: 1 | |
placement: | |
constraints: | |
- node.hostname == floitet | |
restart_policy: | |
condition: any | |
zoo3: | |
image: zookeeper:3.4 | |
hostname: zoo3 | |
networks: | |
- patroni | |
ports: | |
- 2193:2181 | |
environment: | |
ZOO_MY_ID: 3 | |
ZOO_SERVERS: server.1=zoo1:2888:3888 server.2=zoo2:2888:3888 server.3=0.0.0.0:2888:3888 | |
deploy: | |
replicas: 1 | |
placement: | |
constraints: | |
- node.hostname == floitet | |
restart_policy: | |
condition: any | |
networks: | |
patroni: | |
driver: overlay | |
attachable: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM postgres:11 | |
RUN apt-get update -y\ | |
&& apt-get install python3 python3-pip -y\ | |
&& pip3 install --upgrade setuptools\ | |
&& pip3 install psycopg2-binary \ | |
&& pip3 install patroni[zookeeper] \ | |
&& mkdir /data/patroni -p \ | |
&& chown postgres:postgres /data/patroni \ | |
&& chmod 700 /data/patroni | |
COPY patroni.yml /etc/patroni.yml | |
COPY patroni-entrypoint.sh ./entrypoint.sh | |
USER postgres | |
ENTRYPOINT ["bin/sh", "/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
readonly CONTAINER_IP=$(hostname --ip-address) | |
readonly CONTAINER_API_ADDR="${CONTAINER_IP}:${PATRONI_API_CONNECT_PORT}" | |
readonly CONTAINER_POSTGRE_ADDR="${CONTAINER_IP}:5432" | |
export PATRONI_NAME="${PATRONI_NAME:-$(hostname)}" | |
export PATRONI_RESTAPI_CONNECT_ADDRESS="$CONTAINER_API_ADDR" | |
export PATRONI_RESTAPI_LISTEN="$CONTAINER_API_ADDR" | |
export PATRONI_POSTGRESQL_CONNECT_ADDRESS="$CONTAINER_POSTGRE_ADDR" | |
export PATRONI_POSTGRESQL_LISTEN="$CONTAINER_POSTGRE_ADDR" | |
export PATRONI_REPLICATION_USERNAME="$REPLICATION_NAME" | |
export PATRONI_REPLICATION_PASSWORD="$REPLICATION_PASS" | |
export PATRONI_SUPERUSER_USERNAME="$SU_NAME" | |
export PATRONI_SUPERUSER_PASSWORD="$SU_PASS" | |
export PATRONI_approle_PASSWORD="$POSTGRES_APP_ROLE_PASS" | |
export PATRONI_approle_OPTIONS="${PATRONI_admin_OPTIONS:-createdb, createrole}" | |
exec /usr/local/bin/patroni /etc/patroni.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
scope: patroni | |
namespace: /service/ | |
bootstrap: | |
dcs: | |
ttl: 30 | |
loop_wait: 10 | |
retry_timeout: 10 | |
maximum_lag_on_failover: 1048576 | |
postgresql: | |
use_pg_rewind: true | |
postgresql: | |
use_pg_rewind: true | |
initdb: | |
- encoding: UTF8 | |
- data-checksums | |
pg_hba: | |
- host replication all all md5 | |
- host all all all md5 | |
zookeeper: | |
hosts: | |
- zoo1:2181 | |
- zoo2:2181 | |
- zoo3:2181 | |
postgresql: | |
data_dir: /data/patroni | |
bin_dir: /usr/lib/postgresql/11/bin | |
pgpass: /tmp/pgpass | |
parameters: | |
unix_socket_directories: '.' | |
tags: | |
nofailover: false | |
noloadbalance: false | |
clonefrom: false | |
nosync: false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment