mongodb4.0.9版本分片集群搭建

說明

只需要在一個節(jié)點執(zhí)行即可,下載安裝不做描述,主要是配置說明

節(jié)點信息

192.168.1.1 node0
192.168.1.2 node1
192.168.1.3 node2
192.168.1.4 node3
192.168.1.5 node4

分配

config節(jié)點:node2,node3,node4
router節(jié)點:node0,node1
shard節(jié)點:node0,node1,node2,node3,node4

清空數(shù)據(jù)

for ip in 1 2 3 4 5
do
for i in 1 2 3 4 5
do
ssh 192.168.1.$ip "rm -rf /home/mongodb/data/shard$i/*"
done
ssh 192.168.1.$ip "rm -rf /home/mongodb/data/{config,mongos}/*"
done

創(chuàng)建數(shù)據(jù)目錄

for ip in 1 2 3 4 5
do
for i in 1 2 3 4 5
do
ssh 192.168.1.$ip "mkdir -p /home/mongodb/data/shard$i/{data,log}"
done
ssh 192.168.1.$ip "mkdir -p /home/mongodb/data/{config,mongos}/{data,log}"
done

創(chuàng)建config配置

for ip in 3 4 5
do
ssh 192.168.1.$ip "echo '## content
systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/config/log/config.log

# Where and how to store data.
storage:
dbPath: /home/mongodb/data/config/data
journal:
enabled: true
# how the process runs
processManagement:
fork: true
pidFilePath: /home/mongodb/data/config/log/configsrv.pid

# network interfaces
net:
port: 21000
bindIp: 192.168.1.$ip

#operationProfiling:
replication:
replSetName: config

sharding:
clusterRole: configsvr ' > /home/mongodb/config/config.conf "
done

啟動config

for ip in 3 4 5
do
ssh 192.168.1.$ip "/home/mongodb/bin/mongod --config /home/mongodb/config/config.conf"
done

配置config副本集

連接

mongo 192.168.1.3:21000

config變量

config = {
_id : "config",
members : [
{_id : 0, host : "192.168.1.3:21000" },
{_id : 1, host : "192.168.1.4:21000" },
{_id : 2, host : "192.168.1.5:21000" }
]
}

初始化副本集

rs.initiate(config)

查看分區(qū)狀態(tài)

rs.status();

創(chuàng)建shard1

for ip in 1 2 3
do
ssh 192.168.1.$ip "echo '#配置文件內(nèi)容
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/shard1/log/shard1.log

# Where and how to store data.
storage:
dbPath: /home/mongodb/data/shard1/data
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 20

# how the process runs
processManagement:
fork: true
pidFilePath: /home/mongodb/data/shard1/log/shard1.pid

# network interfaces
net:
port: 27001
bindIp: 192.168.1.$ip

#operationProfiling:
replication:
replSetName: shard1
sharding:
clusterRole: shardsvr ' > /home/mongodb/config/shard1.conf"
done

創(chuàng)建shard2

for ip in 2 3 4
do
ssh 192.168.1.$ip "echo '#配置文件內(nèi)容
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/shard2/log/shard2.log

# Where and how to store data.
storage:
dbPath: /home/mongodb/data/shard2/data
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 20

# how the process runs
processManagement:
fork: true
pidFilePath: /home/mongodb/data/shard2/log/shard2.pid

# network interfaces
net:
port: 27002
bindIp: 192.168.1.$ip

#operationProfiling:
replication:
replSetName: shard2
sharding:
clusterRole: shardsvr ' > /home/mongodb/config/shard2.conf"
done

創(chuàng)建shard3

for ip in 3 4 5
do
ssh 192.168.1.$ip "echo '#配置文件內(nèi)容
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/shard3/log/shard3.log

# Where and how to store data.
storage:
dbPath: /home/mongodb/data/shard3/data
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 20

# how the process runs
processManagement:
fork: true
pidFilePath: /home/mongodb/data/shard3/log/shard3.pid

# network interfaces
net:
port: 27003
bindIp: 192.168.1.$ip

#operationProfiling:
replication:
replSetName: shard3
sharding:
clusterRole: shardsvr ' > /home/mongodb/config/shard3.conf"
done

創(chuàng)建shard4

for ip in 4 5 1
do
ssh 192.168.1.$ip "echo '#配置文件內(nèi)容
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/shard4/log/shard4.log

# Where and how to store data.
storage:
dbPath: /home/mongodb/data/shard4/data
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 20

# how the process runs
processManagement:
fork: true
pidFilePath: /home/mongodb/data/shard4/log/shard4.pid

# network interfaces
net:
port: 27004
bindIp: 192.168.1.$ip

#operationProfiling:
replication:
replSetName: shard4
sharding:
clusterRole: shardsvr ' > /home/mongodb/config/shard4.conf"
done

創(chuàng)建shard5

for ip in 5 1 2
do
ssh 192.168.1.$ip "echo '#配置文件內(nèi)容
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/shard5/log/shard5.log

# Where and how to store data.
storage:
dbPath: /home/mongodb/data/shard5/data
journal:
enabled: true
wiredTiger:
engineConfig:
cacheSizeGB: 20

# how the process runs
processManagement:
fork: true
pidFilePath: /home/mongodb/data/shard5/log/shard5.pid

