【Mongodb】分片複製集環境新增新的分片
1.每個節點上分別建立新的shard3配置檔案
2. 每個節點啟動shard3 服務
3.登陸第一個節點,搭建shard3的複製集
4.登陸第一個節點的mongs埠,將shard3分片加入分片組
5、設定均衡器
-
[root@ip-10-1-2-68 etc]# more shard3.conf
-
logpath=/usr/local/mongodb/logs/mongo_shard3.log
-
logappend=true # need logrotae scripts
-
fork=true
-
journal=true
-
port=27017
-
#vvvvv = true
-
#diaglog = 3
-
dbpath=/usr/local/mongodb/shard3
-
pidfilepath=/usr/local/mongodb/logs/mongo_shard3.pid
-
bind_ip=10.1.2.68 ---bind ip 修改為自己的機器
-
replSet=shard3
- shardsvr=true
2. 每個節點啟動shard3 服務
- [root@ip-10-1-2-68 etc]# /usr/local/mongodb/bin/mongod -f shard3.conf
3.登陸第一個節點,搭建shard3的複製集
-
[root@ip-10-1-2-32 etc]# /usr/local/mongodb/bin/mongo 10.1.2.32:27017
-
MongoDB shell version v3.6.4
-
connecting to: mongodb://10.1.2.32:27017/test
-
MongoDB server version: 3.6.4
-
Server has startup warnings:
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten] ** We suggest setting it to 'never'
-
2018-05-08T03:26:23.290+0000 I CONTROL [initandlisten]
-
> config_rs3 = {_id: 'shard3', members: [{_id: 0, host: '10.1.2.32:27017', priority:1}, {_id: 1, host: '10.1.2.68:27017'},{_id: 2, host: '10.1.2.175:27017'}]}
-
{
-
"_id" : "shard3",
-
"members" : [
-
{
-
"_id" : 0,
-
"host" : "10.1.2.32:27017",
-
"priority" : 1
-
},
-
{
-
"_id" : 1,
-
"host" : "10.1.2.68:27017"
-
},
-
{
-
"_id" : 2,
-
"host" : "10.1.2.175:27017"
-
}
-
]
-
}
-
> rs.initiate(config_rs3);
- { "ok" : 1 }
4.登陸第一個節點的mongs埠,將shard3分片加入分片組
-
[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> use admin;
-
switched to db admin
-
mongos> db.runCommand({ addshard: 'shard3/10.1.2.32:27017,10.1.2.68:27017,10.1.2.175:27017'})
-
{
-
"shardAdded" : "shard3",
-
"ok" : 1,
-
"$clusterTime" : {
-
"clusterTime" : Timestamp(1525750332, 7),
-
"signature" : {
-
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
-
"keyId" : NumberLong(0)
-
}
-
},
-
"operationTime" : Timestamp(1525750332, 7)
-
}
-
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.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)
5、設定均衡器
-
# 檢視狀態
-
-
mongos> sh.isBalancerRunning();
-
-
false
-
-
-
-
-
# 設定均衡器
-
-
mongos> sh.setBalancerState(true);
-
-
mongos> sh.enableBalancing("bg")
-
mongos> sh.getBalancerState()
true
-
# 檢視狀態
-
-
mongos> sh.isBalancerRunning();
-
-
false
-
-
-
-
-
# 設定均衡器
-
-
mongos> sh.setBalancerState(true);
-
- mongos> sh.enableBalancing("bg")
-
mongos> sh.getBalancerState()
true
參考:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29096438/viewspace-2154165/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mongodb複製集(replica sets)+分片(sharding)環境搭建MongoDB
- 【Mongodb】往分片複製集新增複製成員MongoDB
- 02 . MongoDB複製集,分片集,備份與恢復MongoDB
- mongodb 分片叢集建立分片集合MongoDB
- MongoDB mongoshake 遷移分片到複製集合MongoDB
- 搭建MongoDB分片叢集MongoDB
- MongoDB 分片叢集搭建MongoDB
- mongodb 分片叢集設定MongoDB
- MongoDB分片叢集常用操作MongoDB
- 高可用mongodb叢集(分片+副本)MongoDB
- MongoDB Sharding(二) -- 搭建分片叢集MongoDB
- 【Mongo】mongo分片加複製集的備份恢復Go
- MongoDB 分片管理MongoDB
- Mongodb分散式叢集副本集+分片MongoDB分散式
- redis叢集之分片叢集的原理和常用代理環境部署Redis
- mongodb之shard分片MongoDB
- linux下Mongodb叢集搭建:分片+副本集LinuxMongoDB
- 【Mongo】單節點升級為複製集再升級為分片加複製集Go
- MongoDB 分片叢集均衡器導致的效能下降MongoDB
- MongoDB 4.2分片叢集搭建及與3.4分片叢集搭建時的一些異同MongoDB
- akka 叢集分片
- 分片叢集元件元件
- 部署分片叢集
- MongoDB分片鍵選擇指南MongoDB
- mongodb分片物理搬遷方案MongoDB
- mongodb複製集MongoDB
- MongoDB 分片鍵的選擇與案例MongoDB
- MongoDB分片叢集節點狀態stateStr:RECOVERING解決MongoDB
- 分散式文件儲存資料庫之MongoDB分片叢集分散式資料庫MongoDB
- MongoDB 搭建複製集MongoDB
- mongodb分片(sharding)搭建、應用及管理MongoDB
- MongoDB4.2 分片掃盲說明MongoDB
- MongoDB學習4:MongoDB複製集機制和原理,搭建複製集MongoDB
- Mongodb叢集搭建一篇就夠了-複製集、分片、帶認證、不帶認證等(帶詳細步驟說明)MongoDB
- GBase XDM(單機/分片叢集)資料庫 新增記錄資料庫
- MongoDB分片群集的部署(用心描述,詳細易懂)!!MongoDB
- 【Mongodb】 可複製集搭建MongoDB
- 分片叢集平衡器Balancer