首先創(chuàng)建mongodb.service文件,并編輯
# vim /lib/systemd/system/mongodb.service
內(nèi)如如下:
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/etc/mongod.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/etc/mongod.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
啟動(dòng)服務(wù)
systemctl start mongodb.service
關(guān)閉服務(wù)
systemctl stop mongodb.service
開機(jī)啟動(dòng)
systemctl enable mongodb.service