nginx centos 服務(wù)開(kāi)機(jī)啟動(dòng)設(shè)置
建立服務(wù)文件
以nginx 為例
vim /lib/systemd/system/nginx.service
在nginx.service 中插入一下內(nèi)容
[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart= 服務(wù)啟動(dòng)命令ExecReload= 服務(wù)重啟命令ExecStop=服務(wù)停止命令PrivateTmp=true [Install] WantedBy=multi-user.target
[Unit]:服務(wù)的說(shuō)明
Description:描述服務(wù)
After:描述服務(wù)類別
[Service]服務(wù)運(yùn)行參數(shù)的設(shè)置
Type=forking是后臺(tái)運(yùn)行的形式
ExecStart為服務(wù)的具體運(yùn)行命令
ExecReload為重啟命令
ExecStop為停止命令
PrivateTmp=True表示給服務(wù)分配獨(dú)立的臨時(shí)空間
注意:[Service]的啟動(dòng)、重啟、停止命令全部要求使用絕對(duì)路徑
以754的權(quán)限保存在目錄:/lib/systemd/system
設(shè)置開(kāi)機(jī)自啟動(dòng):
systemctl enable nginx.service
相關(guān)命令
功能 cnetos7以前 cnetos7
顯示所有已啟動(dòng)的服務(wù) chkconfig --list systemctl list-units --type=service
啟動(dòng)某服務(wù) service nginx start systemctl start nginx.service 或 systemctl start nginx
停止某服務(wù) service nginx stop systemctl stop nginx.service 或 systemctl stop nginx
重啟某服務(wù) service nginx restart systemctl restart nginx.service 或 systemctl restart nginx
使某服務(wù)自動(dòng)啟動(dòng) chkconfig --level 3 nginx on systemctl enable nginx.service 或 systemctl enable nginx
使某服務(wù)不自動(dòng)啟動(dòng) chkconfig --level 3 nginx off systemctl disable nginx.service 或 systemctl disable nginx
檢查服務(wù)狀態(tài) service nginx status systemctl is-active nginx.service (僅顯示是否)Activesystemctl status nginx.service (服務(wù)詳細(xì)信息)
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選