首先创建mongodb.service文件,并编辑
# vim /lib/systemd/system/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/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
启动服务
systemctl start mongodb.service
关闭服务
systemctl stop mongodb.service
开机启动
systemctl enable mongodb.service