-
[root@ip-10-1-2-183 etc]# more shard1.conf
-
logpath=/usr/local/MongoDB/logs/mongo_shard1.log
-
logappend=true # need logrotae scripts
-
fork=true
-
journal=true
-
port=27019
-
#vvvvv = true
-
#diaglog = 3
-
dbpath=/usr/local/mongodb/shard1
-
pidfilepath=/usr/local/mongodb/logs/mongo_shard1.pid
-
bind_ip=10.1.2.183
-
replSet=shard1
-
shardsvr=true
/usr/local/mongodb/bin/mongod -f shard1.conf
-
[root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:27019
-
shard1:PRIMARY> rs.add({_id: 3, host: "10.1.2.183:27019"})
-
{
-
"ok" : 1,
-
"operationTime" : Timestamp(1525752728, 3),
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1525752728, 3),
-
"t" : NumberLong(1)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000001")
-
},
-
"$clusterTime" : {
-
"clusterTime" : Timestamp(1525752728, 3),
-
"signature" : {
-
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
-
"keyId" : NumberLong(0)
-
}
-
},
-
"$configServerState" : {
-
"opTime" : {
-
"ts" : Timestamp(1525752728, 2),
-
"t" : NumberLong(1)
-
}
-
}
-
}
-
shard1:PRIMARY> rs.isMaster()
-
{
-
"hosts" : [
-
"10.1.2.32:27019",
-
"10.1.2.68:27019",
-
"10.1.2.175:27019",
-
"10.1.2.183:27019"
-
],
-
"setName" : "shard1",
-
"setVersion" : 4,
-
"ismaster" : true,
-
"secondary" : false,
-
"primary" : "10.1.2.32:27019",
-
"me" : "10.1.2.32:27019",
-
"electionId" : ObjectId("7fffffff0000000000000001"),
-
"lastWrite" : {
-
"opTime" : {
-
"ts" : Timestamp(1525752728, 3),
-
"t" : NumberLong(1)
-
},
-
"lastWriteDate" : ISODate("2018-05-08T04:12:08Z"),
-
"majorityOpTime" : {
-
"ts" : Timestamp(1525752728, 3),
-
"t" : NumberLong(1)
-
},
-
"majorityWriteDate" : ISODate("2018-05-08T04:12:08Z")
-
},
-
"maxBsonObjectSize" : 16777216,
-
"maxMessageSizeBytes" : 48000000,
-
"maxWriteBatchSize" : 100000,
-
"localTime" : ISODate("2018-05-08T04:12:12.282Z"),
-
"logicalSessionTimeoutMinutes" : 30,
-
"minWireVersion" : 0,
-
"maxWireVersion" : 6,
-
"readOnly" : false,
-
"ok" : 1,
-
"operationTime" : Timestamp(1525752728, 3),
-
"$gleStats" : {
-
"lastOpTime" : {
-
"ts" : Timestamp(1525752728, 3),
-
"t" : NumberLong(1)
-
},
-
"electionId" : ObjectId("7fffffff0000000000000001")
-
},
-
"$clusterTime" : {
-
"clusterTime" : Timestamp(1525752729, 3),
-
"signature" : {
-
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
-
"keyId" : NumberLong(0)
-
}
-
},
-
"$configServerState" : {
-
"opTime" : {
-
"ts" : Timestamp(1525752729, 3),
-
"t" : NumberLong(1)
-
}
-
}
-
}
-
shard1:PRIMARY> rs.conf()
-
{
-
"_id" : "shard1",
-
"version" : 4,
-
"protocolVersion" : NumberLong(1),
-
"members" : [
-
{
-
"_id" : 0,
-
"host" : "10.1.2.32:27019",
-
"arbiterOnly" : false,
-
"buildIndexes" : true,
-
"hidden" : false,
-
"priority" : 1,
-
"tags" : {
-
-
},
-
"slaveDelay" : NumberLong(0),
-
"votes" : 1
-
},
-
{
-
"_id" : 1,
-
"host" : "10.1.2.68:27019",
-
"arbiterOnly" : false,
-
"buildIndexes" : true,
-
"hidden" : false,
-
"priority" : 1,
-
"tags" : {
-
-
},
-
"slaveDelay" : NumberLong(0),
-
"votes" : 1
-
},
-
{
-
"_id" : 2,
-
"host" : "10.1.2.175:27019",
-
"arbiterOnly" : false,
-
"buildIndexes" : true,
-
"hidden" : false,
-
"priority" : 1,
-
"tags" : {
-
-
},
-
"slaveDelay" : NumberLong(0),
-
"votes" : 1
-
},
-
{
-
"_id" : 3,
-
"host" : "10.1.2.183:27019",
-
"arbiterOnly" : false,
-
"buildIndexes" : true,
-
"hidden" : false,
-
"priority" : 1,
-
"tags" : {
-
-
},
-
"slaveDelay" : NumberLong(0),
-
"votes" : 1
-
}
-
],
-
"settings" : {
-
"chainingAllowed" : true,
-
"heartbeatIntervalMillis" : 2000,
-
"heartbeatTimeoutSecs" : 10,
-
"electionTimeoutMillis" : 10000,
-
"catchUpTimeoutMillis" : -1,
-
"catchUpTakeoverDelayMillis" : 30000,
-
"getLastErrorModes" : {
-
-
},
-
"getLastErrorDefaults" : {
-
"w" : 1,
-
"wtimeout" : 0
-
},
-
"replicaSetId" : ObjectId("5aeab9557a9235efbe4a9b59")
-
}
-
shard1:PRIMARY> rs.status()
{
"set" : "shard1",
"date" : ISODate("2018-05-08T05:38:35.245Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"readConcernMajorityOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "10.1.2.32:27019",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 425793,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"electionTime" : Timestamp(1525332319, 1),
"electionDate" : ISODate("2018-05-03T07:25:19Z"),
"configVersion" : 4,
"self" : true
},
{
"_id" : 1,
"name" : "10.1.2.68:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 425606,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
"lastHeartbeat" : ISODate("2018-05-08T05:38:34.014Z"),
"lastHeartbeatRecv" : ISODate("2018-05-08T05:38:34.014Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.1.2.32:27019",
"configVersion" : 4
},
{
"_id" : 2,
"name" : "10.1.2.175:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 425606,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
"lastHeartbeat" : ISODate("2018-05-08T05:38:34.014Z"),
"lastHeartbeatRecv" : ISODate("2018-05-08T05:38:34.016Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.1.2.183:27019",
"configVersion" : 4
},
{
"_id" : 3,
"name" : "10.1.2.183:27019",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 5184,
"optime" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1525757907, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2018-05-08T05:38:27Z"),
"optimeDurableDate" : ISODate("2018-05-08T05:38:27Z"),
"lastHeartbeat" : ISODate("2018-05-08T05:38:34.016Z"),
"lastHeartbeatRecv" : ISODate("2018-05-08T05:38:33.567Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.1.2.68:27019",
"configVersion" : 4
}
],
"ok" : 1,
"operationTime" : Timestamp(1525757907, 1),
"$gleStats" : {
"lastOpTime" : Timestamp(0, 0),
"electionId" : ObjectId("7fffffff0000000000000001")
},
"$clusterTime" : {
"clusterTime" : Timestamp(1525757911, 2),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
},
"$configServerState" : {
"opTime" : {
"ts" : Timestamp(1525757911, 2),
"t" : NumberLong(1)
}
}
}
可以看到新的成員已經(jīng)加入復(fù)制集中去了