基于副本集的分片高可用mongo集群安裝
來自: http://my.oschina.net/shyloveliyi/blog/611058
先上一張拓撲
所有mongo全部安裝到本地(windows)
其中:
分片端口27017
副本1端口27018
仲裁端口27019
路由端口27020
配置端口27021
在各mongo目錄下的bin文件里創建配置文件
#shard.conf dbpath=D:\mongo\shard\mongodb-win32-x86_64-2.6.6\data logpath=D:\mongo\shard\mongodb-win32-x86_64-2.6.6\log\log.log pidfilepath=D:\mongo\shard\mongodb-win32-x86_64-2.6.6\pid\pid.pid directoryperdb=true logappend=true replSet=testrs bind_ip=127.0.0.1 port=27017 oplogSize=10000 noprealloc=true
#slaver.conf dbpath=D:\mongo\shard\slaver\mongodb-win32-x86_64-2.6.6\data logpath=D:\mongo\shard\slaver\mongodb-win32-x86_64-2.6.6\log\log.log pidfilepath=D:\mongo\shard\slaver\mongodb-win32-x86_64-2.6.6\pid\pid.pid directoryperdb=true logappend=true replSet=testrs bind_ip=127.0.0.1 port=27018 oplogSize=10000 noprealloc=true
#arbiter.conf dbpath=D:\mongo\shard\arbiter\mongodb-win32-x86_64-2.6.6\data logpath=D:\mongo\shard\arbiter\mongodb-win32-x86_64-2.6.6\log\log.log pidfilepath=D:\mongo\shard\arbiter\mongodb-win32-x86_64-2.6.6\pid\pid.pid directoryperdb=true logappend=true replSet=testrs bind_ip=127.0.0.1 port=27019 oplogSize=10000 noprealloc=true
#mongos.conf logpath=D:\mongo\mongos\mongodb-win32-x86_64-2.6.6\log\log.log pidfilepath=D:\mongo\mongos\mongodb-win32-x86_64-2.6.6\pid\pid.pid bind_ip=127.0.0.1 port=27020 configdb=127.0.0.1:27021
#mongos.conf dbpath=D:\mongo\config\mongodb-win32-x86_64-2.6.6\data logpath=D:\mongo\config\mongodb-win32-x86_64-2.6.6\log\log.log pidfilepath=D:\mongo\config\mongodb-win32-x86_64-2.6.6\pid\pid.pid bind_ip=127.0.0.1 port=27021
副本:
啟動分片、副本、仲裁
mongod -f 配置文件
連接到分片執行如下操作
use admin cfg={_id:"testrs",members:[{_id:0,host:"127.0.0.1:27017",priority:2},{_id:1,host:"127.0.0.1:27018",priority:1},{_id:2,host:"127.0.0.1:27019",arbiterOnly:true}]};
分片:
啟動配置
mongod -f 配置文件
啟動路由
mongos -f 配置文件
連接路由,使用admin添加分片
use admin db.runCommand({"addShard":"testrs/127.0.0.1:27017"})
開啟分片及設置片鍵
db.runCommand({"enablesharding":"test"}) db.runCommand({"shardcollection":"test.person","key":{_id:'hashed'}})
查看狀態
printShardingStatus() --- Sharding Status --- sharding version: { "_id" : 1, "version" : 4, "minCompatibleVersion" : 4, "currentVersion" : 5, "clusterId" : ObjectId("56a9e3c876c1778c5a28ae2b")} shards: { "_id" : "testrs", "host" : "testrs/127.0.0.1:27017,127.0.0.1:27018" } databases: { "_id" : "admin", "partitioned" : false, "primary" : "config" } { "_id" : "test", "partitioned" : true, "primary" : "testrs" } test.person shard key: { "_id" : "hashed" } chunks: testrs 2 { "_id" : { "$minKey" : 1 } } -->> { "_id" : NumberLong(0) } on : testrs Timestamp(1, 1) { "_id" : NumberLong(0) } -->> { "_id" : { "$maxKey" : 1 } } on : testrs Timestamp(1, 2)
本文由用戶 KryYoon 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!