说明
只需要在一个节点执行即可,下载安装不做描述,主要是配置说明
节点信息
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节点:node2,node3,node4
router节点:node0,node1
shard节点:node0,node1,node2,node3,node4
清空数据
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
创建数据目录
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
创建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)
查看分区状态
rs.status();
创建shard1
for ip in 1 2 3
do
ssh 192.168.1.$ip "echo '#配置文件内容
# 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
创建shard2
for ip in 2 3 4
do
ssh 192.168.1.$ip "echo '#配置文件内容
# 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
创建shard3
for ip in 3 4 5
do
ssh 192.168.1.$ip "echo '#配置文件内容
# 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
创建shard4
for ip in 4 5 1
do
ssh 192.168.1.$ip "echo '#配置文件内容
# 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
创建shard5
for ip in 5 1 2
do
ssh 192.168.1.$ip "echo '#配置文件内容
# 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)
查看分区状态
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)
查看分区状态
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)
查看分区状态
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)
查看分区状态
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)
查看分区状态
rs.status();
创建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
#监听的配置服务器,只能有1个或者3个 configs为配置服务器的副本集名字
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数据库
use admin
串联路由服务器与分配副本集
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")
查看集群状态
sh.status()
网友评论