centos7 設置MongoDB開機自啓動

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

注:其中 /mnt/app/mongodb 需要設置爲自己MongoDB的安裝目錄下

2.設置權限

chmod 754 mongodb.service

3.啓動關閉服務,設置開機啓動

#啓動服務 
systemctl start mongodb.service   
#關閉服務   
systemctl stop mongodb.service   
#開機啓動   
systemctl enable mongodb.service

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章