centos 7的開機啟動跟之前版本的centos有很大不同。現在用 systemctl命令代替了之前的chkconfig 和 service 命令
注冊到開機啟動的方法如下:
在系統服務目錄下新建mongodb的啟動服務
cd /lib/systemd/system vi mongodb.service
內容如下
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target
路徑必須要寫絕對路徑
並給與754的權限
chmod 754 mongodb.service
操作
啟動 systemctl start mongodb.service 關閉 systemctl stop mongodb.service 注冊到開機啟動 systemctl enable mongodb.service
重啟機器驗證
reboot
.