在 swarm 中使用 docker stack 运行这个 YML。Docker 堆栈文件,用于创建具有 2 个从属的 Postgresql 主/从设置。
从容器将在几分钟内重新启动重复并重复......
如何解决?
docker stack deploy -c docker-stack-postgresql.yml post
码头工人-stacl-postgresql.yml
<pre>version: "3"
services:
db1:
image: bitnami/postgresql:latest
ports:
- "127.0.0.1:5432:5432"
networks:
- awesomenet
deploy:
placement:
constraints: [node.hostname == node-docker-1]
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.master
db2:
image: bitnami/postgresql:latest
depends_on:
- db1
ports:
- "127.0.0.1:5433:5432"
networks:
- awesomenet
deploy:
placement:
constraints: [node.hostname == node-docker-2]
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.slave
db3:
image: bitnami/postgresql:latest
depends_on:
- db1
ports:
- "127.0.0.1:5434:5432"
networks:
- awesomenet
deploy:
placement:
constraints: [node.hostname == node-docker-3]
volumes:
- pgdata:/bitnami/postgresql
env_file: .env.slave
volumes:
pgdata:
networks:
awesomenet:
driver: overlay
driver_opts:
encrypted: "true"
</pre>
master的env文件:.env.master
<pre>
POSTGRESQL_REPLICATION_MODE=master
POSTGRESQL_REPLICATION_USER=replication_user
POSTGRESQL_REPLICATION_PASSWORD= replication_password
POSTGRESQL_USERNAME=postgres
POSTGRESQL_PASSWORD=password
POSTGRESQL_DATABASE=monkey_db
</pre>
环境文件:.env.slave
<pre>
POSTGRESQL_REPLICATION_MODE=slave
POSTGRESQL_REPLICATION_USER=replication_user
POSTGRESQL_REPLICATION_PASSWORD= replication_password
POSTGRESQL_MASTER_HOST=db1
POSTGRESQL_MASTER_PORT=5432
</pre>
PostgreSQL 日志文件:
<pre>
nami INFO Initializing postgresql
postgre INFO This installation requires no credentials.
nami INFO postgresql successfully initialized
</pre>
PostgreSQL 错误日志
<pre>
2018-01-16T00:22:47.426512118Z Starting postgresql...
2018-01-16T00:26:11.369732522Z ERROR Unable to start com.bitnami.postgresql: pg_ctl: directory "/opt/bitnami/postgresql/data" is not a database cluster directory
</pre>