paunin / PostDock

PostDock - Postgres & Docker - Postgres streaming replication cluster for any docker environment
MIT License
1.11k stars 338 forks source link

feature request #188

Open frank3427 opened 6 years ago

frank3427 commented 6 years ago

Have you looked at what it would take to run in docker swarm? has anyone tried yet?

frank3427 commented 6 years ago

Hrvoje ,

can you send me your stack yml file or all the files and directory structure to run in swarm frank@djfamily.net

On Mon, Sep 17, 2018 at 4:01 AM Hrvoje notifications@github.com wrote:

I am running PostDock as docker swarm, it's easy to set up. version: '3.6' services: pgmaster: image: environment: REPLICATION_PASSWORD: replication_pass CLUSTER_NAME: pg_cluster CONFIGS_DELIMITER_SYMBOL: ; REPMGR_WAIT_POSTGRES_START_TIMEOUT: '270' CLUSTER_NODE_NETWORK_NAME: pgmaster CLEAN_OVER_REWIND: '0' REPLICATION_USER: replication_user LOG_LEVEL: DEBUG NODE_PRIORITY: '100' REPLICATION_PRIMARY_HOST: pgmaster POSTGRES_PASSWORD: pw PARTNER_NODES: pgmaster,pgslave1,pgslave2 SSH_ENABLE: '1' NODE_NAME: pgmaster POSTGRES_DB: tvmid_core NODE_ID: '1' CONFIGS: listen_addresses:'*';max_replication_slots:5;max_connections:1000;log_destination:'stderr' REPLICATION_DB: replication_db POSTGRES_USER: user ports:

  • 5441:5432 volumes:
  • pgmaster:/var/lib/postgresql/data configs:
  • source: postdock_ssh_entrypoint target: /home/postgres/.ssh/entrypoint.sh secrets:
  • source: postdock_id_rsa target: id_rsa
  • source: postdock_id_rsa_pub target: id_rsa.pub networks:
  • backend logging: driver: json-file deploy: placement: constraints:
  • node.hostname ==

    pgpool: image: environment: WAIT_BACKEND_TIMEOUT: '60' CHECK_PGCONNECT_TIMEOUT: '3' CHECK_PASSWORD: pw REQUIRE_MIN_BACKENDS: '2' PCP_USER: pcp_user PCP_PASSWORD: pcp_pass BACKENDS: '0:pgmaster:5432:1:/var/lib/postgresql/data:ALLOW_TO_FAILOVER,1:pgslave1:5432:::,3:pgslave2:5432:::' SSH_ENABLE: '1' CONFIGS: num_init_children:250,max_pool:4 CHECK_USER: user DB_USERS: user:pwd ports:

    • 5430:5432
    • 9898:9898 configs:
    • source: postdock_ssh_entrypoint target: /home/postgres/.ssh/entrypoint.sh secrets:
    • source: postdock_id_rsa target: id_rsa
    • source: postdock_id_rsa_pub target: id_rsa.pub networks:
    • backend logging: driver: json-file

    pgslave1: image: environment: CONFIGS_DELIMITER_SYMBOL: ; CLUSTER_NODE_NETWORK_NAME: pgslave1 CLEAN_OVER_REWIND: '1' LOG_LEVEL: DEBUG REPLICATION_PRIMARY_HOST: pgmaster PARTNER_NODES: pgmaster,pgslave1,pgslave2 SSH_ENABLE: '1' NODE_NAME: pgslave1 NODE_ID: '2' CONFIGS: max_replication_slots:10;max_connections:1000;log_destination:'stderr' ports:

    • 5442:5432 volumes:
    • pgslave1:/var/lib/postgresql/data configs:
    • source: postdock_ssh_entrypoint target: /home/postgres/.ssh/entrypoint.sh secrets:
    • source: postdock_id_rsa target: id_rsa
    • source: postdock_id_rsa_pub target: id_rsa.pub networks:
    • backend logging: driver: json-file deploy: placement: constraints:
      • node.hostname ==

    pgslave2: image: environment: CONFIGS_DELIMITER_SYMBOL: ; CLUSTER_NODE_NETWORK_NAME: pgslave2 CLEAN_OVER_REWIND: '1' LOG_LEVEL: DEBUG REPLICATION_PRIMARY_HOST: pgmaster PARTNER_NODES: pgmaster,pgslave1,pgslave2 SSH_ENABLE: '1' NODE_NAME: pgslave2 NODE_ID: '3' CONFIGS: max_replication_slots:10;max_connections:1000;log_destination:'stderr' ports:

    • 5443:5432 volumes:
    • pgslave2:/var/lib/postgresql/data configs:
    • source: postdock_ssh_entrypoint target: /home/postgres/.ssh/entrypoint.sh secrets:
    • source: postdock_id_rsa target: id_rsa
    • source: postdock_id_rsa_pub target: id_rsa.pub networks:
    • backend logging: driver: json-file deploy: placement: constraints:
      • node.hostname ==

    backup: image: environment: BACKUP_SCHEDULE: '/30 /5 *' POSTGRES_DB: POSTGRES_PASSWORD: POSTGRES_USER: REPLICATION_HOST: pgmaster REPLICATION_PASSWORD: replication_pass REPLICATION_USER: replication_user SSH_ENABLE: '1' volumes:

    • backup:/var/backups configs:
    • source: postdock_ssh_entrypoint target: /home/postgres/.ssh/entrypoint.sh secrets:
    • source: postdock_id_rsa target: id_rsa
    • source: postdock_id_rsa_pub target: id_rsa.pub networks:
    • backend logging: driver: json-file deploy: placement: constraints:
      • node.hostname ==

    volumes: pgmaster: pgslave1: pgslave2:

    configs: postdock_ssh_entrypoint: file: ./configs/psql/ssh/entrypoint.sh

    secrets: postdock_id_rsa: file: ./secrets/id_rsa postdock_id_rsa_pub: file: ./secrets/id_rsa.pub`

Config file I use `#!/usr/bin/env bash

