Skip to content

Instantly share code, notes, and snippets.

@akira-kurogane
Created January 16, 2015 01:24
Show Gist options
  • Save akira-kurogane/fe30701867026ac7d63d to your computer and use it in GitHub Desktop.
Save akira-kurogane/fe30701867026ac7d63d to your computer and use it in GitHub Desktop.
Bash script to launch three single mongo shard dbs, three configs, a mongos, and add the shards as initialization.
#!/bin/bash
set -e
set -x
hn=$(hostname -s)
dbpath=${HOME}/fresh_shard_cluster
mkdir ${dbpath} ${dbpath}/shard0{1,2,3} ${dbpath}/shard0{1,2,3}/db ${dbpath}/config{1,2,3} ${dbpath}/config{1,2,3}/db
if [ ! -f ${dbpath}/keyfile ]; then
openssl rand -base64 741 > ${dbpath}/keyfile
chmod 600 ${dbpath}/keyfile
fi
mongod --dbpath ${dbpath}/shard01/db --logpath ${dbpath}/shard01/mongod.log --port 27018 --fork --keyFile ${dbpath}/keyfile
mongod --dbpath ${dbpath}/shard02/db --logpath ${dbpath}/shard02/mongod.log --port 27019 --fork --keyFile ${dbpath}/keyfile
mongod --dbpath ${dbpath}/shard03/db --logpath ${dbpath}/shard03/mongod.log --port 27020 --fork --keyFile ${dbpath}/keyfile
mongod --dbpath ${dbpath}/config1/db --logpath ${dbpath}/config1/mongod.log --port 27021 --fork --keyFile ${dbpath}/keyfile --configsvr
mongod --dbpath ${dbpath}/config2/db --logpath ${dbpath}/config2/mongod.log --port 27022 --fork --keyFile ${dbpath}/keyfile --configsvr
mongod --dbpath ${dbpath}/config3/db --logpath ${dbpath}/config3/mongod.log --port 27023 --fork --keyFile ${dbpath}/keyfile --configsvr
mongos --logpath ${dbpath}/mongos.log --configdb ${hn}:27021,${hn}:27022,${hn}:27023 --keyFile ${dbpath}/keyfile --fork
mongo --eval "sh.addShard('${hn}:27018'); sh.addShard('${hn}:27019'); sh.addShard('${hn}:27020')"
@slyang-git
Copy link

Hi, Akira Kurogane, thank you for your time to answer my question in StactOverflow. The log file mongos.log in the mongos's log path, showed the reason for that error.

warning: Error while attempting to acquire distributed lock for user modification: 
could not acquire distributed lock authorizationData for Create user after 5s, 
other lock may be held: { _id: "authorizationData", state: 2, who: "1    0.171.25.79:27000:1421218318:1804289383:conn4:846930886", 
ts: ObjectId('54b6120ea1760ef176f3b1da'), 
process: "10.171.25.79:27000:1421218318:1804289383", 
when: new Date(1421218318456), why: "Create user" }

But I don't know how to going on with this error message to sovle this problem. Can you give me some suggestions according it? very thankful again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment