Nginx服務(wù)器添加Systemd自定義服務(wù)過程解析
一、以nginx為例
使用yum命令安裝的nginx
Systemd服務(wù)文件以.service結(jié)尾,比如現(xiàn)在要建立nginx為開機(jī)啟動(dòng),如果用yum install命令安裝的,yum命令會(huì)自動(dòng)創(chuàng)建nginx.service文件,直接用命令:
systemcel enable nginx.service //開機(jī)自啟
使用源碼編譯安裝的
1、手動(dòng)創(chuàng)建nginx.service服務(wù)文件。并將其放入 /lib/systemd/system 文件夾中。
nginx.service內(nèi)容如下:
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking
ExecStart=/data/nginx/sbin/nginx
ExecReload=/data/nginx/sbin/nginx -s reload
ExecStop=/data/nginx/sbin/nginx -s quit
PrivateTmp=true
[Install]
WantedBy=multi-user.target
PS: 注意上面的ExecStart/ExecReload/ExecStop 必須 以自己的為主
所對(duì)應(yīng)的key說明
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ì)路徑
[Install]運(yùn)行級(jí)別下服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶,即系統(tǒng)運(yùn)行級(jí)別為3
保存退出。
2、設(shè)置開機(jī)啟動(dòng)
systemctl enable nginx.service
其他服務(wù)命令
systemctl start nginx.service?。▎?dòng)nginx服務(wù))
systemctl stop nginx.service?。ㄍV筺ginx服務(wù))
systemctl enable nginx.service (設(shè)置開機(jī)自啟動(dòng))
systemctl disable nginx.service (停止開機(jī)自啟動(dòng))
systemctl status nginx.service (查看服務(wù)當(dāng)前狀態(tài))
systemctl restart nginx.service?。ㄖ匦聠?dòng)服務(wù))
systemctl list-units --type=service (查看所有已啟動(dòng)的服務(wù))
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。
版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請(qǐng)保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非www.sddonglingsh.com所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場(chǎng),如有內(nèi)容涉嫌侵權(quán),請(qǐng)聯(lián)系alex-e#qq.com處理。