(1).在/lib/systemd/system/目录下新建mongodb.service文件,内容如下
[Unit] Description=mongodb
After=network.target remote-fs.target nss-lookup.target [Service]
Type=forking
ExecStart=/mnt/app/mongodb/bin/mongod --config /mnt/app/mongodb/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/mnt/app/mongodb/bin/mongod --shutdown --config /mnt/app/mongodb/mongodb.conf
PrivateTmp=true [Install]
WantedBy=multi-user.target
(2).设置权限
chmod 754 mongodb.service
(3).启动关闭服务,设置开机启动
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service