Created
September 10, 2018 10:16
-
-
Save darkcl/b429260dd40b6e22ccfe97b4e8f2be23 to your computer and use it in GitHub Desktop.
MongoDB Replica Set
This file contains hidden or 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" | |
services: | |
mongo1: | |
container_name: mongo_master | |
image: mongo | |
command: --replSet rs0 | |
ports: | |
- "30001:27017" | |
mongo2: | |
image: mongo | |
command: --replSet rs0 | |
ports: | |
- "30002:27017" | |
mongo3: | |
image: mongo | |
command: --replSet rs0 | |
ports: | |
- "30003:27017" |
This file contains hidden or 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
MONGO_SCRIPT := $(shell cat ./rs_config) | |
start-mongo-rs: | |
@echo "Starting MongoDB Replica Set (localhost:30001)" | |
@docker-compose -f ./mongo_rs/docker-compose.yml up -d | |
@echo Wait... | |
@sleep 15 | |
@docker exec -it mongo_master mongo --eval "$(MONGO_SCRIPT)" | |
@docker exec -it mongo_master mongo --eval "rs.status()" |
This file contains hidden or 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
var cfg={_id:\"rs0\",protocolVersion:1,members:[{_id:0,host:\"mongo1:27017\"},{_id:1,host:\"mongo2:27017\"},{_id:2,host:\"mongo3:27017\"}]};rs.initiate(cfg);rs.reconfig(cfg); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment