1、设置mongodb.service启动服务
cd /lib/systemd/system
vi mongodb.service
2、服务内容
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking RuntimeDirectory=mongodb RuntimeDirectoryMode=0751 PIDFile=/var/run/mongodb/mongod.pid ExecStart=/usr/mongodb/bin/mongod --config /usr/mongodb/mongodb.conf ExecStop=/usr/mongodb/bin/mongod --shutdown --config /usr/mongodb/mongodb.conf PrivateTmp=false [Install] WantedBy=multi-user.target
3、设置mongodb.service权限
chmod 754 mongodb.service
4、启动服务
systemctl start mongodb.service
5、开机启动
systemctl enable mongodb.service
6、关闭服务
systemctl stop mongodb.service
7、服务启动测试
service mongodb start