1. 从Docker Hub上拉取MongoDB镜像
docker pull mongo:4.0.0
2. Docker网络配置
## 为MongoDB集群创建独立的docker网桥
docker network create --subnet=10.1.1.0/24 mongodbnet
## 查看网络信息
docker network ls
docker network inspect 9d4910fdcf5a
3. 准备MongoDB集群配置文件
-
Mongos 配置文件
路径:/mongos/mongos.conf
说明:
mongos不需要存储因此去掉storage字段;
可任意配置net.port字段,需要指定processManagement.fork为true以–fork方式启动;
sharding.configDB字段用于指定Config-Server集群地址,格式为[replSetName]/[config-server1:port],[config-server2:port],[config-server3:port]…
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongos.log
net:
port: 27020
bindIp: 127.0.0.1
processManagement:
fork: true
timeZoneInfo: /usr/share/zoneinfo
sharding:
configDB: cfg/10.1.1.2:27019,10.1.1.3:27019,10.1.1.4:27019
-
Config-Server 配置文件
路径:/configsvr/mongod.conf
说明:MongoDB v3.4 之后要求Config-Server也需要组成副本集形式
storage:
dbPath: /data/db
journal:
enabled: true
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
net:
bindIp: 127.0.0.1
processManagement:
timeZoneInfo: /usr/share/zoneinfo
replication:
replSetName: cfg
sharding:
clusterRole: configsvr
-
Shard-Server 配置文件
路径:E:\hj-usingtools\mongoClusterConfig\shared1/mongod.c