CentOS 7 配置nginx的service 腳本例子

在CentOS 7中對用戶安裝的應用服務設置爲系統服務,比CentOS 6方便很多,下面以配置nginx爲系統服務爲例子進行說明。
本例中的nginx採用源碼編譯方式進行安裝,安裝位置在/usr/local/nginx。要配置nginx爲系統服務,需要有nginx.service文件,執行如下操作,編寫service腳本。

vim /usr/lib/systemd/system/nginx.service
#nginx.service內容
[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/usr/local/nginx/nginx.pid
ExecStartPre=/usr/local/nginx/sbin/nginx -t -c /usr/local/nginx/conf/nginx.conf
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

#賦予腳本執行權限

chmod +x /usr/lib/systemd/system/nginx.service

#設置nginx.service爲系統服務

systemctl enable nginx.service

##通過系統服務操作nginx

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