nginx centos 服務開機啟動設定執行個體詳解_nginx

來源:互聯網
上載者:User

nginx centos 服務開機啟動設定

建立服務檔案

以nginx 為例

vim /lib/systemd/system/nginx.service 

在nginx.service 中插入一下內容

[Unit] Description=nginx After=network.target [Service] Type=forking ExecStart= 服務啟動命令ExecReload= 服務重啟命令ExecStop=服務停止命令PrivateTmp=true [Install] WantedBy=multi-user.target 

[Unit]:服務的說明
Description:描述服務
After:描述服務類別
[Service]服務運行參數的設定
Type=forking是後台啟動並執行形式
ExecStart為服務的具體運行命令
ExecReload為重啟命令
ExecStop為停止命令
PrivateTmp=True表示給服務分配獨立的臨時空間
注意:[Service]的啟動、重啟、停止命令全部要求使用絕對路徑

以754的許可權儲存在目錄:/lib/systemd/system 

設定開機自啟動:

systemctl enable nginx.service

相關命令

功能                                       cnetos7以前                                          cnetos7
顯示所有已啟動的服務            chkconfig --list                 systemctl list-units --type=service

啟動某服務       service nginx start systemctl             start nginx.service 或 systemctl start nginx

停止某服務       service nginx stop systemctl             stop nginx.service 或 systemctl stop nginx

重啟某服務       service nginx restart                    systemctl restart nginx.service 或 systemctl restart nginx

使某服務自動啟動     chkconfig --level 3 nginx  on       systemctl enable nginx.service 或 systemctl enable nginx

使某服務不自動啟動     chkconfig --level 3 nginx off    systemctl disable nginx.service 或 systemctl disable nginx

檢查服務狀態       service nginx status                 systemctl is-active nginx.service (僅顯示是否)Activesystemctl status nginx.service (服務詳細資料)

感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.