[root@test1 ~]# mongo test1.lan:37017
MongoDB shell version v3.4.3
connecting to: test1.lan:37017
MongoDB server version: 3.4.3
Server has startup warnings:
2017-04-24T22:59:43.476+0800 I STORAGE [initandlisten]
2017-04-24T22:59:43.476+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine
2017-04-24T22:59:43.476+0800 I STORAGE [initandlisten] ** See
2017-04-24T22:59:44.019+0800 I CONTROL [initandlisten]
> rs.initiate()
{
"info2" : "no configuration specified. Using a default configuration for the set",
"me" : "test1.lan:37017",
"ok" : 1
}
shard-b:SECONDARY>
shard-b:PRIMARY> config = rs.config()
{
"_id" : "shard-b",
"version" : 1,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "test1.lan:37017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 2000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("58fe1465f7a2e985d87b8bf8")
}
}
shard-b:PRIMARY> config.members[0].priority = 2
2
shard-b:PRIMARY> rs.reconfig(config)
{ "ok" : 1 }
shard-b:PRIMARY> rs.add("test2.lan:37017")
{ "ok" : 1 }
shard-b:PRIMARY> rs.add("test3.lan:37017")
{ "ok" : 1 }
shard-b:PRIMARY> rs.isMaster()
{
"hosts" : [
"test1.lan:37017",
"test2.lan:37017",
"test3.lan:37017"
],
"setName" : "shard-b",
"setVersion" : 4,
"ismaster" : true,
"secondary" : false,
"primary" : "test1.lan:37017",
"me" : "test1.lan:37017",
"electionId" : ObjectId("7fffffff0000000000000001"),
"lastWrite" : {
"opTime" : {
"ts" : Timestamp(1493046429, 1),
"t" : NumberLong(1)
},
"lastWriteDate" : ISODate("2017-04-24T15:07:09Z")
},
"maxBsonObjectSize" : 16777216,
"maxMessageSizeBytes" : 48000000,
"maxWriteBatchSize" : 1000,
"localTime" : ISODate("2017-04-24T15:07:24.475Z"),
"maxWireVersion" : 5,
"minWireVersion" : 0,
"readOnly" : false,
"ok" : 1
}
这样 shard-a shard-b 两个副本集已经配置完成