關於centos服務的命令經常會遇到這幾種
service
systemctl
/etc/init.d/
1 service和/etc/init.d/
service是一個腳本命令,分析service可知是去/etc/init.d目錄下執行相關程序。service和chkconfig結合使用。
服務配置文件存放目錄/etc/init.d/
命令使用:
service start nginx
/etc/init.d/nginx restart
2 systemctl
centos7 上面啟動服務以及關閉服務已經不是以前的service stop/start xxxx了而是systemctl命令,不過用service他會有一個提醒你用systemctl,所以大可不必擔心。
列出正在運行的服務狀態——systemctl
啟動一個服務——systemctl start postfix.service
關閉一個服務——systemctl stop postfix.service
重啟一個服務:——systemctl restart postfix.service
顯示一個服務的狀態——systemctl status postfix.service
在開機時啟用一個服務——systemctl enable postfix.service
在開機時禁用一個服務——systemctl disable postfix.service
查看服務是否開機啟動——systemctl is-enabled postfix.service;echo $?
查看已啟動的服務列表——systemctl list-unit-files|grep enabled