Ubuntu中手动安装MongoDB后添加服务
创建配置文件
执行命令: sudo vim /etc/mongodb/mongod.conf
并添加以下内容
systemLog:
destination: file
path: /var/log/mongodb/mongod.log
logAppend: true
storage:
dbPath: /var/lib/mongo
net:
bindIp: 127.0.0.1
创建服务文件
执行命令:sudo vim /etc/systemd/system/mongodb.service
并添加以下内容
[Unit]
Description=High-performance, schema-free document-oriented database
After=syslog.target
After=network.target
[Service]
type=forking
ExecStart=/usr/local/bin/mongod --quiet --config /etc/mongodb/mongod.conf
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
保存后,分别执行以下命令:
sudo systemctl enable mongodb
sudo systemctl daemon-reload
sudo systemctl restart mongodb
最后执行 sudo systemctl status mongodb
查看是否允许正常