在 Linux 上开启(启动)MongoDB 并加载配置文件,通常有以下几种常见方式,取决于你的安装方式(包管理安装 or 二进制安装)。
默认配置文件一般在这里:
/etc/mongod.conf
vim /etc/mongod.conf
常见配置:
storage:
dbPath: /var/lib/mongo
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
net:
port: 27017
bindIp: 0.0.0.0
sudo systemctl start mongod
sudo systemctl enable mongod
sudo systemctl status mongod
如果你是用 tar 包安装的 MongoDB:
mongod --config /path/to/mongod.conf
或者后台运行:
mongod --config /path/to/mongod.conf --fork
⚠️ 如果使用
--fork,配置文件中必须配置systemLog.path
mongod --dbpath /data/db --port 27017 --bind_ip 0.0.0.0
sudo chown -R mongod:mongod /var/lib/mongo
netstat -tunlp | grep 27017
bindIpsudo ufw allow 27017
如果你能告诉我:
我可以给你更精确的步骤。