Add a shard replica set when MongoDB is running

Source: Internet
Author: User
Based on the cluster configuration of quot; Mongodb cluster (shardingwithreplicaset) quot;, try to dynamically Add a shard replica set when the Mongodb cluster is running.

Based on the cluster of quot; Mongodb cluster configuration (sharding with replica set) quot;, try to dynamically Add a shard replica set when the Mongodb cluster is running.

Based on the "Mongodb cluster configuration (sharding with replica set)" cluster (SEE), try to dynamically Add a shard replica set when the Mongodb cluster is running.

(1) Start the replica set Node

Execute the following three batch files to start three Mongod processes, 127.0.0.1: 36000, 127.0.0.1: 36001, and 127.0.0.1: 36002.

Batch File startShardD_0.bat:

Cd d:/mongodb-win32-i386-1.8.0/bin
Call mongod.exe -- logpath d:/mongodb-win32-i386-1.8.0/logs/d/r0.log -- logappend -- dbpath d: /mongodb-win32-i386-1.8.0/data/d/r0 -- port 36000 -- shardsvr -- replSet setD -- rest -- oplogSize 64

Batch File startShardD_1.bat:

Cd d:/mongodb-win32-i386-1.8.0/bin
Call mongod.exe -- logpath d:/mongodb-win32-i386-1.8.0/logs/d/r1.log -- logappend -- dbpath d: /mongodb-win32-i386-1.8.0/data/d/r1 -- port 36001 -- shardsvr -- replSet setD -- rest -- oplogSize 64

Batch File startShardD_2.bat:

Cd d:/mongodb-win32-i386-1.8.0/bin
Call mongod.exe -- logpath d:/mongodb-win32-i386-1.8.0/logs/d/r2.log -- logappend -- dbpath d: /mongodb-win32-i386-1.8.0/data/d/r2 -- port 36002 -- shardsvr -- replSet setD -- rest -- oplogSize 64

(2) configure the replica set
D:/mongodb-win32-i386-1.8.0/cmd> cd d:/mongodb-win32-i386-1.8.0/bin

D:/mongodb-win32-i386-1.8.0/bin> call cmd.exe 127.0.0.1: 36000/admin
MongoDB shell version: 1.8.0
Connecting to: 127.0.0.1: 36000/admin
> Cfg = {_ id: 'setd', members :[
{_ Id: 0, host: '2017. 0.0.1: 100 '},
{_ Id: 1, host: '2017. 0.0.1: 100 '},
{_ Id: 2, host: '2017. 0.0.1: 100 '}...
]};
{
"_ Id": "setD ",
"Members ":[
{
"_ Id": 0,
"Host": "127.0.0.1: 36000"
},
{
"_ Id": 1,
"Host": "127.0.0.1: 36001"
},
{
"_ Id": 2,
"Host": "127.0.0.1: 36002"
}
]
}
> Rs. initiate (cfg)
{
"Info": "Config now saved locally. shocould come online in about a minute .",
"OK": 1
}
>

(3) Add to cluster

Cd d:/mongodb-win32-i386-1.8.0/bin
Call cmd.exe 127.0.0.1: 50000/admin

> Db. runCommand ({addshard: 'setd/127.0.0.1: 36000,127.0 .0.1: 36001,127.0 .0.1: 36002 '})
{"ShardAdded": "setD", "OK": 1}

(4) view Cluster partition information

> Db. printShardingStatus ()
--- Sharding Status ---
Sharding version: {"_ id": 1, "version": 3}
Shards:
{
"_ Id": "ShardSetA ",
"Host": "setA/127.0.0.1: 10000,127.0 .0.1: 10001,127.0 .0.1: 10002"
}
{
"_ Id": "ShardSetB ",
"Host": "setB/127.0.0.1: 20000,127.0 .0.1: 20001,127.0 .0.1: 20002"
}
{
"_ Id": "ShardSetC ",
"Host": "setC/127.0.0.1: 30000,127.0 .0.1: 30001,127.0 .0.1: 30002"
}
{
"_ Id": "setD ",
"Host": "setD/127.0.0.1: 36000,127.0 .0.1: 36001,127.0 .0.1: 36002"
}
Databases:
{"_ Id": "admin", "partitioned": false, "primary": "config "}
{"_ Id": "wlb", "partitioned": true, "primary": "ShardSetA "}
Wlb. wlb_orders chunks:
ShardSetB 5
ShardSetA 4
ShardSetC 5
{"Order_id" :{$ minKey: 1 }}-- >>{ "order_id": NumberLong (1)} on: ShardSetB {"t": 5000, "I ": 1}
{"Order_id": NumberLong (1)} -- >>{ "order_id": NumberLong (19943)} on: ShardSetA {"t": 8000, "I": 1}
{"Order_id": NumberLong (19943)} -- >>{ "order_id": NumberLong (37015)} on: ShardSetC {"t": 7000, "I": 1}
{"Order_id": NumberLong (37015)} -- >>{ "order_id": NumberLong (54080)} on: ShardSetB {"t": 4000, "I": 2}
{"Order_id": NumberLong (54080)} -- >>{ "order_id": NumberLong (71148)} on: ShardSetB {"t": 4000, "I": 4}
{"Order_id": NumberLong (71148)} -- >>{ "order_id": NumberLong (88201)} on: ShardSetA {"t": 5000, "I": 2}
{"Order_id": NumberLong (88201)} -- >>{ "order_id": NumberLong (105259)} on: ShardSetC {"t": 6000, "I": 2}
{"Order_id": NumberLong (105259)} -- >>{ "order_id": NumberLong (122284)} on: ShardSetC {"t": 6000, "I": 4}
{"Order_id": NumberLong (122284)} -- >>{ "order_id": NumberLong (139303)} on: ShardSetC {"t": 6000, "I": 6}
{"Order_id": NumberLong (139303)} -- >>{ "order_id": NumberLong (173354)} on: ShardSetC {"t": 6000, "I": 8}
{"Order_id": NumberLong (173354)} -- >>{ "order_id": NumberLong (207403)} on: ShardSetA {"t": 7000, "I": 2}
{"Order_id": NumberLong (207403)} -- >>{ "order_id": NumberLong (241449)} on: ShardSetA {"t": 7000, "I": 4}
{"Order_id": NumberLong (241449)} -- >>{ "order_id": NumberLong (275497)} on: ShardSetB {"t": 8000, "I": 2}
{"Order_id": NumberLong (275497)} -- >>{ "order_id" :{$ maxKey: 1 }}on: ShardSetB {"t": 8000, "I ": 3}
{"_ Id": "adimin", "partitioned": false, "primary": "ShardSetA "}

Now, the replica set setD is added to the cluster as a shard.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.