# 该Yaml文件改编自DockerHub中的配置文件
version: '3.8'
services:
mongo:
image: mongo:4.4.0 #根据需要选择自己的镜像
restart: always
ports:
- 27017:27017 #对外暴露停供服务的端口,正式生产的时候理论不用暴露。
volumes:
- /docker/mongodb/data/db:/data/db # 挂载数据目录
- /docker/mongodb/data/log:/var/log/mongodb # 挂载日志目录
- /docker/mongodb/data/config:/etc/mongo # 挂载配置目录
# command: --config /docker/mongodb/mongod.conf # 配置文件
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /data/db
journal:
enabled: true
directoryPerDB: true
engine: wiredTiger
wiredTiger:
engineConfig:
cacheSizeGB: 8
directoryForIndexes: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#replication:
replication:
oplogSizeMB: 51200
replSetName: rs0
centos机器安装
cd /etc/yum.repos.d
vim mongodb-org-4.0.repo
添加
[mngodb-org]
name=MongoDB Repository
baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1
yum update -y
yum install mongodb-org -y
whereis mongod
vim /etc/mongod.conf
修改绑定ip
bindIp: 172.0.0.1 改为 bindIp: 0.0.0.0(注意冒号与ip之间需要一个空格),保存退出
systemctl start mongod