Last active
December 8, 2023 06:34
Revisions
-
leetreveil revised this gist
Oct 30, 2013 . 1 changed file with 39 additions and 0 deletions.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ #!/bin/bash # shell script to create a simple mongodb sharded cluster locally. # Requires a replica set to be already running, you can run # start-mongo-replset.sh first to start a replica set. set -e red=$(tput setaf 1) green=$(tput setaf 2) default=$(tput sgr0) function finish { pid=`cat ~/mongosvr/shard-config-0.pid` kill $pid wait $pid } trap finish EXIT mkdir -p ~/mongosvr/config-0 # start up the mongodb config server for the shards mongod --configsvr --dbpath ~/mongosvr/config-0 --port 27019 \ --config . --pidfilepath ~/mongosvr/shard-config-0.pid 2>&1 | sed "s/.*/$red&$default/" & sleep 3 mongos --configdb localhost:27019 | sed "s/.*/$green&$default/" & sleep 3 # add the first replica set instance as a shard, the others will be discovered automatically by mongos mongo --eval "JSON.stringify(sh._adminCommand( { addShard : 'set/localhost:27091' } , true ))" # enable sharding on the test database mongo --eval "JSON.stringify(sh._adminCommand( { enableSharding : 'test' } ))" # sleep forever cat -
leetreveil revised this gist
Oct 30, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -32,7 +32,7 @@ mongod --shardsvr --dbpath ~/mongosvr/rs-1 --replSet set --rest --port 27092 \ mongod --shardsvr --dbpath ~/mongosvr/rs-2 --replSet set --rest --port 27093 \ --config . --pidfilepath ~/mongosvr/rs-2.pid 2>&1 | sed "s/.*/$yellow&$default/" & # wait a bit for the first server to come up sleep 5 # call rs.initiate({...}) -
leetreveil revised this gist
Oct 30, 2013 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
Empty file. -
leetreveil revised this gist
Oct 30, 2013 . 1 changed file with 10 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -34,8 +34,17 @@ mongod --shardsvr --dbpath ~/mongosvr/rs-2 --replSet set --rest --port 27093 \ # wait for a bit for the first server to come up sleep 5 # call rs.initiate({...}) cfg="{ _id: 'set', members: [ {_id: 1, host: 'localhost:27091'}, {_id: 2, host: 'localhost:27092'}, {_id: 3, host: 'localhost:27093'} ] }" mongo localhost:27091 --eval "JSON.stringify(db.adminCommand({'replSetInitiate' : $cfg}))" # sleep forever cat -
leetreveil revised this gist
Oct 30, 2013 . 1 changed file with 14 additions and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,7 @@ #!/bin/bash # shell script to create a simple mongodb replica set (tested on osx) set -e red=$(tput setaf 1) green=$(tput setaf 2) @@ -15,14 +18,24 @@ function finish { } trap finish EXIT mkdir -p ~/mongosvr/rs-0 mkdir -p ~/mongosvr/rs-1 mkdir -p ~/mongosvr/rs-2 mongod --shardsvr --dbpath ~/mongosvr/rs-0 --replSet set --rest --port 27091 \ --config . --pidfilepath ~/mongosvr/rs-0.pid 2>&1 | sed "s/.*/$red&$default/" & mongod --shardsvr --dbpath ~/mongosvr/rs-1 --replSet set --rest --port 27092 \ --config . --pidfilepath ~/mongosvr/rs-1.pid 2>&1 | sed "s/.*/$green&$default/" & mongod --shardsvr --dbpath ~/mongosvr/rs-2 --replSet set --rest --port 27093 \ --config . --pidfilepath ~/mongosvr/rs-2.pid 2>&1 | sed "s/.*/$yellow&$default/" & # wait for a bit for the first server to come up sleep 5 # call rs.initiate({...}) mongo localhost:27091 --eval "JSON.stringify(db.adminCommand({'replSetInitiate' : {_id: 'set', members: [{_id: 1, host: 'localhost:27091'}, {_id: 2, host: 'localhost:27092'}, {_id: 3, host: 'localhost:27093'}]}}))" # sleep forever cat -
leetreveil revised this gist
Oct 30, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ # shell script to create a simple mongodb replica set (tested on osx) red=$(tput setaf 1) green=$(tput setaf 2) -
leetreveil created this gist
Oct 30, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ # shell script to create a simple mongodb replica set for (tested on osx) red=$(tput setaf 1) green=$(tput setaf 2) yellow=$(tput setaf 3) default=$(tput sgr0) function finish { pids=(`cat ~/mongosvr/rs-*.pid`) for pid in "${pids[@]}" do kill $pid wait $pid done } trap finish EXIT mongod --shardsvr --dbpath ~/mongosvr/rs-0 --replSet set --rest --port 27091 \ --config . --pidfilepath ~/mongosvr/rs-0.pid 2>&1 | sed "s/.*/$red&$default/" & mongod --shardsvr --dbpath ~/mongosvr/rs-1 --replSet set --rest --port 27092 \ --config . --pidfilepath ~/mongosvr/rs-1.pid 2>&1 | sed "s/.*/$green&$default/" & mongod --shardsvr --dbpath ~/mongosvr/rs-2 --replSet set --rest --port 27093 \ --config . --pidfilepath ~/mongosvr/rs-2.pid 2>&1 | sed "s/.*/$yellow&$default/" & # sleep forever cat