日韩黑丝制服一区视频播放|日韩欧美人妻丝袜视频在线观看|九九影院一级蜜桃|亚洲中文在线导航|青草草视频在线观看|婷婷五月色伊人网站|日本一区二区在线|国产AV一二三四区毛片|正在播放久草视频|亚洲色图精品一区

分享

CentOS 7.x設(shè)置自定義開機(jī)啟動(dòng),添加自定義系統(tǒng)服務(wù)

 昵稱6656145 2015-09-07

CentOS 7.x設(shè)置自定義開機(jī)啟動(dòng),添加自定義系統(tǒng)服務(wù)

時(shí)間:2015-05-07 00:32來源:blog.csdn.net 作者:風(fēng)域 舉報(bào) 點(diǎn)擊:2383次
Centos 系統(tǒng)服務(wù)腳本目錄:
[html] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. /usr/lib/systemd/  
有系統(tǒng)(system)和用戶(user)之分,

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

[html] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. /lib/systemd/system/  
反之,用戶登錄后才能運(yùn)行的程序,存在用戶(user)里

服務(wù)以.service結(jié)尾。

這邊以nginx開機(jī)運(yùn)行為例

1.建立服務(wù)文件

[html] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. vim /lib/systemd/system/nginx.service  
[plain] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. [Unit]  
  2. Description=nginx  
  3. After=network.target  
  4.    
  5. [Service]  
  6. Type=forking  
  7. ExecStart=/www/lanmps/init.d/nginx start  
  8. ExecReload=/www/lanmps/init.d/nginx restart  
  9. ExecStop=/www/lanmps/init.d/nginx  stop  
  10. PrivateTmp=true  
  11.    
  12. [Install]  
  13. 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)、重啟、停止命令全部要求使用絕對路徑

[Install]服務(wù)安裝的相關(guān)設(shè)置,可設(shè)置為多用戶

2.保存目錄

以754的權(quán)限保存在目錄:

[html] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. /lib/systemd/system  

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

 

[html] view plaincopyprint?在CODE上查看代碼片派生到我的代碼片
  1. systemctl enable nginx.service  

 

4.其他命令

 

 

任務(wù) 舊指令 新指令
使某服務(wù)自動(dòng)啟動(dòng) chkconfig --level 3 httpd  on              systemctl enable httpd.service
使某服務(wù)不自動(dòng)啟動(dòng) chkconfig --level 3 httpd off systemctl disable httpd.service
檢查服務(wù)狀態(tài) service httpd status systemctl status httpd.service (服務(wù)詳細(xì)信息) 
systemctl is-active httpd.service (僅顯示是否 Active)
顯示所有已啟動(dòng)的服務(wù) chkconfig --list systemctl list-units --type=service
啟動(dòng)某服務(wù) service httpd start systemctl start httpd.service
停止某服務(wù) service httpd stop systemctl stop httpd.service
重啟某服務(wù) service httpd restart systemctl restart httpd.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

    本站是提供個(gè)人知識(shí)管理的網(wǎng)絡(luò)存儲(chǔ)空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多