MongoDB分片集群搭建

2021-10-23 18:30:08 字數 4111 閱讀 8382

1.搭建環境

​ os:centos7

​ version: 4.2.8(

​ 主機規劃:

sharding role

host

port

replica set

mongos

mongos

37017

/shard1

host1/host2/host3

27117

shard1

shard2

host1/host2/host3

27217

shard2

config

host1/host2/host3

27317

config

2.搭建步驟

​ 2.1 sharding搭建,shard1和2基本步驟一致

​ a. 分片集shard1配置檔案,需要開啟認證登陸時,去掉注釋部分

net

:maxincomingconnections

:20000

bindip

: 0.0.0.0

port

:27117

unixdomainsocket

:enabled

:true

wireobjectcheck

:false

operationprofiling

:slowopthresholdms

:100

processmanagement

:fork

:true

replication

:oplogsizemb

:500

replsetname

: shard1

sharding

:clusterrole

: shardsvr

storage

:dbpath

: /data/mongosvr/shard1/data

directoryperdb

:true

engine

: wiredtiger

journal

:enabled

:true

wiredtiger

:engineconfig

:cachesizegb:1

#security:

# keyfile: /data/mongodb/mongodb.key

# authorization: enabled

systemlog

:destination

: file

:true

path

: /data/mongosvr/shard1/logs/mongodb.log

quiet

:true

traceallexceptions

:false

​ b. 初始化分片集

>var shard1_conf=,,]

};>rs.initiate(shard2_conf);

​ 2.2 config server

​ a. 配置

net

:maxincomingconnections

:20000

bindip

: 0.0.0.0

port

:27317

unixdomainsocket

:enabled

:true

wireobjectcheck

:false

operationprofiling

:slowopthresholdms

:100

processmanagement

:fork

:true

replication

:oplogsizemb

:500

replsetname

: config

sharding

:clusterrole

: configsvr

storage

:dbpath

: /data/mongosvr/config/data

directoryperdb

:true

engine

: wiredtiger

journal

:enabled

:true

wiredtiger

:engineconfig

:cachesizegb:1

#security:

# keyfile: /data/mongodb/mongodb.key

# authorization: enabled

systemlog

:destination

: file

:true

path

: /data/mongosvr/config/logs/mongodb.log

quiet

:true

traceallexceptions

:false

​ b. 初始化配置伺服器副本集

>var conf=,,]

};>rs.initiate(conf);

​ 2.3 mongos server

​ a. 配置檔案

net

:maxincomingconnections

:20000

bindip

: 0.0.0.0

port

:37017

unixdomainsocket

:enabled

:true

wireobjectcheck

:false

processmanagement

:fork

:true

sharding

:configdb

: config/host1:

27317

,host2:

27317

,host3:

27317

systemlog

:destination

: file

:true

path

: /data/mongos/logs/mongodb.log

quiet

:true

traceallexceptions

:false

​ b. 啟動mongos

./bin/mongos -f conf/mongo.conf
​ 2.4 初始化新增分片集

#./bin/mongo --port 37017

mongos>sh.addshard("shard1/host1:27117,host2:27117,host3:27117");

mongos>sh.addshard("shard2/host1:27217,host2:27217,host3:27217");

mongos>sh.status(); #檢視分片集合狀態,此時集合未做分片處理,databases未顯示

​ 新增測試分片集合

mongos>sh.enablesharding('test');

mongos>sh.shardcollection('test.t1',); #選定id作為分片鍵

mongos>sh.status();

[外鏈轉存失敗,源站可能有防盜煉機制,建議將儲存下來直接上傳

h.enablesharding(『test』);

mongos>sh.shardcollection(『test.t1』,); #選定id作為分片鍵

mongos>sh.status();

[外鏈轉存中...(img-srbh7nbk-1598263655433)]

mongodb 集群搭建 分片 副本集

mkdir p home mongodb conf mkdir p home mongodb mongos log mkdir p home mongodb config data mkdir p home mongodb config log mkdir p home mongodb shard1...

MongoDB集群分片

什麼是sharding?說白了就是把海量資料水平擴充套件的集群系統,資料分表儲存在sharding的各個節點上。mongodb的資料分開分為chunk,每個chunk都是collection中的一段連續的資料記錄,一般為200mb,超出則生成新的資料塊。構建sharding需要三種角色,shard伺...

mongodb分片 集群

目前在乙個機器上部署,ip 10.1.2.197,埠列表如下 埠埠埠路由服務 27061 路由服務 27062 路由服務 27063 配置服務 27071 配置服務 27072 配置服務 27073 副本集1 27011 副本集2 27021 副本集3 27031 副本集1 27012 副本集2 2...