標籤:mongodb 分區 複製集
1. 主從主節點開啟rest,工作在主模式,開啟http管理介面,開啟安全控制:mongod.exe --install --rest --master --httpinterface --auth --dbpath e:\mongodb\db --logpath e:\mongodb\log\log.txt --logappend
從節點
主節點地址192.168.117.1:mongod.exe --install --rest --slave --source 192.168.117.1 --autoresync --httpinterface --auth --dbpath d:\mongodb\db --logpath d:\mongodb\log\log.txt --logappend
2. 複製集設定節點(1) 設定節點0:mongod.exe --install --serviceName MongoDB-rs1-0 --serviceDisplayName MongoDB-rs1-0 --httpinterface --rest --replSet rs1 --dbpath e:\mongodb\db\rs1-0 --logpath e:\mongodb\log\log-rs1-0.txt --logappend
(2) 設定節點1:mongod.exe --install --port 27018 --serviceName MongoDB-rs1-1 --serviceDisplayName MongoDB-rs1-1 --httpinterface --rest --replSet rs1 --dbpath e:\mongodb\db\rs1-1 --logpath e:\mongodb\log\log-rs1-1.txt --logappend
配置複製集在mongo shell中執行:config_rs1 = {_id:‘rs1‘, members: [ {_id:0, host:‘localhost:27017‘, priority:1}, {_id:1, host:‘localhost:27018‘} ]};rs.initiate(config_rs1)
複製集狀態rs.status()
添加節點(1) 複製目錄e:\mongodb\db\rs1-1為e:\mongodb\db\rs1-2
(2) mongod.exe --install --port 27019 --serviceName MongoDB-rs1-2 --serviceDisplayName MongoDB-rs1-2 --httpinterface --rest --replSet rs1 --dbpath e:\mongodb\db\rs1-2 --logpath e:\mongodb\log\log-rs1-2.txt --logappend --fastsync
(3) mongo shell中串連到ns1-0,並執行rs.add(“localhost:27019”)
3. 分區和複製集這裡建立兩個分區,每個分區包含兩個分布式節點的複製集,如下表所示:
|
192.168.117.1 |
192.168.117.129 |
192.168.117.130 |
複製集rs1 |
27017 |
27017 |
27017 |
複製集rs2 |
27018 |
27018 |
27018 |
佈建服務 |
37017 |
37017 |
37017 |
路由進程 |
47017 |
-- |
-- |
設定複製集(1) 建立複製集rs1a) 在192.168.117.1設定複製集rs1: mongod.exe --install --serviceName MongoDB-rs1-0 --serviceDisplayName MongoDB-rs1-0 --httpinterface --rest --replSet rs1 --dbpath e:\mongodb\db\rs1-0 --logpath e:\mongodb\log\log-rs1-0.txt --logappend
b) 在192.168.117.129上設定複製集rs1: mongod.exe --install --serviceName MongoDB-rs1-1 --serviceDisplayName MongoDB-rs1-1 --httpinterface --rest --replSet rs1 --dbpath e:\mongodb\db\rs1-1 --logpath e:\mongodb\log\log-rs1-1.txt --logappend
c) 在192.168.117.130上設定複製集rs1: mongod.exe --install --serviceName MongoDB-rs1-2 --serviceDisplayName MongoDB-rs1-2 --httpinterface --rest --replSet rs1 --dbpath e:\mongodb\db\rs1-2 --logpath e:\mongodb\log\log-rs1-2.txt --logappend
(2) 建立複製集rs2a) 在192.168.117.1設定複製集rs2: mongod.exe --install --port 27018 --serviceName MongoDB-rs2-0 --serviceDisplayName MongoDB-rs2-0 --httpinterface --rest --replSet rs2 --dbpath e:\mongodb\db\rs2-0 --logpath e:\mongodb\log\log-rs2-0.txt --logappend
b) 在192.168.117.129設定複製集合rs2: mongod.exe --install --port 27018 --serviceName MongoDB-rs2-1 --serviceDisplayName MongoDB-rs2-1 --httpinterface --rest --replSet rs2 --dbpath e:\mongodb\db\rs2-1 --logpath e:\mongodb\log\log-rs2-1.txt --logappend
c) 在192.168.117.130設定複製集合rs2: mongod.exe --install --port 27018 --serviceName MongoDB-rs2-2 --serviceDisplayName MongoDB-rs2-2 --httpinterface --rest --replSet rs2 --dbpath e:\mongodb\db\rs2-2 --logpath e:\mongodb\log\log-rs2-2.txt --logappend
(3) 配置rs1
mongo shell串連到192.168.117.1:27017,執行:rs.initiate({_id:‘rs1‘, members:[{_id:0, host:‘192.168.117.1:27017‘, priority:1}, {_id:1,host:‘192.168.117.129:27017‘}, {_id:2,host:‘192.168.117.130:27017‘}]})
(4) 配置rs2
mongo shell串連到192.168.117.1:27018,執行:rs.initiate({_id:‘rs2‘, members:[{_id:0, host:‘192.168.117.1:27018‘, priority:1}, {_id:1,host:‘192.168.117.129:27018‘}, {_id:2,host:‘192.168.117.130:27018‘}]})
(5) 在瀏覽器中查看複製集rs1資訊
http://192.168.117.1:28017/_replSet
設定設定管理員(1) 在192.168.117.1/129/130上執行:mongod --configsvr --install --serviceName MongoDB-cfg --serviceDisplayName MongoDB-cfg --httpinterface --rest --dbpath e:\mongodb\config --port 37017 --logpath e:\mongodb\log\log-cfg.txt --logappend
設定路由進程(1) 在192.168.117.1上執行:mongos --configdb 192.168.117.1:37017,192.168.117.129:37017,192.168.117.130:37017 --install --port 47017 --serviceName MongoDB-rp --serviceDisplayName MongoDB-rp --chunkSize 1 --httpinterface --logpath e:\mongodb\log\log-rp.txt --logappend
設定分區叢集(1) 串連到路由進程mongo 192.168.117.1:47017
(2) use admin
(3) db.runCommand({addshard:"rs1/192.168.117.1:27017,192.168.117.129:27017,192.168.117.130:27017"})
(4) db.runCommand({addshard:"rs2/192.168.117.1:27018,192.168.117.129:27018,192.168.117.130:27018"})
(5) 為192.168.117.1:27018添加資料庫meta_search
(6) 啟用資料庫分區:db.runCommand({enablesharding:"meta_search" })
(7) 啟用集合分區:先建立wincc集合,然後運行命令db.runCommand({shardcollection: "meta_search.wincc", key:{ _id:1 }})。查看集合分區組態,出現如下資訊表示分區成功
(8) MogoVUE中看到的叢集架構:
(9) 查看叢集分區狀態。可以看到meta_search的partitioned為true,表示分區功能已經開啟;primary表示這個資料庫的“大本營“在哪裡,不論分區與否,資料庫總是會有個“大本營”,建立資料庫時會隨機播放一個片,也就是說大本營是開始建立資料庫檔案的位置,可以看出meta_search的大本營在rs2複製集。還可以看出分區中有兩個複製集rs1和rs2,並且複製集的三個節點是分布在三個主機上的。
4. 注意By default, the size of the oplog is as follows:
? For 64-bit Linux, Solaris, FreeBSD, and Windows systems, MongoDB allocates 5% of the available free disk
space, but will always allocate at least 1 gigabyte and never more than 50 gigabytes.
? For 64-bit OS X systems, MongoDB allocates 183 megabytes of space to the oplog.
? For 32-bit systems, MongoDB allocates about 48 megabytes of space to the oplog.
轉載請註明:http://blog.csdn.net/fragmentalice/article/details/43304007
MongoDB Windows配置手冊