国产欧美日韩第一页|日本一二三不卡视频|在线精品小视频,亚洲第一免费播放区,metcn人体亚洲一区,亚洲精品午夜视频

幫助中心 >  技術(shù)知識庫 >  云服務(wù)器 >  服務(wù)器教程 >  CentOS7設(shè)置自定義開機啟動,添加自定義系統(tǒng)服務(wù)

CentOS7設(shè)置自定義開機啟動,添加自定義系統(tǒng)服務(wù)

2017-03-15 20:18:01 19541

Centos 系統(tǒng)服務(wù)腳本目錄:

/usr/lib/systemd/

 

有系統(tǒng)(system)和用戶(user)之分,如需要開機沒有登陸情況下就能運行的程序,存在系統(tǒng)服務(wù)(system)里,即:

lib/systemd/system/

 

反之,用戶登錄后才能運行的程序,存在用戶(user)里,服務(wù)以.service結(jié)尾。

這邊以nginx開機運行為例:

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

vim /lib/systemd/system/nginx.service   

 

[Unit]    

Description=nginx    

After=network.target         

[Service]    

Type=forking    

ExecStart=/www/lanmps/init.d/nginx start    

ExecReload=/www/lanmps/init.d/nginx restart    

ExecStop=/www/lanmps/init.d/nginx  stop    

PrivateTmp=true    

 

[Install]    

WantedBy=multi-user.target   

 

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

Description:描述服務(wù)

After:描述服務(wù)類別

[Service]服務(wù)運行參數(shù)的設(shè)置

Type=forking是后臺運行的形式

ExecStart為服務(wù)的具體運行命令

ExecReload為重啟命令

ExecStop為停止命令

PrivateTmp=True表示給服務(wù)分配獨立的臨時空間

注意:[Service]的啟動、重啟、停止命令全部要求使用絕對路徑

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


2.保存目錄

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

/lib/systemd/system  

 

3.設(shè)置開機自啟動

systemctl enable nginx.service  

 

4.其他命令

任務(wù)

舊指令

新指令

使某服務(wù)自動啟動

Chkconfig --level   3 httpd on

systemctl enable   httpd.service

使某服務(wù)不自動啟動

chkconfig --level   3 httpd off

systemctl disable   httpd.service

檢查服務(wù)狀態(tài)

service httpd   status

systemctl   status httpd.service (服務(wù)詳細信息)

systemctl   is-active httpd.service(僅顯示是否Active)

顯示所有已啟動的服務(wù)

chkconfig --list

systemctl   list-units --type=service

啟動某服務(wù)

service httpd   start

systemctl start   httpd.service

停止某服務(wù)

service httpd   stop

systemctl stop   httpd.service

重啟某服務(wù)

service httpd   restart

systemctl restart   httpd.service

 

啟動nginx服務(wù):

systemctl start nginx.service

 

設(shè)置開機自啟動:

systemctl enable nginx.service

 

停止開機自啟動:

systemctl disable nginx.service

 

查看服務(wù)當前狀態(tài):

systemctl status nginx.service

 

重新啟動服務(wù):

systemctl restart nginx.service

 

查看所有已啟動的服務(wù):

systemctl list-units --type=service


提交成功!非常感謝您的反饋,我們會繼續(xù)努力做到更好!

這條文檔是否有幫助解決問題?

非常抱歉未能幫助到您。為了給您提供更好的服務(wù),我們很需要您進一步的反饋信息:

在文檔使用中是否遇到以下問題: