-
-
Save umit/5650813 to your computer and use it in GitHub Desktop.
This file contains 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 characters
#!/bin/bash | |
echo "Make data dirs...." | |
mkdir ~/data | |
mkdir ~/data/config | |
mkdir ~/data/db | |
mkdir ~/data/shard0 | |
mkdir ~/data/shard0/rs0 | |
mkdir ~/data/shard0/rs1 | |
mkdir ~/data/shard0/rs2 | |
mkdir ~/data/shard1 | |
mkdir ~/data/shard1/rs0 | |
mkdir ~/data/shard1/rs1 | |
mkdir ~/data/shard1/rs2 | |
mkdir ~/data/logs | |
echo "Successfully create.\n" | |
echo "Starting replica set 1 ..." | |
mongod --replSet s0 --logpath ~/data/logs/s0-r0.log --dbpath ~/data/shard0/rs0 --port 37017 --fork --shardsvr | |
mongod --replSet s0 --logpath ~/data/logs/s0-r1.log --dbpath ~/data/shard0/rs1 --port 37018 --fork --shardsvr | |
mongod --replSet s0 --logpath ~/data/logs/s0-r1.log --dbpath ~/data/shard0/rs2 --port 37019 --fork --shardsvr | |
mongo --port 37017 << EOF | |
config = { _id : "s0", members : [ | |
{_id : 0, host: "127.0.0.1:37017"}, | |
{_id : 1, host: "127.0.0.1:37018"}, | |
{_id : 2, host: "127.0.0.1:37019"} | |
] | |
} | |
rs.initiate(config) | |
EOF | |
echo "Starting replica set 2 ..." | |
mongod --replSet s1 --logpath ~/data/logs/s1-r0.log --dbpath ~/data/shard1/rs0 --port 47017 --fork --shardsvr | |
mongod --replSet s1 --logpath ~/data/logs/s1-r1.log --dbpath ~/data/shard1/rs1 --port 47018 --fork --shardsvr | |
mongod --replSet s1 --logpath ~/data/logs/s1-r1.log --dbpath ~/data/shard1/rs2 --port 47019 --fork --shardsvr | |
mongo --port 47017 << 'EOF' | |
config = { _id : "s1", members : [ | |
{_id : 0, host: "127.0.0.1:47017"}, | |
{_id : 1, host: "127.0.0.1:47018"}, | |
{_id : 2, host: "127.0.0.1:47019"} | |
] | |
}; | |
rs.initiate(config); | |
EOF | |
echo "Starting config servers ..." | |
mkdir -p ~/data/config/config-a ~/data/config/config-b ~/data/config/config-c | |
mongod --logpath ~/data/logs/cfg-a.log --dbpath ~/data/config/config-a --port 57017 --fork --configsvr | |
mongod --logpath ~/data/logs/cfg-b.log --dbpath ~/data/config/config-b --port 57018 --fork --configsvr | |
mongod --logpath ~/data/logs/cfg-c.log --dbpath ~/data/config/config-c --port 57019 --fork --configsvr | |
echo "Start mongos..." | |
mongos --logpath ~/data/logs/mongos.log --configdb 127.0.0.1:57017,127.0.0.1:57018,127.0.0.1:57019 --fork | |
echo "Add shard and enable sharding on the test db" | |
mongo << 'EOF' | |
db.adminCommand({addshard : "s0/127.0.0.1:37017"}); | |
db.adminCommand({addshard : "s1/127.0.0.1:47017"}); | |
db.adminCommand({enableSharding : "test"}); | |
db.adminCommand({shardCollection : "test.users", key: {student_id : 1}}); | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment