在 CentOS 上配置 MongoDB 后,是否需要重启,取决于你修改的是哪类配置:
mongod.conf 配置文件需要重启 MongoDB 服务
例如修改了:
bindIpportstorage.dbPathauthorizationreplicationsecurity✅ 重启方式(CentOS 7+):
systemctl restart mongod
或(老版本):
service mongod restart
⚠️ 修改监听 IP、端口、存储路径等必须重启才生效
通常不需要重启
例如:
✅ 直接通过 mongo / mongosh 执行命令即可:
mongo
use admin
db.createUser(...)
如:
ulimittransparent_hugepagesysctl✅ 需要重启 MongoDB(或至少重启服务)
例如:
systemctl restart mongod
如:
/etc/systemd/system/mongod.service✅ 必须重启
systemctl daemon-reload
systemctl restart mongod
systemctl status mongod
或进入 MongoDB:
mongosh
> db.runCommand({ getCmdLineOpts: 1 })
| 配置类型 | 是否需重启 |
|---|---|
| mongod.conf 核心配置 | ✅ 必须重启 |
| 用户/权限/数据操作 | ❌ 不需要 |
| 系统参数 | ✅ 需要 |
| 启动参数 | ✅ 需要 |
如果你能告诉我 具体改了哪一项配置(比如 bindIp、认证、副本集等),我可以给你更准确的建议。