set -e

cp -f /run/secrets/* /home/postgres/.ssh/ || echo 'No pre-populated ssh keys!' chown -R postgres:postgres /home/postgres/.ssh/id_rsa chown -R postgres:postgres /home/postgres/.ssh/id_rsa.pub if [[ "$SSH_ENABLE" == "1" ]]; then echo '>>> TUNING UP SSH CLIENT...' if [ ! -f "/home/postgres/.ssh/id_rsa.pub" ] && [ ! -f "/home/postgres/.ssh/id_rsa" ]; then echo ">>> There are no ssh keys - SSH daemon can not be enabled!" exit 1 fi

chmod 600 -R /home/postgres/.ssh/id_rsa

mkdir -p /var/run/sshd && sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config sed 's@session\srequired\spam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd echo "export VISIBLE=now" >> /etc/profile

cat /home/postgres/.ssh/id_rsa.pub >> /home/postgres/.ssh/authorized_keys

echo '>>> STARTING SSH SERVER...' /usr/sbin/sshd 2>&1

else echo ">>> SSH is not enabled!" fi `

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/paunin/PostDock/issues/188#issuecomment-421935278, or mute the thread https://github.com/notifications/unsubscribe-auth/AMma859DMtFfI3T-T9LlCRvO7i3MAnhUks5ub2UGgaJpZM4Wmjev .

jsenecal commented 6 years ago

Hi @paunin , Supporting swarm secrets would go a long way into facilitating this. Right now every configuration element has to be defined as an environment variable without any way to load anything from file (afaik).

alexsorokoletov commented 6 years ago

I'd be interested in a simple example how to start a cluster in docker swarm with like 3 nodes or something. The PostDock looks like it is the best available thing and also well structured.