(Nginx、php-fpm)+centOS7.3開機(jī)自動(dòng)啟動(dòng)設(shè)置

centos 7以上是用Systemd進(jìn)行系統(tǒng)初始化的,Systemd 是 Linux 系統(tǒng)中最新的初始化系統(tǒng)(init),它主要的設(shè)計(jì)目標(biāo)是克服 sysvinit 固有的缺點(diǎn),提高系統(tǒng)的啟動(dòng)速度。

Nginx

Systemd服務(wù)文件以.service結(jié)尾,比如現(xiàn)在要建立nginx為開機(jī)啟動(dòng),如果用yum install命令安裝的,yum命令會(huì)自動(dòng)創(chuàng)建nginx.service文件,直接用命令

systemctl enable nginx.service

置開機(jī)啟動(dòng)即可。

在這里我是用源碼編譯安裝的,所以要手動(dòng)創(chuàng)建nginx.service服務(wù)文件。

開機(jī)沒有登陸情況下就能運(yùn)行的程序,存在系統(tǒng)服務(wù)(system)里,即:

/lib/systemd/system/

在系統(tǒng)服務(wù)目錄里創(chuàng)建nginx.service文件

vim /lib/systemd/system/nginx.service

內(nèi)容如下(路徑改成自己的?。?/p>

[Unit]

Description=nginx

After=network.target

?[Service]

Type=forking

ExecStart=/usr/local/nginx/sbin/nginx

ExecReload=/usr/local/nginx/sbin/nginx -s reload

ExecStop=/usr/local/nginx/sbin/nginx -s quit

PrivateTmp=true

?[Install]

WantedBy=multi-user.target

[Unit]:服務(wù)的說明

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

保存退出。

設(shè)置開機(jī)啟動(dòng)

systemctl enable nginx.service

其它命令

啟動(dòng)nginx服務(wù)

systemctl start nginx.service

設(shè)置開機(jī)自啟動(dòng)

systemctl enable nginx.service

停止開機(jī)自啟動(dòng)

systemctl disable nginx.service

查看服務(wù)當(dāng)前狀態(tài)

systemctl status nginx.service

重新啟動(dòng)服務(wù)

systemctl restart nginx.service

查看所有已啟動(dòng)的服務(wù)

systemctl list-units --type=service

php-fpm

vim /lib/systemd/system/php-fpm.service

內(nèi)容如下(路徑記得改?。?/p>

[Unit]

Description=php-fpm

After=network.target

[Service]

Type=forking

ExecStart=/usr/local/php7/sbin/php-fpm

PrivateTmp=true

[Install]

WantedBy=multi-user.target

將服務(wù)加入開機(jī)自啟

systemctl enable php-fpm.service

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容