# network interfaces
net:
port: 27005
bindIp: 192.168.1.$ip

#operationProfiling:
replication:
replSetName: shard5
sharding:
clusterRole: shardsvr ' > /home/mongodb/config/shard5.conf"
done

啟動shard

for ip in 1 4 2 3 5
do
for i in 1 2 3 4 5
do
ssh 192.168.1.$ip "/home/mongodb/bin/mongod --config /home/mongodb/config/shard$i.conf"
done
done

配置shard1副本集

連接

mongo 192.168.1.1:27001

config變量

config = {
_id : "shard1",
members : [
{_id : 0, host : "192.168.1.1:27001" },
{_id : 1, host : "192.168.1.2:27001" },
{_id : 2, host : "192.168.1.3:27001" }
]
}

初始化副本集

rs.initiate(config)

查看分區(qū)狀態(tài)

rs.status();

配置shard2副本集

連接

mongo 192.168.1.2:27002

config變量

config = {
_id : "shard2",
members : [
{_id : 0, host : "192.168.1.2:27002" },
{_id : 1, host : "192.168.1.3:27002" },
{_id : 2, host : "192.168.1.4:27002" }
]
}

初始化副本集

rs.initiate(config)

查看分區(qū)狀態(tài)

rs.status();

配置shard3副本集

連接

mongo 192.168.1.3:27003

config變量

config = {
_id : "shard3",
members : [
{_id : 0, host : "192.168.1.3:27003" },
{_id : 1, host : "192.168.1.4:27003" },
{_id : 2, host : "192.168.1.5:27003" }
]
}

初始化副本集

rs.initiate(config)

查看分區(qū)狀態(tài)

rs.status();

配置shard4副本集

連接

mongo 192.168.1.4:27004

config變量

config = {
_id : "shard4",
members : [
{_id : 0, host : "192.168.1.4:27004" },
{_id : 1, host : "192.168.1.5:27004" },
{_id : 2, host : "192.168.1.1:27004" }
]
}

初始化副本集

rs.initiate(config)

查看分區(qū)狀態(tài)

rs.status();

配置shard5副本集

連接

mongo 192.168.1.5:27005

config變量

config = {
_id : "shard5",
members : [
{_id : 0, host : "192.168.1.5:27005" },
{_id : 1, host : "192.168.1.1:27005" },
{_id : 2, host : "192.168.1.2:27005" }
]
}

初始化副本集

rs.initiate(config)

查看分區(qū)狀態(tài)

rs.status();

創(chuàng)建mongos

for ip in 1 2
do
ssh 192.168.1.$ip "echo 'systemLog:
destination: file
logAppend: true
path: /home/mongodb/data/mongos/log/mongos.log
processManagement:
fork: true
# pidFilePath: /home/mongodb/data/mongos/log/mongos.pid

# network interfaces
net:
port: 20000
bindIp: 192.168.1.$ip
#監(jiān)聽的配置服務(wù)器,只能有1個或者3個 configs為配置服務(wù)器的副本集名字
sharding:
configDB: config/192.168.1.3:21000,192.168.1.4:21000,192.168.1.5:21000 ' > /home/mongodb/config/mongos.conf"
done

啟動mongos

for ip in 1 2
do
ssh 192.168.1.$ip "/home/mongodb/bin/mongos --config /home/mongodb/config/mongos.conf"
done

mongo 192.168.1.1:20000

使用admin數(shù)據(jù)庫

use admin

串聯(lián)路由服務(wù)器與分配副本集

sh.addShard("shard1/192.168.1.1:27001,192.168.1.2:27001,192.168.1.3:27001")
sh.addShard("shard2/192.168.1.2:27002,192.168.1.3:27002,192.168.1.4:27002")
sh.addShard("shard3/192.168.1.3:27003,192.168.1.4:27003,192.168.1.5:27003")
sh.addShard("shard4/192.168.1.4:27004,192.168.1.5:27004,192.168.1.1:27004")
sh.addShard("shard5/192.168.1.5:27005,192.168.1.1:27005,192.168.1.2:27005")

查看集群狀態(tài)

sh.status()

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

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

  • 系統(tǒng)版本 Centos7 系統(tǒng)用戶 root MongoDB版本 3.4.2 s...
    IT_小白閱讀 1,273評論 0 1
  • 在這此前建議先了解一下mongo的片鍵概念,結(jié)合自己的業(yè)務(wù)關(guān)系確定一個合適的片鍵,才能更好的發(fā)揮集群的作用。 進(jìn)入...
    繁繁繁閱讀 808評論 0 1
  • 目錄 十一、mongodb分片介紹十二、mongodb分片搭建十三、mongodb分片測試十四、mongodb備份...
    XiaoMing丶閱讀 542評論 0 0
  • 配置服務(wù)器,全部設(shè)置為靜態(tài)地址 轉(zhuǎn)到/home目錄,創(chuàng)建一個mongo目錄用做實驗,我們需要創(chuàng)建如下的目錄層級和空...
    justonlyyo閱讀 1,482評論 0 0
  • 繼女裝大佬圖片分享,割韭菜大佬賣雞湯后,Github又有了新功能:控訴互聯(lián)網(wǎng)公司侵權(quán)行為。在發(fā)布一個小時...
    景峎閱讀 488評論 0 1

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