1、shard cluster 搭建及规划
10个实例端口:38017-38026
-
configserver:3台构成的复制集(1主两从,不支持arbiter)38018-38020
-
shard节点:
sh1:38021-23 (1主两从,复制集名字sh1)
sh2:38024-26 (1主两从,复制集名字sh2) -
mongos
mongos:38017
2、搭建 shard 节点
规划创建安装路径
$ mkdir -p /mongodb/38021/{conf,log,data}
$ mkdir -p /mongodb/38022/{conf,log,data}
$ mkdir -p /mongodb/38023/{conf,log,data}
$ mkdir -p /mongodb/38024/{conf,log,data}
$ mkdir -p /mongodb/38025/{conf,log,data}
$ mkdir -p /mongodb/38026/{conf,log,data}
编辑配置文件
$ vim /mongodb/38021/conf/mongodb.conf
systemLog:
destination: file
path: /mongodb/38021/log/mongodb.log
logAppend: true
storage:
journal:
enabled: true
dbPath: /mongodb/38021/data
directoryPerDB: true
#engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 1
directoryForIndexes: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
net:
bindIp: 0.0.0.0
port: 38021
replication:
oplogSizeMB: 2048
replSetName: sh1
sharding:
clusterRole: shardsvr
processManagement:
fork: true
$ cp /mongodb/38021/conf/mongodb.conf /mongodb/38022/conf
$ cp /mongodb/38021/conf/mongodb.conf /mongodb/38023/conf
$ sed -i 's/38021/38022/g' /mongodb/38022/conf/mongodb.conf
$ sed -i 's/38021/38023/g' /mongodb/38023/conf/mongodb.conf
$ vim /mongodb/38024/conf/mongodb.conf
systemLog:
destination: file
path: /mongodb/38024/log/mongodb.log
logAppend: true
storage:
journal:
enabled: true
dbPath: /mongodb/38024/data
directoryPerDB: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
directoryForIndexes: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
net:
bindIp: 0.0.0.0
port: 38024
replication:
oplogSizeMB: 2048
replSetName: sh2
sharding:
clusterRole: shardsvr
processManagement:
fork: true
$ cp /mongodb/38024/conf/mongodb.conf /mongodb/38025/conf/
$ cp /mongodb/38024/conf/mongodb.conf /mongodb/38026/conf/
$ sed -i 's/38024/38025/g' /mongodb/38025/conf/mongodb.conf
$ sed -i 's/38024/38026/g' /mongodb/38026/conf/mongodb.conf
启动 mongodb
$ mongod -f /mongodb/38021/conf/mongodb.conf
$ mongod -f /mongodb/38022/conf/mongodb.conf
$ mongod -f /mongodb/38023/conf/mongodb.conf
$ mondod -f /mongodb/38024/conf/mongodb.conf
$ mongod -f /mongodb/38025/conf/mongodb.conf
$ mongod -f /mongodb/38026/conf/mongodb.conf
配置复制集
$ mongo --port 38021
> config={_id:'sh2',members:[{_id:0,host:'192.168.3.105:38024'},{_id:1,host:'192.168.3.105:38025'},{_id:2,host:'192.168.3.105:38026'}]}
> rs.initiate(config)
$ mongo --port 38024
> config={_id:'sh2',members:[{_id:0,host:'192.168.3.105:38024'},{_id:1,host:'192.168.3.105:38025'},{_id:2,host:'192.168.3.105:38026'}]}
> rs.initiate(config)
3、搭建 config 节点
$ mkdir -p /mongodb/38018/{conf,log,data}
$ mkdir -p /mongodb/38019/{conf,log,data}
$ mkdir -p /mongodb/38020/{conf,log,data}
$ vi /mongodb/38018/conf/mongodb.conf
systemLog:
destination: file
path: /mongodb/38018/log/mongodb.conf
logAppend: true
storage:
journal:
enabled: true
dbPath: /mongodb/38018/data
directoryPerDB: true
wiredTiger:
engineConfig:
cacheSizeGB: 1
directoryForIndexes: true
collectionConfig:
blockCompressor: zlib
indexConfig:
prefixCompression: true
net:
bindIp: 0.0.0.0
port: 38018
replication:
oplogSizeMB: 2048
replSetName: configReplSet
sharding:
clusterRole: configsvr
processManagement:
fork: true
$ cp /mongodb/38018/conf/mongodb.conf /mongodb/38019/conf/
$ cp /mongodb/38018/conf/mongodb.conf /mongodb/38020/conf/
$ sed -i 's/38018/38019/g' /mongodb/38019/conf/mongodb.conf
$ sed -i 's/38018/38020/g' /mongodb/38020/conf/mongodb.conf
$ mondod -f /mongodb/38018/conf/mongodb.conf
$ mongod -f /mongodb/38019/conf/mongodb.conf
$ mongod -f /mongodb/38020/conf/mongodb.conf
$ mongo --port 38018
> config={_id:'configReplSet',members:[{_id:0,host:'192.168.3.105:38018'},{_id:1,host:'192.168.3.105:38019'},{_id:2,host:'192.168.3.105:38020'}]}
> rs.initiate(config)
4、mongos节点配置
$ mkdir /mongodb/38017/{conf,log} -p
$ vim /mongodb/38017/conf/mongos.conf
systemLog:
destination: file
path: /mongodb/38017/log/mongos.log
logAppend: true
net:
bindIp: 0.0.0.0
port: 38017
sharding:
configDB: configReplSet/192.168.3.105:38018,192.168.3.105:38019,192.168.3.105:38020
processManagement:
fork: true
$ mongos -f /mongodb/38017/conf/mongos.conf
标签:log,mongodb,shard,38024,cluster,conf,true,38018
From: https://www.cnblogs.com/zbc230/p/17507352.html