mongodb设置开机自启动

 

环境:

OS:Centos 7

Mongodb:4.4.13

 

1.在/lib/systemd/system/目录下新建mongodb.service文件,内容如下

yeemiao@zb-mongodb-80a9a4c-prd system]$ vi /usr/lib/systemd/system/mongodb.service
[Unit]
 
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
 
[Service]
Type=forking
ExecStart=/usr/local/services/mongodb/bin/mongod  --config /home/middle/mongodb/conf/mongo.cnf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/usr/local/services/mongodb/bin/mongod --shutdown --config /home/middle/mongodb/conf/mongo.cnf
PrivateTmp=true
 
[Install]
WantedBy=multi-user.target

 

2.设置权限
[root@dd]# cd /usr/lib/systemd/system
[root@dd]# chmod 754 mongodb.service

 

3.启动关闭服务,设置开机启动
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service

 

posted @ 2022-03-25 14:56  slnngk  阅读(393)  评论(0编辑  收藏  举报