设置mongodb.service启动服务
cd /lib/systemd/system
vi mongodb.service (新创建的,默认安装完mongo,该目录下是有一个mongod.service文件)
写入以下内容:
[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/bin/mongod --config /etc/mongod.conf
ExecStop=/usr/bin/mongod --shutdown --config /etc/mongodb.conf
PrivateTmp=false
[Install]
WantedBy=multi-user.target
设置mongodb.service权限
chmod 754 mongodb.service
系统mongodb.service操作命令
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service
mongodb服务启动 service mongodb start
mongodb服务停止 service mongodb stop
mongodb服务重启 service mongodb restart
参考链接:https://www.bbsmax.com/A/kmzL8m7XzG/