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 (服務詳細資料)
感謝閱讀,希望能協助到大家,謝謝大家對本站的支援!