在 Linux 上,MongoDB 的配置通常通过在 配置文件 中修改,然后重启 MongoDB 服务生效。
常见位置有以下几种(取决于安装方式):
最常见路径:
/etc/mongod.conf
一般在你解压目录里,例如:
/opt/mongodb/mongod.conf
配置文件在容器内或挂载的卷中:
docker inspect <容器名>
看 Mounts 或 Cmd 里的 --config
ps aux | grep mongod
示例输出:
mongod --config /etc/mongod.conf
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
net:
port: 27017
bindIp: 0.0.0.0
常见修改项:
bindIp:允许访问的 IPport:端口dbPath:数据目录authorization: enabled:开启账号密码sudo systemctl restart mongod
sudo systemctl restart mongod
mongod --config /path/mongod.conf
sudo systemctl status mongod
或:
mongo
> db.runCommand({ getCmdLineOpts: 1 })
如果你能告诉我:
我可以直接给你一份可复制的配置。