mongodb叢集方式-分區+複本集方式

來源:互聯網
上載者:User

標籤:啟動   ges   png   cto   生產環境   end   日誌   body   部分   

 

分區就是水平的擴充,將資料分拆到不同的機器上,以達到儲存更多的資料,處理更大的負載。可以選定將按照指定的文檔索引值進行分區。

配置

整體部署方案:

啟動三個分區服務,兩個做資料存放區,另一個作為config,

配置分區的複本集,建立管理使用者,關閉mongod,開啟keyfile,啟動mongos,配置分區服務。

角色

分區一般有三個組成部分:

分區服務(Shard Server),mongod 執行個體,2個以上,負責儲存實際的資料分區,生產環境中一個Shard Server可由幾台伺服器組成一個Replica Set代替,避免主機單點故障;
路由服務(Routing Process),mongos執行個體,1個以上,它負責管理分區,用戶端由此前端路由接入,且讓整個叢集看起來像單一資料庫,用戶端應用可以透明使用,Routing Process不儲存資料,資料來自Config Server;

佈建服務(Config Server),mongod 執行個體,1個以上,負責儲存整個叢集的配置資訊:即資料和片的對應關係。

 

因為測試資源有限, 採取三台虛擬機器的方式,

 

分區的架構圖如下:

192.168.100.101所有配置如下:

############config-1############configsvr = truereplSet = configport = 30001dbpath = /opt/mongo/data/config-1logpath = /opt/mongo/logs/config-1.loglogappend = truefork = trueprofile = 1slowms = 500keyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger############route############configdb = config/192.168.100.101:30001,192.168.100.102:30002,192.168.100.103:30003port = 20000logpath = /opt/mongo/logs/route.loglogappend = truefork = true#chunkSize = 256keyFile = /opt/mongo/config/keyfilemaxConns=20000############rs1-1############port = 10001fork = truedbpath = /opt/mongo/data/rs1-1logpath = /opt/mongo/logs/rs1-1.logreplSet = test1logappend = trueprofile = 1slowms = 500directoryperdb = truekeyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger############rs2-a############port = 20003fork = truedbpath = /opt/mongo/data/rs2-alogpath = /opt/mongo/logs/rs2-a.logreplSet = test2logappend = trueprofile = 1slowms = 500directoryperdb = truekeyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger

192.168.100.102所有配置如下:

############config-2############configsvr = truereplSet = configport = 30002dbpath = /opt/mongo/data/config-2logpath = /opt/mongo/logs/config-2.loglogappend = truefork = trueprofile = 1slowms = 500keyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger############route############configdb = config/192.168.100.101:30001,192.168.100.102:30002,192.168.100.103:30003port = 20000logpath = /opt/mongo/logs/route.loglogappend = truefork = true#chunkSize = 256keyFile = /opt/mongo/config/keyfilemaxConns=20000############rs1-2############port = 10002fork = truedbpath = /opt/mongo/data/rs1-2logpath = /opt/mongo/logs/rs1-2.logreplSet = test1logappend = trueprofile = 1slowms = 500directoryperdb = truekeyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger############rs2-2############port = 20002fork = truedbpath = /opt/mongo/data/rs2-2logpath = /opt/mongo/logs/rs2-2.logreplSet = test2logappend = trueprofile = 1slowms = 500directoryperdb = truekeyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger

192.168.100.103所有配置如下:

############config-3############configsvr = truereplSet = configport = 30003dbpath = /opt/mongo/data/config-3logpath = /opt/mongo/logs/config-3.loglogappend = truefork = trueprofile = 1slowms = 500keyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger############route############configdb = config/192.168.100.101:30001,192.168.100.102:30002,192.168.100.103:30003port = 20000logpath = /opt/mongo/logs/route.loglogappend = truefork = true#chunkSize = 256keyFile = /opt/mongo/config/keyfilemaxConns=20000############rs1-a############port = 10003fork = truedbpath = /opt/mongo/data/rs1-alogpath = /opt/mongo/logs/rs1-a.logreplSet = test1logappend = trueprofile = 1slowms = 500directoryperdb = truekeyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger############rs2-1############port = 20001fork = truedbpath = /opt/mongo/data/rs2-1logpath = /opt/mongo/logs/rs2-1.logreplSet = test2logappend = trueprofile = 1slowms = 500directoryperdb = truekeyFile = /opt/mongo/config/keyfilemaxConns=20000storageEngine = wiredTiger

 

openfile 可以使用命令產生:

openssl rand -base64 500 > keyfilechmod 400 keyfile

確保每台機器的keyfile一致

 

依次按照上面設定檔的內容建立設定檔和儲存目錄日誌目錄

建立完成依次啟動所有的mongod節點

注意此時要把keyfile選項注釋掉,否則啟動之後未建立角色就要認證,無法進入操作

ls |grep -v keyfile| xargs sed -i "s/^keyFile/#keyFile/g"

啟動之後依次串連每個分區的主執行以下操作:

>config = {    _id: "test1",    members: [{        _id: 0,        host: "192.168.100.101:10001"    }, {        _id: 1,        host: "192.168.100.102:10002"    }, {        _id: 2,        host: "192.168.100.103:10003",        arbiterOnly: true    }]}>rs.initiate(config)>rs.status()>db.isMaster( )>use admin;>db.createRole({role:"superman", privileges:[{resource:{anyResource: true}, actions:["anyAction"]}], roles:["root"]})>db.createUser({user:"test",pwd:"test",roles:[{role:"superman", db:"admin"}]})

依次執行成功之後,

停止所有的mongod節點:

for i in `seq 10`;do killall mongod ;done

開啟keyfile

ls |grep -v keyfile| xargs sed -i "s/^#keyFile/keyFile/g"

之後依次啟動mongod節點

 

然後啟動mongos節點

串連mongos節點

mongos>use admin;mongos>db.auth("test","test")mongos>sh.addShard("test1/192.168.100.101:10001")mongos>sh.addShard("test2/192.168.100.103:20001")mongos>sh.status()

至此分區配置完成。

mongodb叢集方式-分區+複本集方式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.