新聞中心
systemd是Linux系統(tǒng)最新的初始化系統(tǒng)(init),作用是提高系統(tǒng)的啟動速度,盡可能啟動較少的進程,盡可能更多進程并發(fā)啟動,systemd對應的進程管理命令是systemctl,下面為大家詳細講解一下systemctl命令使用方法。

專注于為中小企業(yè)提供網(wǎng)站設計制作、網(wǎng)站建設服務,電腦端+手機端+微信端的三站合一,更高效的管理,為中小企業(yè)尉氏免費做網(wǎng)站提供優(yōu)質(zhì)的服務。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了成百上千家企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設實現(xiàn)規(guī)模擴充和轉(zhuǎn)變。
使用systemctl命令 Start/Stop/Restart/Reload 服務
使用systemctl啟動服務時,命令格式:systemctl start [service-name]。例如,啟動firewalld服務:
[root@localhost ~]# systemctl start firewalld
與以前老版本的linux中的service命令相反,systemctl start命令不輸出任何內(nèi)容。 要停止服務,請使用systemctl stop [service-name]。例如,停止firewalld服務:
[root@localhost ~]# systemctl stop firewalld
要重新啟動服務,請使用systemctl restart [service-name],例如:
[root@localhost ~]# systemctl restart firewalld
要重新加載服務的配置(例如ssh)而不重新啟動它,請使用systemctl reload [service-name],例如:
[root@localhost ~]# systemctl reload sshd
systemctl檢查服務狀態(tài)
為了查看服務是否正在運行,我們可以使用systemctl status [service-name]來查看。
[root@localhost ~]# systemctl status firewalld
檢查服務是否設置為開機啟動
要在引導時啟用服務,請使用systemctl enable [service-name],例如:
[root@localhost ~]# systemctl enable httpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
同樣,disable時取消引導時啟用服務:
[root@localhost ~]# systemctl disable httpd.service
可以使用is-enabled選項檢查開機是否啟動該服務,請運行:
[root@localhost ~]# systemctl is-enabled httpd.service
輸出的內(nèi)容enabled表示開機時啟動該服務,disabled表示開機時不啟動該服務。
systemctl列出單元
要列出所有激活的單元,使用list-units選項。
[root@localhost ~]# systemctl list-units
要列出所有活動的服務,請運行:
[root@localhost ~]# systemctl list-units -t service
使用systemctl重啟、關機系統(tǒng)
像poweroff、shutdown命令一樣,systemctl命令可以關閉系統(tǒng),重啟或進入休眠狀態(tài)。
關機:
[root@localhost ~]# systemctl poweroff
重啟:
[root@localhost ~]# systemctl reboot
系統(tǒng)休眠:
[root@localhost ~]# systemctl hibernate
使用systemclt管理遠程系統(tǒng)
通常,上述所有systemctl命令都可以用于通過systemctl命令本身管理遠程主機。這將使用ssh與遠程主機進行通信。如下所示:
[root@localhost ~]# systemctl status httpd -H [email protected]
-H選項,指定遠程主機的用戶名和密碼。
管理Targets
Systemd具有Targets的概念,這些Targets的目的與sysVinit系統(tǒng)中的運行級別相似。sysVinit中的運行級別主要是數(shù)字(0,1,2,-6)。以下是sysVinit中的運行級別及其對應的systemd中的target:
0 runlevel0.target, poweroff.target
1 runlevel1.target, rescue.target
2,3,4 runlevel2.target, runlevel3.target,runlevel4.target, multi-user.target
5 runlevel5.target, graphical.target
6 runlevel6.target, reboot.target
如果想要查看當前的運行級別,可以使用如下命令:
[root@localhost ~]# systemctl get-default
multi-user.target
設置默認的運行級別為graphical,命令如下:
[root@localhost ~]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
想要列出所有激活的target,可以使用下面命令:
[root@localhost ~]# systemctl list-units -t target
systemd工具的其他命令
journalctl日志收集
systemd有自己的日志系統(tǒng),稱為journald。它替換了sysVinit中的syslogd。
[root@localhost ~]# journalctl
要查看所有引導消息,請運行命令journalctl -b
[root@localhost ~]# journalctl -b
以下命令實時跟蹤系統(tǒng)日志(類似于tail -f):
[root@localhost ~]# journalctl -f
查詢系統(tǒng)啟動過程的持續(xù)時間
[root@localhost ~]# systemd-analyze
Startup finished in 497ms (kernel) + 1.836s (initrd) + 6.567s (userspace) = 8.901s
最后顯示系統(tǒng)啟動時間為8.901秒。
查看服務的啟動時間:
[root@localhost ~]# systemd-analyze blame
hostnamectl命令
查看主機名稱:
[root@localhost ~]# hostnamectl
網(wǎng)站題目:詳解systemctl命令使用實例
本文地址:http://fisionsoft.com.cn/article/cogeope.html


咨詢
建站咨詢
