【Mongodb】往分片複製集新增複製成員
1.新的成員機器上安裝mongo,啟動shard1
/usr/local/mongodb/bin/mongod -f shard1.conf
2.主節點上加入新的複製整合員
3.shard2 config 加成員同理(過程略)
4.檢查是否加入成功
4.最後修改下配置檔案
-
[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
2.主節點上加入新的複製整合員
-
[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)
}
}
}
可以看到新的成員已經加入複製集中去了
3.shard2 config 加成員同理(過程略)
4.檢查是否加入成功
- 登陸mongos埠可以看到
-
[root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:30000
-
MongoDB shell version v3.6.4
-
connecting to: mongodb://10.1.2.32:30000/test
-
MongoDB server version: 3.6.4
-
Server has startup warnings:
-
2018-05-03T07:47:09.379+0000 I CONTROL [main]
-
2018-05-03T07:47:09.379+0000 I CONTROL [main] ** WARNING: Access control is not enabled for the database.
-
2018-05-03T07:47:09.379+0000 I CONTROL [main] ** Read and write access to data and configuration is unrestricted.
-
2018-05-03T07:47:09.379+0000 I CONTROL [main] ** WARNING: You are running this process as the root user, which is not recommended.
-
2018-05-03T07:47:09.379+0000 I CONTROL [main]
-
mongos> db.printShardingStatus();
-
--- Sharding Status ---
-
sharding version: {
-
"_id" : 1,
-
"minCompatibleVersion" : 5,
-
"currentVersion" : 6,
-
"clusterId" : ObjectId("5aeabc4db192a4fefca1c888")
-
}
-
shards:
-
{ "_id" : "shard1", "host" : "shard1/10.1.2.175:27019,10.1.2.183:27019,10.1.2.32:27019,10.1.2.68:27019", "state" : 1 } ---新的複製整合員自動同步到分片資訊了
-
{ "_id" : "shard2", "host" : "shard2/10.1.2.175:27018,10.1.2.32:27018,10.1.2.68:27018", "state" : 1 }
-
{ "_id" : "shard3", "host" : "shard3/10.1.2.175:27017,10.1.2.32:27017,10.1.2.68:27017", "state" : 1 }
-
active mongoses:
-
"3.6.4" : 3
-
autosplit:
-
Currently enabled: yes
-
balancer:
-
Currently enabled: yes
-
Currently running: no
-
Failed balancer rounds in last 5 attempts: 0
-
Migration Results for the last 24 hours:
-
No recent migrations
-
databases:
-
{ "_id" : "config", "primary" : "config", "partitioned" : true }
-
config.system.sessions
-
shard key: { "_id" : 1 }
-
unique: false
-
balancing: true
-
chunks:
-
shard1 1
-
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard1 Timestamp(1, 0)
-
{ "_id" : "test", "primary" : "shard2", "partitioned" : true }
-
test.users
-
shard key: { "_id" : 1 }
-
unique: false
-
balancing: true
-
chunks:
-
shard2 1
-
{ "_id" : { "$minKey" : 1 } } -->> { "_id" : { "$maxKey" : 1 } } on : shard2 Timestamp(1, 0)
-
- mongos> ;
4.最後修改下配置檔案
- 避免重啟問題,寫入配置檔案
-
[root@ip-10-1-2-32 etc]# more mongos.conf
-
logpath=/usr/local/mongodb/logs/mongos.log
-
logappend=true # need logrotae scripts
-
fork=true
-
port=30000
-
pidfilepath=/usr/local/mongodb/logs/mongos.pid
-
configdb=conf/10.1.2.32:27000,10.1.2.68:27000,10.1.2.175:27000,10.1.2.183:27000
- bind_ip=10.1.2.32
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2154171/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Mongodb】分片複製集環境新增新的分片MongoDB
- mongodb複製集MongoDB
- 02 . MongoDB複製集,分片集,備份與恢復MongoDB
- mongodb複製集(replica sets)+分片(sharding)環境搭建MongoDB
- MongoDB 搭建複製集MongoDB
- MongoDB學習4:MongoDB複製集機制和原理,搭建複製集MongoDB
- 【Mongodb】 可複製集搭建MongoDB
- MongoDB mongoshake 遷移分片到複製集合MongoDB
- MongoDB 重新同步複製整合員MongoDB
- MongoDB學習之複製集MongoDB
- MongoDB搭建Replica Set複製集MongoDB
- 【Mongo】單節點升級為複製集再升級為分片加複製集Go
- mongodb6.0.13 搭建複製集PSAMongoDB
- MongoDB複製集資料同步流程MongoDB
- mongodb複製集(replica set)搭建及管理MongoDB
- MongoDB 複製機制MongoDB
- MongoDB原理:複製集狀態同步機制MongoDB
- 【Mongo】mongo分片加複製集的備份恢復Go
- 和麵試官這樣吹MongoDB 複製集!MongoDB
- Mongodb 配置複製集,並啟用安全校驗MongoDB
- 淺複製和深複製的概念與值複製和指標複製(引用複製)有關 淺複製 “指標複製 深複製 值複製指標
- Java引用複製、淺複製、深複製Java
- JS物件複製:深複製和淺複製JS物件
- 不可複製的PDF轉成雙層可複製PDF
- 複製和引用複製
- poi操作excel,複製sheet,複製行,複製單元格,複製styleExcel
- 淺複製與深複製
- MySQL 8 複製(三)——延遲複製與部分複製MySql
- mysql複製--主從複製配置MySql
- python 淺複製、深複製坑Python
- python 深複製和淺複製Python
- JavaScript 淺複製和深複製JavaScript
- 常資料成員的深複製,const+字元型指標 ,如何寫深複製的程式碼?字元指標
- 複製
- js 實現深複製/深複製JS
- MySQL主從複製之GTID複製MySql
- MySQL 8 複製(一)——非同步複製MySql非同步
- MySQL 8 複製(二)——半同步複製MySql