Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- ps aux | grep mongod | awk '{print $2}' | xargs kill -9
- ps aux | grep mongos | awk '{print $2}' | xargs kill -9
- data=~/cluster
- opts="--fork --storageEngine wiredTiger"
- mopts="$opts --shardsvr"
- rm -rf $data/config/*
- rm -rf $data/shard0/*
- rm -rf $data/shard1/*
- rm -rf $data/shard2/*
- mkdir -p $data/config/c0
- mkdir -p $data/config/c1
- mkdir -p $data/config/c2
- mkdir -p $data/shard0/m0
- mkdir -p $data/shard0/m1
- mkdir -p $data/shard0/arb
- mkdir -p $data/shard1/m0
- mkdir -p $data/shard1/m1
- mkdir -p $data/shard1/arb
- mkdir -p $data/shard2/m0
- mkdir -p $data/shard2/m1
- mkdir -p $data/shard2/arb
- mkdir -p $data/mongos
- mongod --replSet shard0 $mopts --dbpath $data/shard0/m0 --logpath $data/shard0/m0/mongod.log --port 27107
- mongod --replSet shard0 $mopts --dbpath $data/shard0/m1 --logpath $data/shard0/m1/mongod.log --port 27108
- mongod --replSet shard0 $mopts --dbpath $data/shard0/arb --logpath $data/shard0/arb/mongod.log --port 27109
- mongod --replSet shard1 $mopts --dbpath $data/shard1/m0 --logpath $data/shard1/m0/mongod.log --port 27117
- mongod --replSet shard1 $mopts --dbpath $data/shard1/m1 --logpath $data/shard1/m1/mongod.log --port 27118
- mongod --replSet shard1 $mopts --dbpath $data/shard1/arb --logpath $data/shard1/arb/mongod.log --port 27119
- mongod --replSet shard2 $mopts --dbpath $data/shard2/m0 --logpath $data/shard2/m0/mongod.log --port 27127
- mongod --replSet shard2 $mopts --dbpath $data/shard2/m1 --logpath $data/shard2/m1/mongod.log --port 27128
- mongod --replSet shard2 $mopts --dbpath $data/shard2/arb --logpath $data/shard2/arb/mongod.log --port 27129
- mongod $opts --dbpath $data/config/c0 --logpath $data/config/c0/mongod.log --port 27227 --configsvr --replSet csrs0
- mongod $opts --dbpath $data/config/c1 --logpath $data/config/c1/mongod.log --port 27228 --configsvr --replSet csrs0
- mongod $opts --dbpath $data/config/c2 --logpath $data/config/c2/mongod.log --port 27229 --configsvr --replSet csrs0
- sleep 10
- echo "cfg = {'_id': 'csrs0', \
- 'members': [{'_id' : 0, 'host' : 'localhost:27227'}, \
- {'_id': 1, 'host': 'localhost:27228' }, \
- {'_id': 2, 'host': 'localhost:27229'}]};
- rs.initiate(cfg);" | mongo --port 27227
- echo "cfg = {'_id': 'shard0', 'version': 1, \
- 'members': [{'_id' : 0, 'host' : 'localhost:27107'}, \
- {'_id': 1, 'host': 'localhost:27108' }, \
- {'_id': 2, 'host': 'localhost:27109', 'arbiterOnly': true}]};
- rs.initiate(cfg);" | mongo --port 27107
- echo "cfg = {'_id': 'shard1', 'version': 1, \
- 'members': [{'_id' : 0, 'host' : 'localhost:27117'}, \
- {'_id': 1, 'host': 'localhost:27118' }, \
- {'_id': 2, 'host': 'localhost:27119', 'arbiterOnly': true}]};
- rs.initiate(cfg);" | mongo --port 27117
- echo "cfg = {'_id': 'shard2', 'version': 1, \
- 'members': [{'_id' : 0, 'host' : 'localhost:27127'}, \
- {'_id': 1, 'host': 'localhost:27128' }, \
- {'_id': 2, 'host': 'localhost:27129', 'arbiterOnly': true}]};
- rs.initiate(cfg);" | mongo --port 27127
- sleep 10
- mongos --logpath $data/mongos/mongos.log --fork --port 27017 --configdb csrs0/localhost:27227,localhost:27228,localhost:27229
- echo "Waiting for replica sets to initialize..."
- sleep 10
- echo 'sh.addShard("shard0/localhost:27107");sh.addShard("shard1/localhost:27117");sh.addShard("shard2/localhost:27127");sh.status()' | mongo
- #echo 'sh.addShard("shard0/localhost:27107");sh.status()' | mongo
- echo "DONE"
Add Comment
Please, Sign In to add comment