Mongodb adds and removes instances of Shard Server
- 2020-05-13 03:45:38
- OfStack
1. Add a new configuration file and start the mongod instance
#14
mkdir -p /data/mongodb/shard311
./mongod -f /opt/mongodb-linux-x86_64-2.2.0/conf/mongod_3.conf
#16
mkdir -p /data/mongodb/shard32
./mongod -f /opt/mongodb-linux-x86_64-2.2.0/conf/mongod_3.conf
#23
mkdir -p /data/mongodb/shard33
./mongod -f /opt/mongodb-linux-x86_64-2.2.0/conf/mongod_3.conf
Step 2: initialize the set cluster
/opt/mongodb-linux-x86_64-2.2.0/bin/mongo -port 10003
config = {_id: 'shard3', members: [
{_id: 0, host: '192.168.1.14:10003', priority:1},
{_id: 1, host: '192.168.1.16:10003'},
{_id: 2, host: '192.168.1.23:10003'}]};
rs.initiate(config);
3. Increase shard
/opt/mongodb-linux-x86_64-2.2.0/bin/mongo 192.168.1.14:10000/admin
db.runCommand( {
addshard : "shard3/192.168.1.14:10003,192.168.1.16:10003,192.168.1.23:10003",
name:"shard3",
maxsize:20480,
allowLocal:true } );
4. Remove the shard
db.runCommand({"removeshard" : "shard3/192.168.1.14:10003,192.168.1.16:10003,192.168.1.23:10003"});
Note:
The three servers clock are out of sync, which leads to the problem that cannot be shard. Today, I have encountered it again. It will be ok after synchronization. Is this a bit of a frequent problem? Should clock of 3 servers be synchronized at a fixed time every day?
It will take a long time to remove shard, and printShardingStatus() will display the status "draining" : true.