1、進入cd /lib/systemd/system目錄下
2、創建編輯 vi mongodb.service
3、把內容粘貼到mongodb.service中,保存退出
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/bin/mongodb.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
4、執行此命令 systemctl start mongodb.service
如果報錯執行 systemctl daemon-reload