小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

使用 Systemctl 命令 來(lái)管理系統(tǒng)服務(wù)

 蘇醒的貝殼 2021-01-31
Systemctl是systemd用于管理系統(tǒng)和管理服務(wù)的工具。許多現(xiàn)代Linux發(fā)行版,如Ubuntu、Debian、Fedora、Linux Mint、OpenSuSE、Redhat都采用systemd作為默認(rèn)的init系統(tǒng)。

使用systemctl,可以啟動(dòng)、停止、重新加載、重啟服務(wù)、列出服務(wù)單元、檢查服務(wù)狀態(tài)、啟用/禁用服務(wù)、管理運(yùn)行級(jí)別和電源管理。在本文中將展示如何在Linux中使用systemctl命令來(lái)管理systemd服務(wù)。

*使用systemctl命令 Start/Stop/Restart/Reload 服務(wù)
使用systemctl啟動(dòng)服務(wù)時(shí),命令格式:systemctl start [service-name]。例如,啟動(dòng)firewalld服務(wù):
[root@localhost ~]# systemctl start firewalld
<以上代碼可復(fù)制粘貼,可往左滑>
與以前老版本的linux中的service命令相反,systemctl start命令不輸出任何內(nèi)容。


要停止服務(wù),請(qǐng)使用systemctl stop [service-name]。例如,停止firewalld服務(wù):
[root@localhost ~]# systemctl stop firewalld
<以上代碼可復(fù)制粘貼,可往左滑>


要重新啟動(dòng)服務(wù),請(qǐng)使用systemctl restart [service-name],例如:
[root@localhost ~]# systemctl restart firewalld
<以上代碼可復(fù)制粘貼,可往左滑>


要重新加載服務(wù)的配置(例如ssh)而不重新啟動(dòng)它,請(qǐng)使用systemctl reload [service-name],例如:
[root@localhost ~]# systemctl reload sshd
<以上代碼可復(fù)制粘貼,可往左滑>


*systemctl檢查服務(wù)狀態(tài)
為了查看服務(wù)是否正在運(yùn)行,我們可以使用systemctl status [service-name]來(lái)查看。
[root@localhost ~]# systemctl status firewalld
<以上代碼可復(fù)制粘貼,可往左滑>


*檢查服務(wù)是否設(shè)置為開(kāi)機(jī)啟動(dòng)
要在引導(dǎo)時(shí)啟用服務(wù),請(qǐng)使用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.
<以上代碼可復(fù)制粘貼,可往左滑>


同樣,disable時(shí)取消引導(dǎo)時(shí)啟用服務(wù):
[root@localhost ~]# systemctl disable httpd.service
<以上代碼可復(fù)制粘貼,可往左滑>


可以使用is-enabled選項(xiàng)檢查開(kāi)機(jī)是否啟動(dòng)該服務(wù),請(qǐng)運(yùn)行:
[root@localhost ~]# systemctl is-enabled httpd.service
<以上代碼可復(fù)制粘貼,可往左滑>


輸出的內(nèi)容enabled表示開(kāi)機(jī)時(shí)啟動(dòng)該服務(wù),disabled表示開(kāi)機(jī)時(shí)不啟動(dòng)該服務(wù)。

*systemctl列出單元
要列出所有激活的單元,使用list-units選項(xiàng)。
[root@localhost ~]# systemctl list-units
<以上代碼可復(fù)制粘貼,可往左滑>


要列出所有活動(dòng)的服務(wù),請(qǐng)運(yùn)行:
[root@localhost ~]# systemctl list-units -t service
<以上代碼可復(fù)制粘貼,可往左滑>


*使用systemctl重啟、關(guān)機(jī)系統(tǒng)
poweroff、shutdown命令一樣,systemctl命令可以關(guān)閉系統(tǒng),重啟或進(jìn)入休眠狀態(tài)。
關(guān)機(jī):
[root@localhost ~]# systemctl poweroff
<以上代碼可復(fù)制粘貼,可往左滑>
重啟:
[root@localhost ~]# systemctl reboot
<以上代碼可復(fù)制粘貼,可往左滑>
系統(tǒng)休眠:
[root@localhost ~]# systemctl hibernate
<以上代碼可復(fù)制粘貼,可往左滑>

*使用systemclt管理遠(yuǎn)程系統(tǒng)
通常,上述所有systemctl命令都可以用于通過(guò)systemctl命令本身管理遠(yuǎn)程主機(jī)。這將使用ssh與遠(yuǎn)程主機(jī)進(jìn)行通信。如下所示:
[root@localhost ~]# systemctl status httpd -H root@192.168.0.12
<以上代碼可復(fù)制粘貼,可往左滑>


-H選項(xiàng),指定遠(yuǎn)程主機(jī)的用戶名和密碼。

*管理Targets
Systemd具有Targets的概念,這些Targets的目的與sysVinit系統(tǒng)中的運(yùn)行級(jí)別相似。sysVinit中的運(yùn)行級(jí)別主要是數(shù)字(0,1,2,-6)。以下是sysVinit中的運(yùn)行級(jí)別及其對(duì)應(yīng)的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
<以上代碼可復(fù)制粘貼,可往左滑>
如果想要查看當(dāng)前的運(yùn)行級(jí)別,可以使用如下命令:
[root@localhost ~]# systemctl get-default 
multi-user.target
<以上代碼可復(fù)制粘貼,可往左滑>


設(shè)置默認(rèn)的運(yùn)行級(jí)別為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.
<以上代碼可復(fù)制粘貼,可往左滑>


想要列出所有激活的target,可以使用下面命令:
[root@localhost ~]# systemctl list-units -t target
<以上代碼可復(fù)制粘貼,可往左滑>


*systemd工具的其他命令
journalctl日志收集
systemd有自己的日志系統(tǒng),稱為journald。它替換了sysVinit中的syslogd。
[root@localhost ~]# journalctl
<以上代碼可復(fù)制粘貼,可往左滑>


要查看所有引導(dǎo)消息,請(qǐng)運(yùn)行命令journalctl -b
[root@localhost ~]# journalctl -b
<以上代碼可復(fù)制粘貼,可往左滑>
以下命令實(shí)時(shí)跟蹤系統(tǒng)日志(類(lèi)似于tail -f):
[root@localhost ~]# journalctl -f
<以上代碼可復(fù)制粘貼,可往左滑>

查詢系統(tǒng)啟動(dòng)過(guò)程的持續(xù)時(shí)間
[root@localhost ~]# systemd-analyze
Startup finished in 497ms (kernel) + 1.836s (initrd) + 6.567s (userspace) = 8.901s

<以上代碼可復(fù)制粘貼,可往左滑>


最后顯示系統(tǒng)啟動(dòng)時(shí)間為8.901秒。
查看服務(wù)的啟動(dòng)時(shí)間:
[root@localhost ~]# systemd-analyze blame
<以上代碼可復(fù)制粘貼,可往左滑>

hostnamectl命令
查看主機(jī)名稱:
[root@localhost ~]# hostnamectl
<以上代碼可復(fù)制粘貼,可往左滑>


*總   結(jié)
在本文學(xué)習(xí)了systemctl命令來(lái)管理Linux發(fā)行版中的系統(tǒng)服務(wù)。希望對(duì)你們有所幫助。


END

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

    0條評(píng)論

    發(fā)表

    請(qǐng)遵守用戶 評(píng)論公約

    類(lèi)似文章 更多