systemctl mongod
程序员文章站
2024-02-23 08:13:52
...
vim /etc/systemd/system/mongod.service
写入配置如下:
[Unit]
Description=mongod
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
# ./bin/mongod --config ./etc/mongodb.conf
ExecStart=/home/mongodb/mongodb_4.2.3/bin/mongod --config /home/mongodb/mongodb_4.2.3/etc/mongodb.conf
ExecStop=/home/mongodb/mongodb_4.2.3/bin/mongod --shutdown --config /home/mongodb/mongodb_4.2.3/etc/mongodb.conf
PrivateTmp=false
Restart=on-failure
[Install]
WantedBy=multi-user.target
最后设置启动
systemctl daemon-reload
systemctl status mongod
systemctl start mongod
systemctl stop mongod
systemctl enable mongod.service #开机运行服务
systemctl disable mongod.service #取消开机运行