From f3593c388ab069918572d7e1facf34a4bc8cef40 Mon Sep 17 00:00:00 2001 From: bitliner Date: Sun, 30 Oct 2016 23:38:59 +0000 Subject: [PATCH 01/17] +fixed start-cluster to support reading IP of containers with Docker --- bin/start-cluster.sh | 46 +++++++++++++++-------------------- bin/start-cluster.sh.rej | 52 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+), 27 deletions(-) create mode 100644 bin/start-cluster.sh.rej diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 52118b6..aab000c 100644 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -1,18 +1,5 @@ #!/bin/bash - - -PORT=10000 - -if [ ! -z "$1" ]; then -PORT=$1 -fi - -PORT_1=$(( $PORT - 1 )) -PORT1=$(( $PORT + 1 )) -PORT2=$(( $PORT + 2 )) - - set -e if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then @@ -28,41 +15,45 @@ if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then fi # start docker containers for 3xreplicaset rs0 -SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) -SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +#SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` +#echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" until sudo docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; do sleep 2 done -SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT1) -SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10001) +#SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" until sudo docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; do sleep 2 done -SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT2) -SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10002) +#SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" until sudo docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; do sleep 2 done - echo "initialize replicaset" -mongo ${SHARD00_IP}:$PORT --eval "rs.initiate({_id: \"rs0\", members: [{_id:0, host:\"${SHARD00_IP}:$PORT\"}, {_id:1, host:\"${SHARD01_IP}:$PORT1\"}, {_id:2, host:\"${SHARD02_IP}:$PORT2\"}]});" +mongo ${SHARD00_IP}:10000 --eval "rs.initiate({_id: \"rs0\", members: [{_id:0, host:\"${SHARD00_IP}:10000\"}, {_id:1, host:\"${SHARD01_IP}:10001\"}, {_id:2, host:\"${SHARD02_IP}:10002\"}]});" until sudo docker logs ${SHARD00_ID} | grep "replSet PRIMARY" >/dev/null; do sleep 2 done echo "The shard replset is available now..." -CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) -CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +#CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +CONFIG0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONFIG0_ID` echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; @@ -72,8 +63,9 @@ done echo "The config is available now..." -MONGOS0_ID=$(sudo docker run -p $PORT_1:$PORT_1 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:$PORT --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT_1) -MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +MONGOS0_ID=$(sudo docker run -p 9999:9999 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:10000 --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) +#MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +MONGOS0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGOS0_ID` echo "Contacting shard and mongod containers" until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; @@ -82,8 +74,8 @@ do done # Add the shard -mongo ${MONGOS0_IP}:$PORT_1 --eval "sh.addShard(\"rs0/${SHARD00_IP}:$PORT\");" +mongo ${MONGOS0_IP}:9999 --eval "sh.addShard(\"rs0/${SHARD00_IP}:10000\");" echo "OK, you can connect to mongos using: " -echo "mongo ${MONGOS0_IP}:$PORT_1" +echo "mongo ${MONGOS0_IP}:9999" diff --git a/bin/start-cluster.sh.rej b/bin/start-cluster.sh.rej new file mode 100644 index 0000000..703f55a --- /dev/null +++ b/bin/start-cluster.sh.rej @@ -0,0 +1,52 @@ +diff a/bin/start-cluster.sh b/bin/start-cluster.sh (rejected hunks) +@@ -16,7 +16,9 @@ fi + + # start docker containers for 3xreplicaset rs0 + SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +-SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++#SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` ++#echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` + echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" + until sudo docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; + do +@@ -24,7 +26,8 @@ do + done + + SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10001) +-SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++#SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` + echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" + until sudo docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; + do +@@ -32,7 +35,8 @@ do + done + + SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10002) +-SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++#SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` + echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" + until sudo docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; + do +@@ -48,7 +52,8 @@ done + echo "The shard replset is available now..." + + CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +-CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++#CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++CONFIG0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONFIG0_ID` + echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" + + until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; +@@ -59,7 +64,8 @@ done + echo "The config is available now..." + + MONGOS0_ID=$(sudo docker run -p 9999:9999 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:10000 --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) +-MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++#MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) ++MONGOS0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGOS0_ID` + echo "Contacting shard and mongod containers" + + until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; From 22ffcc6462cea8208738d17d84f01a851ff8546d Mon Sep 17 00:00:00 2001 From: bitliner Date: Sun, 30 Oct 2016 23:42:55 +0000 Subject: [PATCH 02/17] -useless start-cluster --- bin/start-cluster | 82 ----------------------------------------------- 1 file changed, 82 deletions(-) delete mode 100755 bin/start-cluster diff --git a/bin/start-cluster b/bin/start-cluster deleted file mode 100755 index 832d5ec..0000000 --- a/bin/start-cluster +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -set -e -PORT=10000 - -if [ ! -z "$1" ]; then -PORT=$1 -fi -echo $PORT - -PORT= -if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then - echo "" - echo "It looks like you already have some containers running." - echo "Please take them down before attempting to bring up another" - echo "cluster with the following command:" - echo "" - echo " make stop-cluster" - echo "" - - exit 1 -fi - -# start docker containers for 3xreplicaset rs0 -SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) -SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; -do - sleep 2 -done - -SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port ($PORT+1)) -SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; -do - sleep 2 -done - -SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port ($PORT+2)) -SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; -do - sleep 2 -done - -echo "initialize replicaset" -mongo ${SHARD00_IP}:$PORT --eval "rs.initiate({_id: \"rs0\", members: [{_id:0, host:\"${SHARD00_IP}:$PORT\"}, {_id:1, host:\"${SHARD01_IP}:($PORT+1)\"}, {_id:2, host:\"${SHARD02_IP}:($PORT+2)\"}]});" -until sudo docker logs ${SHARD00_ID} | grep "replSet PRIMARY" >/dev/null; -do - sleep 2 -done -echo "The shard replset is available now..." - -CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) -CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" - -until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; -do - sleep 2 -done - -echo "The config is available now..." - -MONGOS0_ID=$(sudo docker run -p 9999:9999 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:$PORT --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) -MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -echo "Contacting shard and mongod containers" - -until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; -do - sleep 2 -done - -# Add the shard -mongo ${MONGOS0_IP}:9999 --eval "sh.addShard(\"rs0/${SHARD00_IP}:$PORT\");" - -echo "OK, you can connect to mongos using: " -echo "mongo ${MONGOS0_IP}:9999" - From b0d6ca3b34fec477d65297fe742b1c95eb8b182f Mon Sep 17 00:00:00 2001 From: bitliner Date: Mon, 31 Oct 2016 00:04:21 +0000 Subject: [PATCH 03/17] +added todo --- bin/start-cluster.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index aab000c..58af956 100644 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -1,5 +1,10 @@ #!/bin/bash +### TODO 1 - create function `create_replica_set n` that creates n replica sets +### TODO 2 - create function `create_mongos` that instantiates mongos +### TODO 3 - create a function that create n replica sets and n shards + + set -e if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then From ecb57b3b4ebd1d2cbd175ed9e34d6dd528997258 Mon Sep 17 00:00:00 2001 From: phra Date: Fri, 18 Nov 2016 15:26:13 +0100 Subject: [PATCH 04/17] change docker image to official mongo --- bin/start-cluster.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 58af956..9e01d4c 100644 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -4,10 +4,12 @@ ### TODO 2 - create function `create_mongos` that instantiates mongos ### TODO 3 - create a function that create n replica sets and n shards +#IMAGE="ankurcha/tokumx" +IMAGE="mongo" set -e -if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then +if sudo docker ps | grep $IMAGE >/dev/null; then echo "" echo "It looks like you already have some containers running." echo "Please take them down before attempting to bring up another" @@ -20,7 +22,7 @@ if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then fi # start docker containers for 3xreplicaset rs0 -SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +SHARD00_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) #SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` #echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` @@ -30,7 +32,7 @@ do sleep 2 done -SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10001) +SHARD01_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10001) #SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" @@ -39,7 +41,7 @@ do sleep 2 done -SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10002) +SHARD02_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10002) #SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" @@ -56,7 +58,7 @@ do done echo "The shard replset is available now..." -CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +CONFIG0_ID=$(sudo docker run -d $IMAGE mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) #CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) CONFIG0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONFIG0_ID` echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" @@ -68,7 +70,7 @@ done echo "The config is available now..." -MONGOS0_ID=$(sudo docker run -p 9999:9999 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:10000 --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) +MONGOS0_ID=$(sudo docker run -p 9999:9999 -d $IMAGE mongos --configdb ${CONFIG0_IP}:10000 --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) #MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) MONGOS0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGOS0_ID` echo "Contacting shard and mongod containers" From eb77a755113f712734e616d7775b0bffa1052ffa Mon Sep 17 00:00:00 2001 From: phra Date: Fri, 18 Nov 2016 15:41:13 +0100 Subject: [PATCH 05/17] change grep text --- bin/start-cluster.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 9e01d4c..5f9cdb6 100644 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -27,7 +27,7 @@ SHARD00_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` #echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; +until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port 10000" >/dev/null; do sleep 2 done @@ -36,7 +36,7 @@ SHARD01_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath #SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; +until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port 10001" >/dev/null; do sleep 2 done @@ -45,7 +45,7 @@ SHARD02_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath #SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; +until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port 10002" >/dev/null; do sleep 2 done From 49591d49842c99ba98a3cd68a01d08c1918f2f8c Mon Sep 17 00:00:00 2001 From: phra Date: Fri, 18 Nov 2016 15:50:32 +0100 Subject: [PATCH 06/17] remove logpath flag --- bin/start-cluster.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 5f9cdb6..969681f 100644 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -22,7 +22,7 @@ if sudo docker ps | grep $IMAGE >/dev/null; then fi # start docker containers for 3xreplicaset rs0 -SHARD00_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +SHARD00_ID=$(sudo docker run -dt $IMAGE mongod --replSet rs0 --shardsvr --bind_ip 0.0.0.0 --port 10000) #SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` #echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` @@ -32,7 +32,7 @@ do sleep 2 done -SHARD01_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10001) +SHARD01_ID=$(sudo docker run -dt $IMAGE mongod --replSet rs0 --shardsvr --bind_ip 0.0.0.0 --port 10001) #SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" @@ -41,7 +41,7 @@ do sleep 2 done -SHARD02_ID=$(sudo docker run -d $IMAGE mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10002) +SHARD02_ID=$(sudo docker run -dt $IMAGE mongod --replSet rs0 --shardsvr --bind_ip 0.0.0.0 --port 10002) #SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" @@ -58,7 +58,7 @@ do done echo "The shard replset is available now..." -CONFIG0_ID=$(sudo docker run -d $IMAGE mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) +CONFIG0_ID=$(sudo docker run -d $IMAGE mongod --configsvr --dbpath /data/ --bind_ip 0.0.0.0 --port 10000) #CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) CONFIG0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONFIG0_ID` echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" @@ -70,7 +70,7 @@ done echo "The config is available now..." -MONGOS0_ID=$(sudo docker run -p 9999:9999 -d $IMAGE mongos --configdb ${CONFIG0_IP}:10000 --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) +MONGOS0_ID=$(sudo docker run -p 9999:9999 -d $IMAGE mongos --configdb ${CONFIG0_IP}:10000 --bind_ip 0.0.0.0 --port 9999) #MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) MONGOS0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGOS0_ID` echo "Contacting shard and mongod containers" From 277e494494590a56bc774d0d9c8b1cb309d4ad8f Mon Sep 17 00:00:00 2001 From: phra Date: Fri, 18 Nov 2016 15:51:29 +0100 Subject: [PATCH 07/17] chmod u+x scripts --- bin/start-cluster.sh | 0 bin/stop-cluster.sh | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 bin/start-cluster.sh mode change 100644 => 100755 bin/stop-cluster.sh diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh old mode 100644 new mode 100755 diff --git a/bin/stop-cluster.sh b/bin/stop-cluster.sh old mode 100644 new mode 100755 From 8ce5706b0b6a0c18335e17e4b7bb02641bda589a Mon Sep 17 00:00:00 2001 From: phra Date: Fri, 18 Nov 2016 15:58:25 +0100 Subject: [PATCH 08/17] change grep text --- bin/start-cluster.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 969681f..aaedc26 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -52,7 +52,7 @@ done echo "initialize replicaset" mongo ${SHARD00_IP}:10000 --eval "rs.initiate({_id: \"rs0\", members: [{_id:0, host:\"${SHARD00_IP}:10000\"}, {_id:1, host:\"${SHARD01_IP}:10001\"}, {_id:2, host:\"${SHARD02_IP}:10002\"}]});" -until sudo docker logs ${SHARD00_ID} | grep "replSet PRIMARY" >/dev/null; +until sudo docker logs ${SHARD00_ID} | grep "state PRIMARY" >/dev/null; do sleep 2 done From ab45ab6944cc47b222b6b5118d7cb5dde84e8778 Mon Sep 17 00:00:00 2001 From: phra Date: Fri, 18 Nov 2016 16:10:06 +0100 Subject: [PATCH 09/17] update script to mongo 3.2 and docker 1.12 --- Makefile | 2 + bin/start-cluster.sh | 81 ++++++++++++++++++++++++++------------ stop-remove-all.sh | 3 ++ stop-remove-restart-all.sh | 2 + 4 files changed, 62 insertions(+), 26 deletions(-) create mode 100755 stop-remove-all.sh create mode 100755 stop-remove-restart-all.sh diff --git a/Makefile b/Makefile index 6273056..3be02be 100644 --- a/Makefile +++ b/Makefile @@ -9,3 +9,5 @@ start-cluster: stop-cluster: bash ./bin/stop-cluster.sh +restart-cluster: + ./stop-remove-restart-all.sh diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index aaedc26..c03dbde 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -4,8 +4,30 @@ ### TODO 2 - create function `create_mongos` that instantiates mongos ### TODO 3 - create a function that create n replica sets and n shards -#IMAGE="ankurcha/tokumx" +NAME_INDEX=0 +NAME_CFG_INDEX=0 +NAME_MONGOS_INDEX=0 +PORT_INDEX=10000 +MONGOS_PORT=9999 IMAGE="mongo" +NET="my-mongo-cluster" +BIND_ADDRESS=0.0.0.0 + +start_mongod_docker() { + echo `sudo docker run --detach --name mongo${NAME_INDEX} --net ${NET} ${IMAGE} mongod --replSet rs0 --shardsvr --bind_ip ${BIND_ADDRESS} --port ${PORT_INDEX}` +} + +start_mongocfg_docker() { + echo `sudo docker run --detach --name mongocfg${NAME_CFG_INDEX} --net ${NET} ${IMAGE} mongod --configsvr --bind_ip ${BIND_ADDRESS} --port ${PORT_INDEX}` +} + +start_mongos_docker() { + echo `sudo docker run --detach -p ${MONGOS_PORT}:${MONGOS_PORT} --name mongos${NAME_MONGOS_INDEX} --net ${NET} ${IMAGE} mongos --configdb ${1}:${2} --bind_ip ${BIND_ADDRESS} --port ${MONGOS_PORT}` +} + +get_ip_from_id() { + echo `sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${1}` +} set -e @@ -22,67 +44,74 @@ if sudo docker ps | grep $IMAGE >/dev/null; then fi # start docker containers for 3xreplicaset rs0 -SHARD00_ID=$(sudo docker run -dt $IMAGE mongod --replSet rs0 --shardsvr --bind_ip 0.0.0.0 --port 10000) -#SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` -#echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` +SHARD00_ID=`start_mongod_docker` +SHARD00_IP=`get_ip_from_id $SHARD00_ID` echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port 10000" >/dev/null; +until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done +echo NAME_INDEX $((NAME_INDEX++)) +echo PORT_INDEX $((PORT_INDEX++)) -SHARD01_ID=$(sudo docker run -dt $IMAGE mongod --replSet rs0 --shardsvr --bind_ip 0.0.0.0 --port 10001) -#SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` +SHARD01_ID=`start_mongod_docker` +SHARD01_IP=`get_ip_from_id $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port 10001" >/dev/null; +until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done +echo NAME_INDEX $((NAME_INDEX++)) +echo PORT_INDEX $((PORT_INDEX++)) -SHARD02_ID=$(sudo docker run -dt $IMAGE mongod --replSet rs0 --shardsvr --bind_ip 0.0.0.0 --port 10002) -#SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` +SHARD02_ID=`start_mongod_docker` +SHARD02_IP=`get_ip_from_id $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port 10002" >/dev/null; +until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done +echo NAME_INDEX $((NAME_INDEX++)) +echo PORT_INDEX $((PORT_INDEX++)) echo "initialize replicaset" -mongo ${SHARD00_IP}:10000 --eval "rs.initiate({_id: \"rs0\", members: [{_id:0, host:\"${SHARD00_IP}:10000\"}, {_id:1, host:\"${SHARD01_IP}:10001\"}, {_id:2, host:\"${SHARD02_IP}:10002\"}]});" -until sudo docker logs ${SHARD00_ID} | grep "state PRIMARY" >/dev/null; +sudo docker exec ${SHARD00_ID} mongo localhost:10000 --eval "rs.initiate();" > /dev/null +echo mongo ${SHARD00_IP}:10000 --eval "rs.initiate();" +sudo docker exec ${SHARD00_ID} mongo localhost:10000 --eval "rs.add(\"${SHARD01_IP}:10001\");" > /dev/null +echo mongo ${SHARD00_IP}:10000 --eval "rs.add(\"${SHARD01_IP}:10001\");" +sudo docker exec ${SHARD00_ID} mongo localhost:10000 --eval "rs.add(\"${SHARD02_IP}:10002\");" > /dev/null +echo mongo ${SHARD00_IP}:10000 --eval "rs.add(\"${SHARD02_IP}:10002\");" +until sudo docker logs ${SHARD00_ID} | grep "10002 is now in state SECONDARY" > /dev/null; do sleep 2 done echo "The shard replset is available now..." -CONFIG0_ID=$(sudo docker run -d $IMAGE mongod --configsvr --dbpath /data/ --bind_ip 0.0.0.0 --port 10000) -#CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -CONFIG0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONFIG0_ID` +CONFIG0_ID=`start_mongocfg_docker` +CONFIG0_IP=`get_ip_from_id $CONFIG0_ID` echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" -until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; +until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done +echo NAME_CFG_INDEX $((NAME_CFG_INDEX++)) +echo PORT_INDEX $((PORT_INDEX++)) echo "The config is available now..." -MONGOS0_ID=$(sudo docker run -p 9999:9999 -d $IMAGE mongos --configdb ${CONFIG0_IP}:10000 --bind_ip 0.0.0.0 --port 9999) -#MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -MONGOS0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGOS0_ID` +MONGOS0_ID=`start_mongos_docker ${CONFIG0_IP} $((PORT_INDEX - 1))` +MONGOS0_IP=`get_ip_from_id $MONGOS0_ID` echo "Contacting shard and mongod containers" -until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; +until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" > /dev/null; do sleep 2 done # Add the shard -mongo ${MONGOS0_IP}:9999 --eval "sh.addShard(\"rs0/${SHARD00_IP}:10000\");" +mongo ${MONGOS0_IP}:${MONGOS_PORT} --eval "sh.addShard(\"rs0/${SHARD00_IP}:10000,${SHARD01_IP}:10001,${SHARD02_IP}:10002\");" echo "OK, you can connect to mongos using: " -echo "mongo ${MONGOS0_IP}:9999" +echo "mongo ${MONGOS0_IP}:${MONGOS_PORT}" diff --git a/stop-remove-all.sh b/stop-remove-all.sh new file mode 100755 index 0000000..d903f06 --- /dev/null +++ b/stop-remove-all.sh @@ -0,0 +1,3 @@ +sudo docker stop $(sudo docker ps -a -q) +sudo docker rm $(sudo docker ps -a -q) +sudo docker volume rm $(sudo docker volume ls -qf dangling=true) diff --git a/stop-remove-restart-all.sh b/stop-remove-restart-all.sh new file mode 100755 index 0000000..f262f46 --- /dev/null +++ b/stop-remove-restart-all.sh @@ -0,0 +1,2 @@ +./stop-remove-all.sh +./bin/start-cluster.sh From ef8d874422bd375584bbfbe6aba4e884e1471356 Mon Sep 17 00:00:00 2001 From: phra Date: Mon, 21 Nov 2016 18:21:54 +0100 Subject: [PATCH 10/17] remove ports management --- bin/start-cluster.sh | 37 +++++++++++-------------------------- 1 file changed, 11 insertions(+), 26 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index c03dbde..e93139e 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -4,25 +4,21 @@ ### TODO 2 - create function `create_mongos` that instantiates mongos ### TODO 3 - create a function that create n replica sets and n shards -NAME_INDEX=0 -NAME_CFG_INDEX=0 -NAME_MONGOS_INDEX=0 -PORT_INDEX=10000 -MONGOS_PORT=9999 +MONGOS_PORT=27017 IMAGE="mongo" NET="my-mongo-cluster" BIND_ADDRESS=0.0.0.0 start_mongod_docker() { - echo `sudo docker run --detach --name mongo${NAME_INDEX} --net ${NET} ${IMAGE} mongod --replSet rs0 --shardsvr --bind_ip ${BIND_ADDRESS} --port ${PORT_INDEX}` + echo `sudo docker run --detach --net ${NET} ${IMAGE} mongod --replSet rs0 --shardsvr --bind_ip ${BIND_ADDRESS}` } start_mongocfg_docker() { - echo `sudo docker run --detach --name mongocfg${NAME_CFG_INDEX} --net ${NET} ${IMAGE} mongod --configsvr --bind_ip ${BIND_ADDRESS} --port ${PORT_INDEX}` + echo `sudo docker run --detach --net ${NET} ${IMAGE} mongod --configsvr --bind_ip ${BIND_ADDRESS}` } start_mongos_docker() { - echo `sudo docker run --detach -p ${MONGOS_PORT}:${MONGOS_PORT} --name mongos${NAME_MONGOS_INDEX} --net ${NET} ${IMAGE} mongos --configdb ${1}:${2} --bind_ip ${BIND_ADDRESS} --port ${MONGOS_PORT}` + echo `sudo docker run --detach -p ${MONGOS_PORT}:${MONGOS_PORT} --net ${NET} ${IMAGE} mongos --configdb ${1} --bind_ip ${BIND_ADDRESS}` } get_ip_from_id() { @@ -51,8 +47,6 @@ until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port" > do sleep 2 done -echo NAME_INDEX $((NAME_INDEX++)) -echo PORT_INDEX $((PORT_INDEX++)) SHARD01_ID=`start_mongod_docker` SHARD01_IP=`get_ip_from_id $SHARD01_ID` @@ -61,8 +55,6 @@ until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port" > do sleep 2 done -echo NAME_INDEX $((NAME_INDEX++)) -echo PORT_INDEX $((PORT_INDEX++)) SHARD02_ID=`start_mongod_docker` SHARD02_IP=`get_ip_from_id $SHARD02_ID` @@ -71,17 +63,12 @@ until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port" > do sleep 2 done -echo NAME_INDEX $((NAME_INDEX++)) -echo PORT_INDEX $((PORT_INDEX++)) echo "initialize replicaset" -sudo docker exec ${SHARD00_ID} mongo localhost:10000 --eval "rs.initiate();" > /dev/null -echo mongo ${SHARD00_IP}:10000 --eval "rs.initiate();" -sudo docker exec ${SHARD00_ID} mongo localhost:10000 --eval "rs.add(\"${SHARD01_IP}:10001\");" > /dev/null -echo mongo ${SHARD00_IP}:10000 --eval "rs.add(\"${SHARD01_IP}:10001\");" -sudo docker exec ${SHARD00_ID} mongo localhost:10000 --eval "rs.add(\"${SHARD02_IP}:10002\");" > /dev/null -echo mongo ${SHARD00_IP}:10000 --eval "rs.add(\"${SHARD02_IP}:10002\");" -until sudo docker logs ${SHARD00_ID} | grep "10002 is now in state SECONDARY" > /dev/null; +sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.initiate();" > /dev/null +sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD01_IP}:27018\");" > /dev/null +sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD02_IP}:27018\");" > /dev/null +until sudo docker logs ${SHARD00_ID} | grep "is now in state SECONDARY" > /dev/null; do sleep 2 done @@ -95,12 +82,10 @@ until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" > do sleep 2 done -echo NAME_CFG_INDEX $((NAME_CFG_INDEX++)) -echo PORT_INDEX $((PORT_INDEX++)) echo "The config is available now..." -MONGOS0_ID=`start_mongos_docker ${CONFIG0_IP} $((PORT_INDEX - 1))` +MONGOS0_ID=`start_mongos_docker ${CONFIG0_IP}:27019` MONGOS0_IP=`get_ip_from_id $MONGOS0_ID` echo "Contacting shard and mongod containers" @@ -110,8 +95,8 @@ do done # Add the shard -mongo ${MONGOS0_IP}:${MONGOS_PORT} --eval "sh.addShard(\"rs0/${SHARD00_IP}:10000,${SHARD01_IP}:10001,${SHARD02_IP}:10002\");" +sudo docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs0/${SHARD00_IP}:27018,${SHARD01_IP}:27018,${SHARD02_IP}:27018\");" > /dev/null echo "OK, you can connect to mongos using: " -echo "mongo ${MONGOS0_IP}:${MONGOS_PORT}" +echo "mongo ${MONGOS0_IP}" From 508981d965d2e6acd7cb9e9e27f4a1a53ce5465b Mon Sep 17 00:00:00 2001 From: phra Date: Mon, 21 Nov 2016 18:37:13 +0100 Subject: [PATCH 11/17] change makefile task name --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 3be02be..5869725 100644 --- a/Makefile +++ b/Makefile @@ -9,5 +9,5 @@ start-cluster: stop-cluster: bash ./bin/stop-cluster.sh -restart-cluster: +rebuild-cluster: ./stop-remove-restart-all.sh From 1f3dbc6d52766c20ac10837ed80803d6c6a3b70f Mon Sep 17 00:00:00 2001 From: phra Date: Mon, 21 Nov 2016 19:03:41 +0100 Subject: [PATCH 12/17] parameterized creation of shards --- bin/start-cluster.sh | 110 +++++++++++++++++++++++++------------------ 1 file changed, 65 insertions(+), 45 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index e93139e..87805b2 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -9,8 +9,10 @@ IMAGE="mongo" NET="my-mongo-cluster" BIND_ADDRESS=0.0.0.0 +set -e + start_mongod_docker() { - echo `sudo docker run --detach --net ${NET} ${IMAGE} mongod --replSet rs0 --shardsvr --bind_ip ${BIND_ADDRESS}` + echo `sudo docker run --detach --net ${NET} ${IMAGE} mongod --replSet rs$1 --shardsvr --bind_ip ${BIND_ADDRESS}` } start_mongocfg_docker() { @@ -25,7 +27,66 @@ get_ip_from_id() { echo `sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${1}` } -set -e +start_shard() { + # start docker containers for 3xreplicaset rs0 + SHARD00_ID=`start_mongod_docker $1` + SHARD00_IP=`get_ip_from_id $SHARD00_ID` + echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" + until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port" > /dev/null; + do + sleep 2 + done + + SHARD01_ID=`start_mongod_docker $1` + SHARD01_IP=`get_ip_from_id $SHARD01_ID` + echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" + until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port" > /dev/null; + do + sleep 2 + done + + SHARD02_ID=`start_mongod_docker $1` + SHARD02_IP=`get_ip_from_id $SHARD02_ID` + echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" + until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port" > /dev/null; + do + sleep 2 + done + + echo "initialize replicaset" + sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.initiate();" + until sudo docker logs ${SHARD00_ID} | grep "PRIMARY" > /dev/null; + do + sleep 2 + done + + echo "patching host for docker" + sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "cfg = rs.conf(); cfg.members[0].host = \"${SHARD00_IP}:27018\"; rs.reconfig(cfg);" + until sudo docker logs ${SHARD00_ID} | grep "This node is ${SHARD00_IP}:27018 in the config" > /dev/null; + do + sleep 2 + done + + sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD01_IP}:27018\");" > /dev/null + sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD02_IP}:27018\");" > /dev/null + until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD01_IP}:27018 is now in state SECONDARY" > /dev/null; + do + sleep 2 + done + until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD02_IP}:27018 is now in state SECONDARY" > /dev/null; + do + sleep 2 + done + echo "The shard replset is available now..." + + # Add the shard + echo `sudo docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs$1/${SHARD00_IP}:27018,${SHARD01_IP}:27018,${SHARD02_IP}:27018\");"` + echo "Contacting shard and mongod containers rs$1" + until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" > /dev/null; + do + sleep 2 + done +} if sudo docker ps | grep $IMAGE >/dev/null; then echo "" @@ -39,41 +100,6 @@ if sudo docker ps | grep $IMAGE >/dev/null; then exit 1 fi -# start docker containers for 3xreplicaset rs0 -SHARD00_ID=`start_mongod_docker` -SHARD00_IP=`get_ip_from_id $SHARD00_ID` -echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port" > /dev/null; -do - sleep 2 -done - -SHARD01_ID=`start_mongod_docker` -SHARD01_IP=`get_ip_from_id $SHARD01_ID` -echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port" > /dev/null; -do - sleep 2 -done - -SHARD02_ID=`start_mongod_docker` -SHARD02_IP=`get_ip_from_id $SHARD02_ID` -echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port" > /dev/null; -do - sleep 2 -done - -echo "initialize replicaset" -sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.initiate();" > /dev/null -sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD01_IP}:27018\");" > /dev/null -sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD02_IP}:27018\");" > /dev/null -until sudo docker logs ${SHARD00_ID} | grep "is now in state SECONDARY" > /dev/null; -do - sleep 2 -done -echo "The shard replset is available now..." - CONFIG0_ID=`start_mongocfg_docker` CONFIG0_IP=`get_ip_from_id $CONFIG0_ID` echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" @@ -87,16 +113,10 @@ echo "The config is available now..." MONGOS0_ID=`start_mongos_docker ${CONFIG0_IP}:27019` MONGOS0_IP=`get_ip_from_id $MONGOS0_ID` -echo "Contacting shard and mongod containers" -until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" > /dev/null; -do - sleep 2 +for i in `seq 0 ${1:-0}`; do + start_shard $i done -# Add the shard -sudo docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs0/${SHARD00_IP}:27018,${SHARD01_IP}:27018,${SHARD02_IP}:27018\");" > /dev/null - echo "OK, you can connect to mongos using: " echo "mongo ${MONGOS0_IP}" - From e7e767104b53a51732948f626f68cbe563366c9a Mon Sep 17 00:00:00 2001 From: phra Date: Tue, 22 Nov 2016 13:36:28 +0100 Subject: [PATCH 13/17] add persistence of shard instances --- bin/start-cluster.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 87805b2..c994495 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -12,7 +12,9 @@ BIND_ADDRESS=0.0.0.0 set -e start_mongod_docker() { - echo `sudo docker run --detach --net ${NET} ${IMAGE} mongod --replSet rs$1 --shardsvr --bind_ip ${BIND_ADDRESS}` + DATA_PATH=/data/shard${1}${2} + sudo mkdir -p $DATA_PATH > /dev/null + echo `sudo docker run --detach -v /data --net ${NET} ${IMAGE} mongod --replSet rs$1 --shardsvr --bind_ip ${BIND_ADDRESS}` } start_mongocfg_docker() { @@ -29,7 +31,7 @@ get_ip_from_id() { start_shard() { # start docker containers for 3xreplicaset rs0 - SHARD00_ID=`start_mongod_docker $1` + SHARD00_ID=`start_mongod_docker $1 0` SHARD00_IP=`get_ip_from_id $SHARD00_ID` echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port" > /dev/null; @@ -37,7 +39,7 @@ start_shard() { sleep 2 done - SHARD01_ID=`start_mongod_docker $1` + SHARD01_ID=`start_mongod_docker $1 1` SHARD01_IP=`get_ip_from_id $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port" > /dev/null; @@ -45,7 +47,7 @@ start_shard() { sleep 2 done - SHARD02_ID=`start_mongod_docker $1` + SHARD02_ID=`start_mongod_docker $1 2` SHARD02_IP=`get_ip_from_id $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port" > /dev/null; @@ -114,7 +116,7 @@ echo "The config is available now..." MONGOS0_ID=`start_mongos_docker ${CONFIG0_IP}:27019` MONGOS0_IP=`get_ip_from_id $MONGOS0_ID` -for i in `seq 0 ${1:-0}`; do +for i in `seq 0 $((${1:-1} - 1))`; do start_shard $i done From aa817c5f60d933362fdb013ff60de7d065514405 Mon Sep 17 00:00:00 2001 From: phra Date: Tue, 22 Nov 2016 14:10:43 +0100 Subject: [PATCH 14/17] change replica db to CSRS --- bin/start-cluster.sh | 96 ++++++++++++++++++++++++++++++++------------ 1 file changed, 70 insertions(+), 26 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index c994495..4553e06 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -5,32 +5,81 @@ ### TODO 3 - create a function that create n replica sets and n shards MONGOS_PORT=27017 -IMAGE="mongo" +SHARDS_PORT=27018 +CONFIG_PORT=27019 +IMAGE="mongo:3.2" NET="my-mongo-cluster" BIND_ADDRESS=0.0.0.0 set -e +get_ip_from_id() { + echo `sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${1}` +} + start_mongod_docker() { - DATA_PATH=/data/shard${1}${2} - sudo mkdir -p $DATA_PATH > /dev/null - echo `sudo docker run --detach -v /data --net ${NET} ${IMAGE} mongod --replSet rs$1 --shardsvr --bind_ip ${BIND_ADDRESS}` + DATA_PATH="/data/db/shard${1}${2}" + echo `sudo docker run --detach -v ${DATA_PATH}:${DATA_PATH} --net ${NET} ${IMAGE} mongod --replSet rs$1 --dbpath ${DATA_PATH} --shardsvr --bind_ip ${BIND_ADDRESS}` } start_mongocfg_docker() { - echo `sudo docker run --detach --net ${NET} ${IMAGE} mongod --configsvr --bind_ip ${BIND_ADDRESS}` + CFG_PATH="/data/configdb/cfg${1}" + echo `sudo docker run --detach -v ${CFG_PATH}:${CFG_PATH} --net ${NET} ${IMAGE} mongod --dbpath ${CFG_PATH} --replSet cfg --configsvr --bind_ip ${BIND_ADDRESS}` } start_mongos_docker() { echo `sudo docker run --detach -p ${MONGOS_PORT}:${MONGOS_PORT} --net ${NET} ${IMAGE} mongos --configdb ${1} --bind_ip ${BIND_ADDRESS}` } -get_ip_from_id() { - echo `sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${1}` +start_mongocfg_replica_docker() { + CFG0_ID=`start_mongocfg_docker 0` + CFG0_IP=`get_ip_from_id $CFG0_ID` + until sudo docker logs ${CFG0_ID} | grep "waiting for connections on port" > /dev/null; + do + sleep 2 + done + + CFG1_ID=`start_mongocfg_docker 1` + CFG1_IP=`get_ip_from_id $CFG1_ID` + until sudo docker logs ${CFG1_ID} | grep "waiting for connections on port" > /dev/null + do + sleep 2 + done + + CFG2_ID=`start_mongocfg_docker 2` + CFG2_IP=`get_ip_from_id $CFG2_ID` + until sudo docker logs ${CFG2_ID} | grep "waiting for connections on port" > /dev/null; + do + sleep 2 + done + + sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.initiate();" > /dev/null; + until sudo docker logs ${CFG0_ID} | grep "PRIMARY" > /dev/null; + do + sleep 2 + done + + sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "cfg = rs.conf(); cfg.members[0].host = \"${CFG0_IP}:${CONFIG_PORT}\"; rs.reconfig(cfg);" > /dev/null; + until sudo docker logs ${CFG0_ID} | grep "This node is ${CFG0_IP}:${CONFIG_PORT} in the config" > /dev/null; + do + sleep 2 + done + + sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.add(\"${CFG1_IP}:${CONFIG_PORT}\");" > /dev/null + sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.add(\"${CFG2_IP}:${CONFIG_PORT}\");" > /dev/null + until sudo docker logs ${CFG0_ID} | grep "Member ${CFG1_IP}:${CONFIG_PORT} is now in state SECONDARY" > /dev/null; + do + sleep 2 + done + until sudo docker logs ${CFG0_ID} | grep "Member ${CFG2_IP}:${CONFIG_PORT} is now in state SECONDARY" > /dev/null; + do + sleep 2 + done + + echo "cfg/${CFG0_IP}:${CONFIG_PORT},${CFG1_IP}:${CONFIG_PORT},${CFG2_IP}:${CONFIG_PORT}" } start_shard() { - # start docker containers for 3xreplicaset rs0 SHARD00_ID=`start_mongod_docker $1 0` SHARD00_IP=`get_ip_from_id $SHARD00_ID` echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" @@ -56,33 +105,32 @@ start_shard() { done echo "initialize replicaset" - sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.initiate();" + sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.initiate();" until sudo docker logs ${SHARD00_ID} | grep "PRIMARY" > /dev/null; do sleep 2 done echo "patching host for docker" - sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "cfg = rs.conf(); cfg.members[0].host = \"${SHARD00_IP}:27018\"; rs.reconfig(cfg);" - until sudo docker logs ${SHARD00_ID} | grep "This node is ${SHARD00_IP}:27018 in the config" > /dev/null; + sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "cfg = rs.conf(); cfg.members[0].host = \"${SHARD00_IP}:${SHARDS_PORT}\"; rs.reconfig(cfg);" + until sudo docker logs ${SHARD00_ID} | grep "This node is ${SHARD00_IP}:${SHARDS_PORT} in the config" > /dev/null; do sleep 2 done - sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD01_IP}:27018\");" > /dev/null - sudo docker exec ${SHARD00_ID} mongo --port 27018 --eval "rs.add(\"${SHARD02_IP}:27018\");" > /dev/null - until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD01_IP}:27018 is now in state SECONDARY" > /dev/null; + sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.add(\"${SHARD01_IP}:${SHARDS_PORT}\");" > /dev/null + sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.add(\"${SHARD02_IP}:${SHARDS_PORT}\");" > /dev/null + until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD01_IP}:${SHARDS_PORT} is now in state SECONDARY" > /dev/null; do sleep 2 done - until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD02_IP}:27018 is now in state SECONDARY" > /dev/null; + until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD02_IP}:${SHARDS_PORT} is now in state SECONDARY" > /dev/null; do sleep 2 done echo "The shard replset is available now..." - # Add the shard - echo `sudo docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs$1/${SHARD00_IP}:27018,${SHARD01_IP}:27018,${SHARD02_IP}:27018\");"` + echo `sudo docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs$1/${SHARD00_IP}:${SHARDS_PORT},${SHARD01_IP}:${SHARDS_PORT},${SHARD02_IP}:${SHARDS_PORT}\");"` echo "Contacting shard and mongod containers rs$1" until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" > /dev/null; do @@ -102,21 +150,17 @@ if sudo docker ps | grep $IMAGE >/dev/null; then exit 1 fi -CONFIG0_ID=`start_mongocfg_docker` -CONFIG0_IP=`get_ip_from_id $CONFIG0_ID` -echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" +echo "Preparing config db..." -until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" > /dev/null; -do - sleep 2 -done +CONFIG0=`start_mongocfg_replica_docker` -echo "The config is available now..." +echo "The config is available now @ ${CONFIG0}..." -MONGOS0_ID=`start_mongos_docker ${CONFIG0_IP}:27019` +MONGOS0_ID=`start_mongos_docker ${CONFIG0}` MONGOS0_IP=`get_ip_from_id $MONGOS0_ID` for i in `seq 0 $((${1:-1} - 1))`; do + echo "Starting shard #$i creation..." start_shard $i done From 25b1086dc990b96e111c64a32a17e88c97f0bc19 Mon Sep 17 00:00:00 2001 From: phra Date: Tue, 22 Nov 2016 15:28:34 +0100 Subject: [PATCH 15/17] move files in bin directory --- Makefile | 4 +- bin/start-cluster.sh.rej | 52 -------------------- stop-remove-all.sh => bin/stop-remove-all.sh | 0 bin/stop-remove-restart-all.sh | 2 + stop-remove-restart-all.sh | 2 - 5 files changed, 4 insertions(+), 56 deletions(-) delete mode 100644 bin/start-cluster.sh.rej rename stop-remove-all.sh => bin/stop-remove-all.sh (100%) create mode 100755 bin/stop-remove-restart-all.sh delete mode 100755 stop-remove-restart-all.sh diff --git a/Makefile b/Makefile index 5869725..f8df306 100644 --- a/Makefile +++ b/Makefile @@ -4,10 +4,10 @@ tokumx-container: sudo docker pull "ankurcha/tokumx" start-cluster: - bash ./bin/start-cluster.sh + bash ./bin/start-cluster.sh $(instances) stop-cluster: bash ./bin/stop-cluster.sh rebuild-cluster: - ./stop-remove-restart-all.sh + bash ./bin/stop-remove-restart-all.sh $(instances) diff --git a/bin/start-cluster.sh.rej b/bin/start-cluster.sh.rej deleted file mode 100644 index 703f55a..0000000 --- a/bin/start-cluster.sh.rej +++ /dev/null @@ -1,52 +0,0 @@ -diff a/bin/start-cluster.sh b/bin/start-cluster.sh (rejected hunks) -@@ -16,7 +16,9 @@ fi - - # start docker containers for 3xreplicaset rs0 - SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) --SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+#SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+SHARD00_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD00_ID` -+#echo `sudo docker inspect --format '{{ .NetworkSettings.IPAddress }}' "$@" $SHARD00_ID` - echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" - until sudo docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; - do -@@ -24,7 +26,8 @@ do - done - - SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10001) --SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+#SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+SHARD01_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD01_ID` - echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" - until sudo docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; - do -@@ -32,7 +35,8 @@ do - done - - SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet rs0 --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10002) --SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+#SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+SHARD02_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $SHARD02_ID` - echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" - until sudo docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; - do -@@ -48,7 +52,8 @@ done - echo "The shard replset is available now..." - - CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port 10000) --CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+#CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+CONFIG0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $CONFIG0_ID` - echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" - - until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; -@@ -59,7 +64,8 @@ done - echo "The config is available now..." - - MONGOS0_ID=$(sudo docker run -p 9999:9999 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:10000 --logpath /dev/stdout --bind_ip 0.0.0.0 --port 9999) --MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+#MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) -+MONGOS0_IP=`sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $MONGOS0_ID` - echo "Contacting shard and mongod containers" - - until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; diff --git a/stop-remove-all.sh b/bin/stop-remove-all.sh similarity index 100% rename from stop-remove-all.sh rename to bin/stop-remove-all.sh diff --git a/bin/stop-remove-restart-all.sh b/bin/stop-remove-restart-all.sh new file mode 100755 index 0000000..6f03488 --- /dev/null +++ b/bin/stop-remove-restart-all.sh @@ -0,0 +1,2 @@ +./stop-remove-all.sh +./start-cluster.sh $1 diff --git a/stop-remove-restart-all.sh b/stop-remove-restart-all.sh deleted file mode 100755 index f262f46..0000000 --- a/stop-remove-restart-all.sh +++ /dev/null @@ -1,2 +0,0 @@ -./stop-remove-all.sh -./bin/start-cluster.sh From aff2ab90b66f648c6a7aa9bbadd5766b99ca937c Mon Sep 17 00:00:00 2001 From: bitliner Date: Sat, 18 Mar 2017 21:29:52 +0100 Subject: [PATCH 16/17] -sudo --- Makefile | 2 +- bin/start-cluster.sh | 61 +++++++++++++++++++++------------------- bin/start_singleShard.sh | 32 ++++++++++----------- bin/stop-all-clusters | 4 +-- bin/stop-cluster | 4 +-- bin/stop-cluster.sh | 4 +-- bin/stop-remove-all.sh | 6 ++-- 7 files changed, 58 insertions(+), 55 deletions(-) diff --git a/Makefile b/Makefile index f8df306..c36565c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ all: start-cluster tokumx-container: - sudo docker pull "ankurcha/tokumx" + docker pull "ankurcha/tokumx" start-cluster: bash ./bin/start-cluster.sh $(instances) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 4553e06..403fc54 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -12,66 +12,69 @@ NET="my-mongo-cluster" BIND_ADDRESS=0.0.0.0 set -e +docker network rm my-mongo-cluster +docker network create --driver bridge my-mongo-cluster get_ip_from_id() { - echo `sudo docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${1}` + echo `docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' ${1}` } start_mongod_docker() { + # echo "Starting a docker instance - shard${1}${2}" DATA_PATH="/data/db/shard${1}${2}" - echo `sudo docker run --detach -v ${DATA_PATH}:${DATA_PATH} --net ${NET} ${IMAGE} mongod --replSet rs$1 --dbpath ${DATA_PATH} --shardsvr --bind_ip ${BIND_ADDRESS}` + echo `docker run --detach -v ${DATA_PATH}:${DATA_PATH} --net ${NET} ${IMAGE} mongod --replSet rs$1 --dbpath ${DATA_PATH} --shardsvr --bind_ip ${BIND_ADDRESS}` } start_mongocfg_docker() { CFG_PATH="/data/configdb/cfg${1}" - echo `sudo docker run --detach -v ${CFG_PATH}:${CFG_PATH} --net ${NET} ${IMAGE} mongod --dbpath ${CFG_PATH} --replSet cfg --configsvr --bind_ip ${BIND_ADDRESS}` + echo `docker run --detach -v ${CFG_PATH}:${CFG_PATH} --net ${NET} ${IMAGE} mongod --dbpath ${CFG_PATH} --replSet cfg --configsvr --bind_ip ${BIND_ADDRESS}` } start_mongos_docker() { - echo `sudo docker run --detach -p ${MONGOS_PORT}:${MONGOS_PORT} --net ${NET} ${IMAGE} mongos --configdb ${1} --bind_ip ${BIND_ADDRESS}` + echo `docker run --detach -p ${MONGOS_PORT}:${MONGOS_PORT} --net ${NET} ${IMAGE} mongos --configdb ${1} --bind_ip ${BIND_ADDRESS}` } start_mongocfg_replica_docker() { CFG0_ID=`start_mongocfg_docker 0` CFG0_IP=`get_ip_from_id $CFG0_ID` - until sudo docker logs ${CFG0_ID} | grep "waiting for connections on port" > /dev/null; + until docker logs ${CFG0_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done CFG1_ID=`start_mongocfg_docker 1` CFG1_IP=`get_ip_from_id $CFG1_ID` - until sudo docker logs ${CFG1_ID} | grep "waiting for connections on port" > /dev/null + until docker logs ${CFG1_ID} | grep "waiting for connections on port" > /dev/null do sleep 2 done CFG2_ID=`start_mongocfg_docker 2` CFG2_IP=`get_ip_from_id $CFG2_ID` - until sudo docker logs ${CFG2_ID} | grep "waiting for connections on port" > /dev/null; + until docker logs ${CFG2_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done - sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.initiate();" > /dev/null; - until sudo docker logs ${CFG0_ID} | grep "PRIMARY" > /dev/null; + docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.initiate();" > /dev/null; + until docker logs ${CFG0_ID} | grep "PRIMARY" > /dev/null; do sleep 2 done - sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "cfg = rs.conf(); cfg.members[0].host = \"${CFG0_IP}:${CONFIG_PORT}\"; rs.reconfig(cfg);" > /dev/null; - until sudo docker logs ${CFG0_ID} | grep "This node is ${CFG0_IP}:${CONFIG_PORT} in the config" > /dev/null; + docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "cfg = rs.conf(); cfg.members[0].host = \"${CFG0_IP}:${CONFIG_PORT}\"; rs.reconfig(cfg);" > /dev/null; + until docker logs ${CFG0_ID} | grep "This node is ${CFG0_IP}:${CONFIG_PORT} in the config" > /dev/null; do sleep 2 done - sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.add(\"${CFG1_IP}:${CONFIG_PORT}\");" > /dev/null - sudo docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.add(\"${CFG2_IP}:${CONFIG_PORT}\");" > /dev/null - until sudo docker logs ${CFG0_ID} | grep "Member ${CFG1_IP}:${CONFIG_PORT} is now in state SECONDARY" > /dev/null; + docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.add(\"${CFG1_IP}:${CONFIG_PORT}\");" > /dev/null + docker exec ${CFG0_ID} mongo --port ${CONFIG_PORT} --eval "rs.add(\"${CFG2_IP}:${CONFIG_PORT}\");" > /dev/null + until docker logs ${CFG0_ID} | grep "Member ${CFG1_IP}:${CONFIG_PORT} is now in state SECONDARY" > /dev/null; do sleep 2 done - until sudo docker logs ${CFG0_ID} | grep "Member ${CFG2_IP}:${CONFIG_PORT} is now in state SECONDARY" > /dev/null; + until docker logs ${CFG0_ID} | grep "Member ${CFG2_IP}:${CONFIG_PORT} is now in state SECONDARY" > /dev/null; do sleep 2 done @@ -83,7 +86,7 @@ start_shard() { SHARD00_ID=`start_mongod_docker $1 0` SHARD00_IP=`get_ip_from_id $SHARD00_ID` echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" - until sudo docker logs ${SHARD00_ID} | grep "waiting for connections on port" > /dev/null; + until docker logs ${SHARD00_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done @@ -91,7 +94,7 @@ start_shard() { SHARD01_ID=`start_mongod_docker $1 1` SHARD01_IP=`get_ip_from_id $SHARD01_ID` echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" - until sudo docker logs ${SHARD01_ID} | grep "waiting for connections on port" > /dev/null; + until docker logs ${SHARD01_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done @@ -99,46 +102,46 @@ start_shard() { SHARD02_ID=`start_mongod_docker $1 2` SHARD02_IP=`get_ip_from_id $SHARD02_ID` echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" - until sudo docker logs ${SHARD02_ID} | grep "waiting for connections on port" > /dev/null; + until docker logs ${SHARD02_ID} | grep "waiting for connections on port" > /dev/null; do sleep 2 done echo "initialize replicaset" - sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.initiate();" - until sudo docker logs ${SHARD00_ID} | grep "PRIMARY" > /dev/null; + docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.initiate();" + until docker logs ${SHARD00_ID} | grep "PRIMARY" > /dev/null; do sleep 2 done echo "patching host for docker" - sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "cfg = rs.conf(); cfg.members[0].host = \"${SHARD00_IP}:${SHARDS_PORT}\"; rs.reconfig(cfg);" - until sudo docker logs ${SHARD00_ID} | grep "This node is ${SHARD00_IP}:${SHARDS_PORT} in the config" > /dev/null; + docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "cfg = rs.conf(); cfg.members[0].host = \"${SHARD00_IP}:${SHARDS_PORT}\"; rs.reconfig(cfg);" + until docker logs ${SHARD00_ID} | grep "This node is ${SHARD00_IP}:${SHARDS_PORT} in the config" > /dev/null; do sleep 2 done - sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.add(\"${SHARD01_IP}:${SHARDS_PORT}\");" > /dev/null - sudo docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.add(\"${SHARD02_IP}:${SHARDS_PORT}\");" > /dev/null - until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD01_IP}:${SHARDS_PORT} is now in state SECONDARY" > /dev/null; + docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.add(\"${SHARD01_IP}:${SHARDS_PORT}\");" > /dev/null + docker exec ${SHARD00_ID} mongo --port ${SHARDS_PORT} --eval "rs.add(\"${SHARD02_IP}:${SHARDS_PORT}\");" > /dev/null + until docker logs ${SHARD00_ID} | grep "Member ${SHARD01_IP}:${SHARDS_PORT} is now in state SECONDARY" > /dev/null; do sleep 2 done - until sudo docker logs ${SHARD00_ID} | grep "Member ${SHARD02_IP}:${SHARDS_PORT} is now in state SECONDARY" > /dev/null; + until docker logs ${SHARD00_ID} | grep "Member ${SHARD02_IP}:${SHARDS_PORT} is now in state SECONDARY" > /dev/null; do sleep 2 done echo "The shard replset is available now..." - echo `sudo docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs$1/${SHARD00_IP}:${SHARDS_PORT},${SHARD01_IP}:${SHARDS_PORT},${SHARD02_IP}:${SHARDS_PORT}\");"` + echo `docker exec ${MONGOS0_ID} mongo --eval "sh.addShard(\"rs$1/${SHARD00_IP}:${SHARDS_PORT},${SHARD01_IP}:${SHARDS_PORT},${SHARD02_IP}:${SHARDS_PORT}\");"` echo "Contacting shard and mongod containers rs$1" - until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" > /dev/null; + until docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" > /dev/null; do sleep 2 done } -if sudo docker ps | grep $IMAGE >/dev/null; then +if docker ps | grep $IMAGE >/dev/null; then echo "" echo "It looks like you already have some containers running." echo "Please take them down before attempting to bring up another" diff --git a/bin/start_singleShard.sh b/bin/start_singleShard.sh index 10e191b..2e4c8b8 100755 --- a/bin/start_singleShard.sh +++ b/bin/start_singleShard.sh @@ -17,26 +17,26 @@ PORT2=$(( $PORT + 2 )) set -e # start docker containers for 3xreplicaset $RS -SHARD00_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet $RS --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) -SHARD00_IP=$(sudo docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD00_ID=$(docker run -d ankurcha/tokumx mongod --replSet $RS --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) +SHARD00_IP=$(docker inspect ${SHARD00_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) echo "Your shard container ${SHARD00_ID} listen on ip: ${SHARD00_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; +until docker logs ${SHARD00_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; do sleep 2 done -SHARD01_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet $RS --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT1) -SHARD01_IP=$(sudo docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD01_ID=$(docker run -d ankurcha/tokumx mongod --replSet $RS --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT1) +SHARD01_IP=$(docker inspect ${SHARD01_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) echo "Your shard container ${SHARD01_ID} listen on ip: ${SHARD01_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; +until docker logs ${SHARD01_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; do sleep 2 done -SHARD02_ID=$(sudo docker run -d ankurcha/tokumx mongod --replSet $RS --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT2) -SHARD02_IP=$(sudo docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +SHARD02_ID=$(docker run -d ankurcha/tokumx mongod --replSet $RS --shardsvr --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT2) +SHARD02_IP=$(docker inspect ${SHARD02_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) echo "Your shard container ${SHARD02_ID} listen on ip: ${SHARD02_IP} (waiting that becomes ready)" -until sudo docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; +until docker logs ${SHARD02_ID} | grep "replSet info you may need to run replSetInitiate" >/dev/null; do sleep 2 done @@ -44,28 +44,28 @@ done echo "initialize replicaset" mongo ${SHARD00_IP}:$PORT --eval "rs.initiate({_id: \"$RS\", members: [{_id:0, host:\"${SHARD00_IP}:$PORT\"}, {_id:1, host:\"${SHARD01_IP}:$PORT1\"}, {_id:2, host:\"${SHARD02_IP}:$PORT2\"}]});" -until sudo docker logs ${SHARD00_ID} | grep "replSet PRIMARY" >/dev/null; +until docker logs ${SHARD00_ID} | grep "replSet PRIMARY" >/dev/null; do sleep 2 done echo "The shard replset is available now..." -CONFIG0_ID=$(sudo docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) -CONFIG0_IP=$(sudo docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +CONFIG0_ID=$(docker run -d ankurcha/tokumx mongod --configsvr --dbpath /data/ --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT) +CONFIG0_IP=$(docker inspect ${CONFIG0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) echo "Your config container ${CONFIG0_ID} listen on ip: ${CONFIG0_IP} (waiting that becomes ready)" -until sudo docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; +until docker logs ${CONFIG0_ID} | grep "waiting for connections on port" >/dev/null; do sleep 2 done echo "The config is available now..." -MONGOS0_ID=$(sudo docker run -p $PORT_1:$PORT_1 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:$PORT --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT_1) -MONGOS0_IP=$(sudo docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) +MONGOS0_ID=$(docker run -p $PORT_1:$PORT_1 -d ankurcha/tokumx mongos --configdb ${CONFIG0_IP}:$PORT --logpath /dev/stdout --bind_ip 0.0.0.0 --port $PORT_1) +MONGOS0_IP=$(docker inspect ${MONGOS0_ID} | grep "IPAddress" | cut -d':' -f2 | cut -d'"' -f2) echo "Contacting shard and mongod containers" -until sudo docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; +until docker logs ${MONGOS0_ID} | grep "config servers and shards contacted successfully" >/dev/null; do sleep 2 done diff --git a/bin/stop-all-clusters b/bin/stop-all-clusters index 7c1ea56..7f7aa30 100755 --- a/bin/stop-all-clusters +++ b/bin/stop-all-clusters @@ -2,7 +2,7 @@ set -e -if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then - sudo docker ps | grep "ankurcha/tokumx" | awk '{ print $1 }' | xargs -r sudo docker stop >/dev/null +if docker ps | grep "ankurcha/tokumx" >/dev/null; then + docker ps | grep "ankurcha/tokumx" | awk '{ print $1 }' | xargs -r docker stop >/dev/null echo "Stopped the cluster and cleared all of the running containers." fi diff --git a/bin/stop-cluster b/bin/stop-cluster index 7c1ea56..7f7aa30 100755 --- a/bin/stop-cluster +++ b/bin/stop-cluster @@ -2,7 +2,7 @@ set -e -if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then - sudo docker ps | grep "ankurcha/tokumx" | awk '{ print $1 }' | xargs -r sudo docker stop >/dev/null +if docker ps | grep "ankurcha/tokumx" >/dev/null; then + docker ps | grep "ankurcha/tokumx" | awk '{ print $1 }' | xargs -r docker stop >/dev/null echo "Stopped the cluster and cleared all of the running containers." fi diff --git a/bin/stop-cluster.sh b/bin/stop-cluster.sh index 7c1ea56..7f7aa30 100755 --- a/bin/stop-cluster.sh +++ b/bin/stop-cluster.sh @@ -2,7 +2,7 @@ set -e -if sudo docker ps | grep "ankurcha/tokumx" >/dev/null; then - sudo docker ps | grep "ankurcha/tokumx" | awk '{ print $1 }' | xargs -r sudo docker stop >/dev/null +if docker ps | grep "ankurcha/tokumx" >/dev/null; then + docker ps | grep "ankurcha/tokumx" | awk '{ print $1 }' | xargs -r docker stop >/dev/null echo "Stopped the cluster and cleared all of the running containers." fi diff --git a/bin/stop-remove-all.sh b/bin/stop-remove-all.sh index d903f06..e17c38f 100755 --- a/bin/stop-remove-all.sh +++ b/bin/stop-remove-all.sh @@ -1,3 +1,3 @@ -sudo docker stop $(sudo docker ps -a -q) -sudo docker rm $(sudo docker ps -a -q) -sudo docker volume rm $(sudo docker volume ls -qf dangling=true) +docker stop $(docker ps -a -q) +docker rm $(docker ps -a -q) +docker volume rm $(docker volume ls -qf dangling=true) From cd2a33dd3c273f6e1f592773d70c8e2071694af8 Mon Sep 17 00:00:00 2001 From: bitliner Date: Sat, 18 Mar 2017 22:19:12 +0100 Subject: [PATCH 17/17] +better management of data folder --- bin/start-cluster.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bin/start-cluster.sh b/bin/start-cluster.sh index 403fc54..fa7e727 100755 --- a/bin/start-cluster.sh +++ b/bin/start-cluster.sh @@ -10,6 +10,7 @@ CONFIG_PORT=27019 IMAGE="mongo:3.2" NET="my-mongo-cluster" BIND_ADDRESS=0.0.0.0 +DATA_ROOT=/data set -e docker network rm my-mongo-cluster @@ -21,12 +22,12 @@ get_ip_from_id() { start_mongod_docker() { # echo "Starting a docker instance - shard${1}${2}" - DATA_PATH="/data/db/shard${1}${2}" + DATA_PATH="$DATA_ROOT/db/shard${1}${2}" echo `docker run --detach -v ${DATA_PATH}:${DATA_PATH} --net ${NET} ${IMAGE} mongod --replSet rs$1 --dbpath ${DATA_PATH} --shardsvr --bind_ip ${BIND_ADDRESS}` } start_mongocfg_docker() { - CFG_PATH="/data/configdb/cfg${1}" + CFG_PATH="DATA_ROOT/configdb/cfg${1}" echo `docker run --detach -v ${CFG_PATH}:${CFG_PATH} --net ${NET} ${IMAGE} mongod --dbpath ${CFG_PATH} --replSet cfg --configsvr --bind_ip ${BIND_ADDRESS}` }