centos7 將服務添加到systemctl


centos7中提供了systemd服務,可以方便的管理各種服務

但是有些通過編譯安裝的服務systemd里面沒有,我們只需要添加一下服務文件即可

以下用nginx作為例子,展示如何添加服務到systemd中

假設nginx安裝在/usr/bin/nginx,配置文件在/usr/local/nginx/conf/nginx.conf

vim /usr/lib/systemd/system/nginx.service 

編輯該文件

[Unit]
Description=nginx - high performance web server
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s stop

[Install]
WantedBy=multi-user.target
[Unit]:服務的說明
Description:描述服務
After:描述服務類別

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

[Install]服務安裝的相關設置,可設置為多用戶
chmod 754 nginx.service

修改權限,現在systemctl可以使用nginx了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM