- 需要手动新建/lib/systemd/system/mongod.service文件,并写入下面内容:
[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target
- 然后执行 (激活mongod service)
sudo systemctl enable mongod
- 启动、重启和关闭命令
sudo service mongod start
sudo service mongod restart
sudo service mongod stop