CentOS 7.X 中systemctl命令用法詳解

來源:互聯網
上載者:User

從linux系統版本centos 6.x到centos 7.x變化整體不大,不過還是有很多地方需要我們注意的,最為直觀的當屬服務管理命令,之前centos 7.x之前的系統我們使用service和chkconfig來管理伺服器,而到了centos 7.x 這個版本的linux中,systemctl 一個命令就搞定了,它整合了service和chkconfig 的功能於一身。這裡今天簡單說明一下:

systemctl start *.service #啟動某服務
systemctl stop *.service #停止某服務
systemctl restart *.service #重啟某服務
systemctl reload *.service #重載某服務組態檔
systemctl status *.service #查詢某服務運行狀態
systemctl is-enabled *.service #查看某服務是否開機啟動
systemctl enable *.service #設定開機啟動
systemctl disable *.service #取消開機啟動
systemctl –failed #查看啟動失敗的服務

註:*指服務的名字,比如重啟、iptables,我們就會這樣操作:

[root@21yunwei network-scripts]# systemctl stop  iptables.service
[root@21yunwei network-scripts]# systemctl start iptables.service
[root@21yunwei network-scripts]# systemctl restart  iptables.service
[root@21yunwei network-scripts]# systemctl status  iptables.service
● iptables.service - IPv4 firewall with iptables
  Loaded: loaded (/usr/lib/systemd/system/iptables.service; enabled; vendor preset: disabled)
  Active: active (exited) since Fri 2016-06-17 17:52:05 CST; 16s ago
  Process: 48807 ExecStop=/usr/libexec/iptables/iptables.init stop (code=exited, status=0/SUCCESS)
  Process: 48870 ExecStart=/usr/libexec/iptables/iptables.init start (code=exited, status=0/SUCCESS)
  Main PID: 48870 (code=exited, status=0/SUCCESS)
 
Jun 17 17:52:05 21yunwei systemd[1]: Starting IPv4 firewall with iptables...
Jun 17 17:52:05 21yunwei iptables.init[48870]: iptables: Applying firewall rules: [  OK  ]
Jun 17 17:52:05 21yunwei systemd[1]: Started IPv4 firewall with iptables.
[root@21yunwei network-scripts]# systemctl is-enabled iptables.service
enabled
補充一點小技巧:systemctl 預設沒有伺服器名不全,原因是迷你安裝沒有進行安裝包bash-completion,需要執行下邊命令後重新登入系統就可以看到命令補全了。

yum install -y bash-completion

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.