mongodb複製+分片
1.規劃
角色 主機 埠 資料檔案路徑 日誌檔案路徑
Router localhost 9001 /home/master/data/router1 /home/master/log/router1/router1.log
localhost 9002 /home/master/data/router2 /home/master/log/router2/router2.log
Config Server localhost 10001 /home/master/data/config1 /home/master/log/config1/config1.log
localhost 10002 /home/master/data/config2 /home/master/log/config2/config2.log
localhost 10003 /home/master/data/config3 /home/master/log/config3/config3.log
複製集1(power1) localhost 20001 /home/master/data/power1_01 /home/master/log/power1_01/power1_01.log
localhost 20002 /home/master/data/power1_02 /home/master/log/power1_02/power1_02.log
localhost 20003 /home/master/data/power1_03 /home/master/log/power1_03/power1_03.log
複製集2(power2) localhost 30001 /home/master/data/power2_01 /home/master/log/power2_01/power2_01.log
localhost 30002 /home/master/data/power2_02 /home/master/log/power2_02/power2_02.log
localhost 30003 /home/master/data/power2_03 /home/master/log/power2_03/power2_03.log
2.建立相關目錄
mkdir /home/oracle/data/router1
mkdir /home/oracle/data/router2
mkdir /home/oracle/data/config1
mkdir /home/oracle/data/config2
mkdir /home/oracle/data/config3
mkdir /home/oracle/data/power1_01
mkdir /home/oracle/data/power1_02
mkdir /home/oracle/data/power1_03
mkdir /home/oracle/data/power2_01
mkdir /home/oracle/data/power2_02
mkdir /home/oracle/data/power2_03
mkdir -p /home/oracle/log/router1
mkdir -p /home/oracle/log/router2
mkdir -p /home/oracle/log/config1
mkdir -p /home/oracle/log/config2
mkdir -p /home/oracle/log/config3
mkdir -p /home/oracle/log/power1_01
mkdir -p /home/oracle/log/power1_02
mkdir -p /home/oracle/log/power1_03
mkdir -p /home/oracle/log/power2_01
mkdir -p /home/oracle/log/power2_02
mkdir -p /home/oracle/log/power2_03
3. 部署config server叢集
mongod --configsvr --replSet configset --port 10001 --dbpath /home/oracle/data/config1 --logpath /home/oracle/log/config1/config1.log --fork
mongod --configsvr --replSet configset --port 10002 --dbpath /home/oracle/data/config2 --logpath /home/oracle/log/config2/config2.log --fork
mongod --configsvr --replSet configset --port 10003 --dbpath /home/oracle/data/config3 --logpath /home/oracle/log/config3/config3.log --fork
--初始化叢集:
rs.initiate( {
_id: "configset",
configsvr: true,
members: [
{ _id: 0, host: "master:10001" },
{ _id: 1, host: "master:10002" },
{ _id: 2, host: "master:10003" }
]
} )
4.啟動mongos例項
mongos --configdb configset/master:10001,master:10002,master:10003 --port 9001 --logpath /home/oracle/log/router1/router1.log --fork
mongos --configdb configset/master:10001,master:10002,master:10003 --port 9002 --logpath /home/oracle/log/router2/router2.log --fork
5.建立mongodb複製集
---啟動mongodb
mongod --replSet "power1" --dbpath /home/oracle/data/power1_01 --port 20001 --logpath /home/oracle/log/power1_01/power1_01.log --fork
mongod --replSet "power1" --dbpath /home/oracle/data/power1_02 --port 20002 --logpath /home/oracle/log/power1_02/power1_02.log --fork
mongod --replSet "power1" --dbpath /home/oracle/data/power1_03 --port 20003 --logpath /home/oracle/log/power1_03/power1_03.log --fork
mongod --replSet "power2" --dbpath /home/oracle/data/power2_01 --port 30001 --logpath /home/oracle/log/power2_01/power2_01.log --fork
mongod --replSet "power2" --dbpath /home/oracle/data/power2_02 --port 30002 --logpath /home/oracle/log/power2_02/power2_02.log --fork
mongod --replSet "power2" --dbpath /home/oracle/data/power2_03 --port 30003 --logpath /home/oracle/log/power2_03/power2_03.log --fork
mongo master:20001/admin
rs.initiate()
rs.conf()
rs.add("master:20002")
rs.add("master:20003")
rs.status()
mongo master:30001/admin
rs.initiate()
rs.conf()
rs.add("master:30002")
rs.add("master:30003")
6.將複製集加入到分片叢集中
mongo master:9001/admin
sh.addShard("power1/master:20001")
sh.addShard("power2/master:30001")
7.開啟資料庫test分片功能
mongo master:9001/adminn
sh.enableSharding("test")
8.開啟collection的分片功能
1)決定使用什麼作為片鍵。片鍵的選擇會影響分片的效能。
2)如果一個collection已經包含資料,則必須在片鍵的欄位上使用ensureIndex()命令建立一個索引。如果collection是空的,則MongoDB將在sh.shardCollection()階段建立一個索引。
3)通過在mongo shell中執行sh.shardCollection()方法開啟一個collection的分片功能。這個方法的使用語法如下:
db.shardCollection(“<database>.<collection>”, shard-key-pattern)
sh.shardCollection("records.people", { "zipcode": 1, "name": 1 } )
sh.shardCollection("people.addresses", { "state": 1, "_id": 1 } )
sh.shardCollection("assets.chairs", { "type": 1, "_id": 1 } )
sh.shardCollection("test.alerts", { "_id": "hashed" } )
角色 主機 埠 資料檔案路徑 日誌檔案路徑
Router localhost 9001 /home/master/data/router1 /home/master/log/router1/router1.log
localhost 9002 /home/master/data/router2 /home/master/log/router2/router2.log
Config Server localhost 10001 /home/master/data/config1 /home/master/log/config1/config1.log
localhost 10002 /home/master/data/config2 /home/master/log/config2/config2.log
localhost 10003 /home/master/data/config3 /home/master/log/config3/config3.log
複製集1(power1) localhost 20001 /home/master/data/power1_01 /home/master/log/power1_01/power1_01.log
localhost 20002 /home/master/data/power1_02 /home/master/log/power1_02/power1_02.log
localhost 20003 /home/master/data/power1_03 /home/master/log/power1_03/power1_03.log
複製集2(power2) localhost 30001 /home/master/data/power2_01 /home/master/log/power2_01/power2_01.log
localhost 30002 /home/master/data/power2_02 /home/master/log/power2_02/power2_02.log
localhost 30003 /home/master/data/power2_03 /home/master/log/power2_03/power2_03.log
2.建立相關目錄
mkdir /home/oracle/data/router1
mkdir /home/oracle/data/router2
mkdir /home/oracle/data/config1
mkdir /home/oracle/data/config2
mkdir /home/oracle/data/config3
mkdir /home/oracle/data/power1_01
mkdir /home/oracle/data/power1_02
mkdir /home/oracle/data/power1_03
mkdir /home/oracle/data/power2_01
mkdir /home/oracle/data/power2_02
mkdir /home/oracle/data/power2_03
mkdir -p /home/oracle/log/router1
mkdir -p /home/oracle/log/router2
mkdir -p /home/oracle/log/config1
mkdir -p /home/oracle/log/config2
mkdir -p /home/oracle/log/config3
mkdir -p /home/oracle/log/power1_01
mkdir -p /home/oracle/log/power1_02
mkdir -p /home/oracle/log/power1_03
mkdir -p /home/oracle/log/power2_01
mkdir -p /home/oracle/log/power2_02
mkdir -p /home/oracle/log/power2_03
3. 部署config server叢集
mongod --configsvr --replSet configset --port 10001 --dbpath /home/oracle/data/config1 --logpath /home/oracle/log/config1/config1.log --fork
mongod --configsvr --replSet configset --port 10002 --dbpath /home/oracle/data/config2 --logpath /home/oracle/log/config2/config2.log --fork
mongod --configsvr --replSet configset --port 10003 --dbpath /home/oracle/data/config3 --logpath /home/oracle/log/config3/config3.log --fork
--初始化叢集:
rs.initiate( {
_id: "configset",
configsvr: true,
members: [
{ _id: 0, host: "master:10001" },
{ _id: 1, host: "master:10002" },
{ _id: 2, host: "master:10003" }
]
} )
4.啟動mongos例項
mongos --configdb configset/master:10001,master:10002,master:10003 --port 9001 --logpath /home/oracle/log/router1/router1.log --fork
mongos --configdb configset/master:10001,master:10002,master:10003 --port 9002 --logpath /home/oracle/log/router2/router2.log --fork
5.建立mongodb複製集
---啟動mongodb
mongod --replSet "power1" --dbpath /home/oracle/data/power1_01 --port 20001 --logpath /home/oracle/log/power1_01/power1_01.log --fork
mongod --replSet "power1" --dbpath /home/oracle/data/power1_02 --port 20002 --logpath /home/oracle/log/power1_02/power1_02.log --fork
mongod --replSet "power1" --dbpath /home/oracle/data/power1_03 --port 20003 --logpath /home/oracle/log/power1_03/power1_03.log --fork
mongod --replSet "power2" --dbpath /home/oracle/data/power2_01 --port 30001 --logpath /home/oracle/log/power2_01/power2_01.log --fork
mongod --replSet "power2" --dbpath /home/oracle/data/power2_02 --port 30002 --logpath /home/oracle/log/power2_02/power2_02.log --fork
mongod --replSet "power2" --dbpath /home/oracle/data/power2_03 --port 30003 --logpath /home/oracle/log/power2_03/power2_03.log --fork
mongo master:20001/admin
rs.initiate()
rs.conf()
rs.add("master:20002")
rs.add("master:20003")
rs.status()
mongo master:30001/admin
rs.initiate()
rs.conf()
rs.add("master:30002")
rs.add("master:30003")
6.將複製集加入到分片叢集中
mongo master:9001/admin
sh.addShard("power1/master:20001")
sh.addShard("power2/master:30001")
7.開啟資料庫test分片功能
mongo master:9001/adminn
sh.enableSharding("test")
8.開啟collection的分片功能
1)決定使用什麼作為片鍵。片鍵的選擇會影響分片的效能。
2)如果一個collection已經包含資料,則必須在片鍵的欄位上使用ensureIndex()命令建立一個索引。如果collection是空的,則MongoDB將在sh.shardCollection()階段建立一個索引。
3)通過在mongo shell中執行sh.shardCollection()方法開啟一個collection的分片功能。這個方法的使用語法如下:
db.shardCollection(“<database>.<collection>”, shard-key-pattern)
sh.shardCollection("records.people", { "zipcode": 1, "name": 1 } )
sh.shardCollection("people.addresses", { "state": 1, "_id": 1 } )
sh.shardCollection("assets.chairs", { "type": 1, "_id": 1 } )
sh.shardCollection("test.alerts", { "_id": "hashed" } )
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10972173/viewspace-1992985/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【Mongodb】分片加複製集MongoDB
- 【Mongodb】往分片複製集新增複製成員MongoDB
- 【Mongodb】分片複製集環境新增新的分片MongoDB
- MongoDB mongoshake 遷移分片到複製集合MongoDB
- mongodb複製集(replica sets)+分片(sharding)環境搭建MongoDB
- 02 . MongoDB複製集,分片集,備份與恢復MongoDB
- Mongodb主從複製/ 副本集/分片叢集介紹MongoDB
- MySQL Cluster 與 MongoDB 複製群集分片設計及原理MySqlMongoDB
- mongodb複製集MongoDB
- MongoDB分片MongoDB
- MongoDB 搭建複製集MongoDB
- MongoDB複製集原理MongoDB
- MongoDB 複製機制MongoDB
- MongoDB主從複製MongoDB
- mongodb複製集搭建MongoDB
- 【mongodb】mongodb 實現主從複製MongoDB
- 利用Mongodb的複製集搭建高可用分片,Replica Sets + Sharding的搭建過程MongoDB
- MongoDB 分片管理MongoDB
- MongoDB之分片MongoDB
- mongodb分片搭建MongoDB
- mongodb分片balanceMongoDB
- MongoDB學習4:MongoDB複製集機制和原理,搭建複製集MongoDB
- mongodb 分片叢集建立分片集合MongoDB
- MongoDB分片叢集新增分片(自用)MongoDB
- 【Mongodb】 可複製集搭建MongoDB
- 深入淺出MongoDB複製MongoDB
- MongoDB 搭建可複製群集MongoDB
- mongodb之shard分片MongoDB
- MongoDB搭建Replica Set複製集MongoDB
- MongoDB學習之複製集MongoDB
- MongoDB 複製集模式Replica SetsMongoDB模式
- MongoDB 重新同步複製整合員MongoDB
- MongoDB 分片叢集搭建MongoDB
- MongoDB叢集之分片MongoDB
- 搭建MongoDB分片叢集MongoDB
- MongoDB複製集資料同步流程MongoDB
- Mongodb 複製的紐帶–OplogMongoDB
- mongoDB研究筆記:複製集概述MongoDB筆記