Ubuntu16.04 配置mongodb開機自啓動

1、安裝mongodb

參閱官方文檔:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

安裝完成後,官方給的啓動,停止,重啓命令分別爲:

sudo service mongod start
sudo service mongod stop
sudo service mongod restart

鬱悶的是不能開機自啓動

2、配置開機自啓動(使用root用戶配置)

cd /etc/init.d/
vi start_mongodb

將下面內容寫入start_mongodb中

#!/bin/bash
### BEGIN INIT INFO
# Provides:          yxk
# Required-start:    $local_fs $remote_fs $network $syslog
# Required-Stop:     $local_fs $remote_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description:
# Description:      
### END INIT INFO

service mongod start

給start_mongodb增加權限

chmod 777 start_mongodb

最後設置開機自啓動

update-rc.d start_mongodb defaults

如果想關閉開機自啓動,則使用

update-rc.d start_mongodb remove

 

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