Centos 開機啓動Openresty之中的Nginx

centos 7是用Systemd進行系統初始化的,Systemd是Linux系統中最新的初始化系統(init)
關於Systemd的詳情介紹在這裏:

https://www.linuxidc.com/Linux/2015-04/115937.htm

https://www.linuxidc.com/Linux/2016-09/135464.htm

 

Systemd服務文件以.service結尾,比如現在要建立nginx爲開機啓動,
如果用yum install命令安裝的,yum命令會自動創建nginx.service文件,直接用命令:
systemctl enable nginx.service設置開機啓動即可。


由於我的openresty是用源碼編譯安裝的,所以要手動創建nginx.service服務文件。
在系統服務目錄(/usr/lib/systemd/system/)裏創建nginx.service文件。

nginx.service內容如下:

[Unit]
Description=nginx
After=network.target
 
[Service]
Type=forking
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/usr/local/openresty/nginx/sbin/nginx -s reload
ExecStop=/usr/local/openresty/nginx/sbin/nginx -s quit
PrivateTmp=true

[Install]
WantedBy=multi-user.target

參數說明

Description:描述服務
After:描述服務類別

[Service]服務運行參數的設置
Type=forking是後臺運行的形式
ExecStart爲服務的具體運行命令
ExecReload爲重啓命令
ExecStop爲停止命令
PrivateTmp=True表示給服務分配獨立的臨時空間
#  注意:[Service]的啓動、重啓、停止命令全部要求使用絕對路徑

[Install]運行級別下服務安裝的相關設置,可設置爲多用戶,即系統運行級別爲3

設置開機啓動:

systemctl enable nginx.service

 

 

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