Created
August 27, 2019 10:35
-
-
Save code-machina/8e93b30a8384699485e7e12d39be3d95 to your computer and use it in GitHub Desktop.
도커 컴포저를 이용한 Replica Set 간편 구성 (샘플1)
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: | |
anguis1: | |
image: mongo:4.1 | |
hostname: anguis1 | |
container_name: anguis1 | |
networks: | |
- mongo-bridge | |
ports: | |
- 30001:27017 | |
volumes: | |
- /data/mongo/db-01:/data/db | |
restart: always | |
command: ["mongod", "--replSet", "anguis-repl", "--bind_ip_all", "--ipv6"] | |
anguis2: | |
image: mongo:4.1 | |
hostname: anguis2 | |
container_name: anguis2 | |
networks: | |
- mongo-bridge | |
ports: | |
- 30002:27017 | |
volumes: | |
- /data/mongo/db-02:/data/db | |
restart: always | |
command: ["mongod", "--replSet", "anguis-repl", "--bind_ip_all", "--ipv6"] | |
anguis3: | |
image: mongo:4.1 | |
hostname: anguis3 | |
container_name: anguis3 | |
networks: | |
- mongo-bridge | |
ports: | |
- 30003:27017 | |
volumes: | |
- /data/mongo/db-03:/data/db | |
restart: always | |
command: ["mongod", "--replSet", "anguis-repl", "--bind_ip_all", "--ipv6"] | |
# configure the mongo replica set | |
mongosetup: | |
build: ./mongosetup | |
networks: | |
- mongo-bridge | |
volumes: | |
- ./scripts:/scripts | |
entrypoint: [ "/scripts/setup_init.sh" ] | |
networks: | |
mongo-bridge: | |
name: mongo-bridge |
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
#!/usr/bin/env bash | |
echo "Waiting for MongoDB startup.." | |
until [ "$(mongo --host anguis1:27017 admin --eval "printjson(db.serverStatus())" | grep uptime | head -1)" ]; do | |
printf '.' | |
sleep 1 | |
done | |
echo $(mongo --host anguis1:27017 admin --eval "printjson(db.serverStatus())" | grep uptime | head -1) | |
echo "MongoDB Started.." | |
echo SETUP.sh time now: `date +"%T" ` | |
mongo --host anguis1:27017 <<EOF | |
var cfg = { | |
"_id": "anguis-repl", | |
"members": [ | |
{ | |
"_id": 0, | |
"host": "anguis1:27017", | |
"priority": 2 | |
}, | |
{ | |
"_id": 1, | |
"host": "anguis2:27017", | |
"priority": 0 | |
}, | |
{ | |
"_id": 2, | |
"host": "anguis3:27017", | |
"priority": 1, | |
"arbiterOnly": true | |
} | |
] | |
}; | |
rs.initiate(cfg, { force: true }); | |
rs.reconfig(cfg, { force: true }); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment