mongodb分片集群搭建

mongo版本:mongodb-linux-x86_64-4.0.16.tgz
三臺(tái)虛擬機(jī)
192.168.150.133 192.168.150.134 192.168.150.135
集群環(huán)境
2個(gè)分片復(fù)制集
shard1(192.168.150.133:27017 192.168.150.134:27017 192.168.150.135:27017)
shard2(192.168.150.133:27018 192.168.150.134:27018 192.168.150.135:27018)
解壓/opt/mongodb目錄下
tar -zxvf mongodb-linux-x86_64-4.0.16.tgz

創(chuàng)建/opt/mongo配置目錄
添加(yidian_repl)復(fù)制集配置文件:mongo.conf (133/134/135)

#守護(hù)進(jìn)程模式
fork = true
##數(shù)據(jù)目錄
dbpath=/opt/mongo/data/db
##端口
port = 27017
bind_ip=0.0.0.0
##日志文件
logpath=/opt/mongo/logs/mongodb1.log
##日志追加
logappend=true
##復(fù)制集的名字
replSet=yidian_repl
smallfiles=true
#分片集群必須要的屬性
shardsvr=true

添加(yidian_repl2)復(fù)制集配置文件:mongo2.conf

 (133/134/135)
#守護(hù)進(jìn)程模式
fork = true
##數(shù)據(jù)目錄
dbpath=/opt/mongo/data/db
##端口
port = 27018
bind_ip=0.0.0.0
##日志文件
logpath=/opt/mongo/logs/mongodb2.log
##日志追加
logappend=true
##復(fù)制集的名字
replSet=yidian_repl2
smallfiles=true
#分片集群必須要的屬性
shardsvr=true

啟動(dòng)副本集(yidian_repl)
/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongod -f /opt/mongo/mongo.conf
啟動(dòng)副本集(yidian_repl2)
/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongod -f /opt/mongo/mongo2.conf

登錄復(fù)制集,添加初始化配置
進(jìn)入mongo客戶端
配置(yidian_repl)
/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongo -port 27017

進(jìn)入27017客戶端后,執(zhí)行初始化命令

var rsconf = { _id:"yidian_repl", members:[

                     {_id:1,host:"192.168.150.133:27017"},

                     {_id:2,host:"192.168.150.134:27017"},

                     {_id:3,host:"192.168.150.135:27017"}

                ]

         }
rs.initiate(rsconf);
rs.status();//查看狀態(tài)

配置(yidian_rep2)
/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongo -port 27018

進(jìn)入27018客戶端后,執(zhí)行初始化命令

var rsconf = { _id:"yidian_repl2", members:[

                     {_id:1,host:"192.168.150.133:27018"},

                     {_id:2,host:"192.168.150.134:27018"},

                     {_id:3,host:"192.168.150.135:27018"}

                ]

         }
rs.initiate(rsconf);

搭建config節(jié)點(diǎn)復(fù)制集

創(chuàng)建config節(jié)點(diǎn)配置文件:mongo-cfg.conf (133/134/135)

    systemLog:
  destination: file
  #日志存儲(chǔ)位置
  path: "/opt/mongo/mongo-cfg/logs/mongodb.log"
  logAppend: true
storage:
  journal:
    enabled: true
  #數(shù)據(jù)文件存儲(chǔ)位置
  dbPath: "/opt/mongo/mongo-cfg/data"
  #是否一個(gè)庫一個(gè)文件夾
  directoryPerDB: true
  #WT引擎配置
  wiredTiger:
    engineConfig:
      #WT最大使用cache(根據(jù)服務(wù)器實(shí)際情況調(diào)節(jié))
      cacheSizeGB: 1
      #是否將索引也按數(shù)據(jù)庫名單獨(dú)存儲(chǔ)
      directoryForIndexes: true
    #表壓縮配置
    collectionConfig:
      blockCompressor: zlib
    #索引配置
    indexConfig:
      prefixCompression: true
#端口配置
net:
  bindIp: 192.168.150.133
  port: 28018
replication:
  oplogSizeMB: 2048
  replSetName: csvr
sharding:
  clusterRole: configsvr
processManagement:
  fork: true

啟動(dòng)配置復(fù)制集
/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongod -f /opt/mongo/mongo-cfg.conf

初始化配置節(jié)點(diǎn)

登錄(任意一臺(tái))

/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongo -host 192.168.133 -port 28018
初始化命令

rs.initiate( {
   _id : "csvr",
   configsvr: true,
   members: [
      { _id: 0, host: "192.168.150.133:28018" },
      { _id: 1, host: "192.168.150.134:28018" },
      { _id: 2, host: "192.168.150.135:28018" }
   ]
   
})

mongos節(jié)點(diǎn)配置
mongos配置文件:mongos.conf

systemLog:
  destination: file
  path: "/opt/mongo/mongos/log/mongos.log"
  logAppend: true
net:
  bindIp: 192.168.150.133
  port: 28017
# 將confige server 添加到路由
sharding:
  configDB: csvr/192.168.150.133:28018,192.168.150.134:28018,192.168.150.135:28018
processManagement:
  fork: true

啟動(dòng)mongos

/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongos -config /opt/mongo/mongos/mongos.conf
登錄mongos節(jié)點(diǎn)
/opt/mongodb/mongodb-linux-x86_64-4.0.16/bin/mongo 192.168.150.133:28017
添加集群中的分片節(jié)點(diǎn)
切換admin:
use admin
添加shard1復(fù)制集
db.runCommand( { addshard : "yidian_repl/192.168.150.133:27017,192.168.150.134:27017,192.168.150.135:27017",name:"shard1"} )
添加shard2復(fù)制集
db.runCommand( { addshard : "yidian_repl2/192.168.150.133:27018,192.168.150.134:27018,192.168.150.135:27018",name:"shard2"} )
mongos查看分片狀態(tài):
sh.status()

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • MongoDb分片集群搭建 基于mongodb3.6 分片集群的權(quán)限控制 Brief: 內(nèi)部通過keyfile控制...
    tufatao閱讀 465評(píng)論 0 3
  • 環(huán)境 服務(wù)器:centOS7 mongodb版本:3.6.2 集群方案:路由服務(wù)器(2臺(tái))+分片服務(wù)器(2個(gè)分片,...
    hello_kd閱讀 1,356評(píng)論 1 4
  • 摘要 本文內(nèi)容基于mongodb4.2.3 本文基于本地安裝,也就是ip相同,端口不同 3個(gè)shard復(fù)制集(3臺(tái)...
    飄逸峰閱讀 1,950評(píng)論 0 4
  • 一、環(huán)境說明: 1、操作系統(tǒng):CentOS Linux release 7.4.1708 2、mongodb版本:...
    張偉科閱讀 1,227評(píng)論 0 1
  • 子曰:“加我數(shù)年,五十以學(xué)《易》,可以無大過矣。” 本章出自:述而篇 【注釋】 ①加:通“假'',給予的意思。 ...
    余余152閱讀 483評(píng)論 1 10

友情鏈接更多精彩內(nèi)容