Last active
August 29, 2015 14:08
-
-
Save ak47/b440e04d4e8beedc9ac4 to your computer and use it in GitHub Desktop.
docker mongo shared replica set for dev
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
# https://sebastianvoss.com/docker-mongodb-sharded-cluster.html | |
# rs1_srv1 172.17.0.20:49170 | |
# rs1_srv2 172.17.0.21:49171 | |
# rs1_srv3 172.17.0.22:49172 | |
# rs2_srv1 172.17.0.23:49173 | |
# rs2_srv2 172.17.0.24:49174 | |
# rs2_srv3 172.17.0.25:49175 | |
# cfg1 172.17.0.26:49176 | |
# mongos1 172.17.0.27:49177 | |
docker run \ | |
-P ---name rs1_srv1 \ | |
-d dev24/mongodb \ | |
--replSet rs1 \ | |
--noprealloc --smallfiles | |
docker run \ | |
-P ---name rs1_srv2 \ | |
-d dev24/mongodb \ | |
--replSet rs1 \ | |
--noprealloc --smallfiles | |
docker run \ | |
-P ---name rs1_srv3 \ | |
-d dev24/mongodb \ | |
--replSet rs1 \ | |
--noprealloc --smallfiles | |
docker run \ | |
-P --name rs2_srv1 \ | |
-d dev24/mongodb \ | |
--replSet rs2 \ | |
--noprealloc --smallfiles | |
docker run \ | |
-P --name rs2_srv2 \ | |
-d dev24/mongodb \ | |
--replSet rs2 \ | |
--noprealloc --smallfiles | |
docker run \ | |
-P --name rs2_srv3 \ | |
-d dev24/mongodb \ | |
--replSet rs2 \ | |
--noprealloc --smallfiles | |
rs.initiate() | |
rs.add("172.17.0.21:27017") | |
rs.add("172.17.0.22:27017") | |
rs.status() | |
cfg = rs.conf() | |
cfg.members[0].host = "172.17.0.20:27017" | |
rs.reconfig(cfg) | |
rs.status() | |
rs.initiate() | |
rs.add("172.17.0.24:27017") | |
rs.add("172.17.0.25:27017") | |
rs.status() | |
cfg = rs.conf() | |
cfg.members[0].host = "172.17.0.23:27017" | |
rs.reconfig(cfg) | |
rs.status() | |
docker run \ | |
-P --name cfg1 \ | |
-d dev24/mongodb \ | |
--noprealloc --smallfiles \ | |
--configsvr \ | |
--dbpath /data/db \ | |
--port 27017 | |
docker run \ | |
-P --name mongos1 \ | |
-d dev24/mongos \ | |
--port 27017 \ | |
--configdb \ | |
172.17.0.26:27017 | |
sh.addShard("rs1/172.17.0.20:27017") | |
sh.addShard("rs2/172.17.0.23:27017") | |
sh.status() | |
# this last bit, otherwise when you try to add the sharding | |
# you get a "sharding not enabled for this database" | |
# of course, create the db first (not shown) ;-) | |
mongos> sh.enableSharding('intake_domain') | |
{ "ok" : 1 } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment