MongoDB分片集群搭建
一.环境介绍
系统环境
操作系统 | 主机名 | IP地址 |
---|---|---|
CentOS Linux release 7.6.1810 (Core) | mongox | 10.0.0.4 |
CentOS Linux release 7.6.1810 (Core) | mongoy | 10.0.0.5 |
CentOS Linux release 7.6.1810 (Core) | mongoz | 10.0.0.6 |
MongoDB版本
当前使用的MongoDB版本为4.2.0,下载地址.
关闭防火墙
systemctl stop filewalld
集群架构
副本集
若要查看具体的文档,可以访问官方文档,文章中很多内容都可以参考https://docs.mongodb.com/manual/,地址
分片
二.安装
创建用户
创建目录
#创建日志目录
mkdir -p /var/log/mongodb/
touch /var/log/mongodb/mongod{
0,1,2}.log
touch /var/log/mongodb/csvr.log
#创建存储目录
mkdir -p /data/mongodb/{
0,1,2,csvr}
配置副本集
在每台机器上都创建下列三个文件
#mongod0.yaml
systemLog:
destination: file
path: "/var/log/mongodb/mongod0.log"
logAppend: true
storage:
journal:
enabled: true
dbPath: "/data/mongodb/0"
processManagement:
fork: true
net:
bindIp: 0.0.0.0
port: 27016
setParameter:
enableLocalhostAuthBypass: false
replication:
replSetName: "rs0"
sharding:
clusterRole: shardsvr
#mongod1.yaml
systemLog:
destination: file
path: "/var/log/mongodb/mongod1.log"
logAppend: true
storage:
journal:
enabled: true
dbPath: "/data/mongodb/1"
processManagement:
fork: true
net:
bindIp: 0.0.0.0
port: 27017
setParameter:
enableLocalhostAuthBypass: false
replication:
replSetName: "rs1"
sharding:
clusterRole: shardsvr
#mongod2.yaml
systemLog:
destination: file
path: "/var/log/mongodb/mongod2.log"
logAppend: true
storage:
journal:
enabled: true
dbPath: "/data/mongodb/2"
processManagement