Guest User

Untitled

a guest
Jul 19th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. ps aux | grep mongod | awk '{print $2}' | xargs kill -9
  4. ps aux | grep mongos | awk '{print $2}' | xargs kill -9
  5.  
  6. data=~/cluster
  7. opts="--fork --storageEngine wiredTiger"
  8. mopts="$opts --shardsvr"
  9.  
  10. rm -rf $data/config/*
  11. rm -rf $data/shard0/*
  12. rm -rf $data/shard1/*
  13. rm -rf $data/shard2/*
  14.  
  15. mkdir -p $data/config/c0
  16. mkdir -p $data/config/c1
  17. mkdir -p $data/config/c2
  18.  
  19. mkdir -p $data/shard0/m0
  20. mkdir -p $data/shard0/m1
  21. mkdir -p $data/shard0/arb
  22.  
  23. mkdir -p $data/shard1/m0
  24. mkdir -p $data/shard1/m1
  25. mkdir -p $data/shard1/arb
  26.  
  27. mkdir -p $data/shard2/m0
  28. mkdir -p $data/shard2/m1
  29. mkdir -p $data/shard2/arb
  30.  
  31. mkdir -p $data/mongos
  32.  
  33. mongod --replSet shard0 $mopts --dbpath $data/shard0/m0 --logpath $data/shard0/m0/mongod.log --port 27107
  34. mongod --replSet shard0 $mopts --dbpath $data/shard0/m1 --logpath $data/shard0/m1/mongod.log --port 27108
  35. mongod --replSet shard0 $mopts --dbpath $data/shard0/arb --logpath $data/shard0/arb/mongod.log --port 27109
  36.  
  37. mongod --replSet shard1 $mopts --dbpath $data/shard1/m0 --logpath $data/shard1/m0/mongod.log --port 27117
  38. mongod --replSet shard1 $mopts --dbpath $data/shard1/m1 --logpath $data/shard1/m1/mongod.log --port 27118
  39. mongod --replSet shard1 $mopts --dbpath $data/shard1/arb --logpath $data/shard1/arb/mongod.log --port 27119
  40.  
  41. mongod --replSet shard2 $mopts --dbpath $data/shard2/m0 --logpath $data/shard2/m0/mongod.log --port 27127
  42. mongod --replSet shard2 $mopts --dbpath $data/shard2/m1 --logpath $data/shard2/m1/mongod.log --port 27128
  43. mongod --replSet shard2 $mopts --dbpath $data/shard2/arb --logpath $data/shard2/arb/mongod.log --port 27129
  44.  
  45. mongod $opts --dbpath $data/config/c0 --logpath $data/config/c0/mongod.log --port 27227 --configsvr --replSet csrs0
  46. mongod $opts --dbpath $data/config/c1 --logpath $data/config/c1/mongod.log --port 27228 --configsvr --replSet csrs0
  47. mongod $opts --dbpath $data/config/c2 --logpath $data/config/c2/mongod.log --port 27229 --configsvr --replSet csrs0
  48.  
  49. sleep 10
  50.  
  51. echo "cfg = {'_id': 'csrs0', \
  52. 'members': [{'_id' : 0, 'host' : 'localhost:27227'}, \
  53. {'_id': 1, 'host': 'localhost:27228' }, \
  54. {'_id': 2, 'host': 'localhost:27229'}]};
  55. rs.initiate(cfg);" | mongo --port 27227
  56.  
  57. echo "cfg = {'_id': 'shard0', 'version': 1, \
  58. 'members': [{'_id' : 0, 'host' : 'localhost:27107'}, \
  59. {'_id': 1, 'host': 'localhost:27108' }, \
  60. {'_id': 2, 'host': 'localhost:27109', 'arbiterOnly': true}]};
  61. rs.initiate(cfg);" | mongo --port 27107
  62.  
  63. echo "cfg = {'_id': 'shard1', 'version': 1, \
  64. 'members': [{'_id' : 0, 'host' : 'localhost:27117'}, \
  65. {'_id': 1, 'host': 'localhost:27118' }, \
  66. {'_id': 2, 'host': 'localhost:27119', 'arbiterOnly': true}]};
  67. rs.initiate(cfg);" | mongo --port 27117
  68.  
  69. echo "cfg = {'_id': 'shard2', 'version': 1, \
  70. 'members': [{'_id' : 0, 'host' : 'localhost:27127'}, \
  71. {'_id': 1, 'host': 'localhost:27128' }, \
  72. {'_id': 2, 'host': 'localhost:27129', 'arbiterOnly': true}]};
  73. rs.initiate(cfg);" | mongo --port 27127
  74.  
  75. sleep 10
  76. mongos --logpath $data/mongos/mongos.log --fork --port 27017 --configdb csrs0/localhost:27227,localhost:27228,localhost:27229
  77.  
  78. echo "Waiting for replica sets to initialize..."
  79. sleep 10
  80.  
  81. echo 'sh.addShard("shard0/localhost:27107");sh.addShard("shard1/localhost:27117");sh.addShard("shard2/localhost:27127");sh.status()' | mongo
  82.  
  83. #echo 'sh.addShard("shard0/localhost:27107");sh.status()' | mongo
  84.  
  85. echo "DONE"
Add Comment
Please, Sign In to add comment