【Linux】一步一步学Linux——systemctl命令(147)
00. 目錄
文章目錄
- 00. 目錄
- 01. 命令概述
- 02. 命令格式
- 03. 常用選項
- 04. 參考示例
- 05. 附錄
01. 命令概述
systemctl命令是系統服務管理器指令,它實際上將 service和chkconfig這兩個命令組合到一起。
Centos7之后從init完全換成了systemd的啟動方式,systemd 啟動服務的機制主要是通過 systemctl 的這個系統服務管理指令來處理。systemctl在用法上也囊括 service / chkconfig / setup / init 的大部分功能。
| 使某服務自動啟動 | chkconfig --level 3 httpd on | systemctl enable httpd.service |
| 使某服務不自動啟動 | chkconfig --level 3 httpd off | systemctl disable httpd.service |
| 檢查服務狀態 | service httpd status | systemctl status httpd.service (服務詳細信息) systemctl is-enabled httpd.service (僅顯示是否 Active) |
| 顯示所有已啟動的服務 | chkconfig --list | systemctl list-units --type=service |
| 啟動某服務 | service httpd start | systemctl start httpd.service |
| 停止某服務 | service httpd stop | systemctl stop httpd.service |
| 重啟某服務 | service httpd restart | systemctl restart httpd.service |
| 某服務重新加載配置文件 | service httpd reload | systemctl reload httpd.service |
02. 命令格式
格式:systemctl [選項...] {命令} ...03. 常用選項
-start 啟動服務 -stop 停止服務 -restart 重啟服務 -enable 使某服務開機自啟 -disable 關閉某服務開機自啟 -status 查看服務狀態 -list-units –type=service 列舉所有已啟動服務04. 參考示例
4.1 輸出所有已經啟動服務
[deng@localhost ~]$ systemctl4.2 輸出所有已經啟動的單元
[deng@localhost ~]$ systemctl list-units4.3 顯示啟動失敗的服務
[deng@localhost ~]$ systemctl --failedUNIT LOAD ACTIVE SUB DESCRIPTION ● network.service loaded failed failed LSB: Bring up/down networking ● postfix.service loaded failed failed Postfix Mail Transport Agent4.4 查看所有已經安裝的服務
[deng@localhost ~]$ systemctl list-unit-files UNIT FILE STATE proc-sys-fs-binfmt_misc.automount static dev-hugepages.mount static dev-mqueue.mount static proc-fs-nfsd.mount static proc-sys-fs-binfmt_misc.mount static sys-fs-fuse-connections.mount static4.5 啟動服務
[root@localhost ~]# systemctl start sshd4.6 停止服務
[root@localhost ~]# systemctl stop sshd4.7 重啟服務
[root@localhost ~]# systemctl restart sshd4.8 重新加載服務配置
[root@localhost ~]# systemctl reload sshd4.9 查看服務狀態
[root@localhost ~]# systemctl status sshd ● sshd.service - OpenSSH server daemonLoaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)Active: active (running) since 六 2019-08-17 20:56:41 CST; 1min 10s ago4.10 查看服務是否開機啟動
[root@localhost ~]# systemctl is-enabled sshd enabled [root@localhost ~]#4.11 開機自動啟動服務
[root@localhost ~]# systemctl enable sshd [root@localhost ~]#4.12 開機不啟動服務
[root@localhost ~]# systemctl disable sshd Removed symlink /etc/systemd/system/multi-user.target.wants/sshd.service. [root@localhost ~]#4.13 顯示服務幫助信息
[root@localhost ~]# systemctl help sshd4.14 重新加載systemd
[root@localhost ~]# systemctl daemon-reload4.15 重新啟動系統
[root@localhost ~]# systemctl reboot4.16 關機
[root@localhost ~]# systemctl poweroff4.17 休眠
[root@localhost ~]# systemctl hibernatehibernate:休眠模式則是將系統狀態保存到硬盤當中,保存完畢后,將計算機關機。當用戶嘗試喚醒系統時,系統會開始正常運行,然后將保存在硬盤中的系統狀態恢復回來。因為數據需要從硬盤讀取,因此喚醒的速度比較慢(如果你使用的是 SSD 磁盤,喚醒的速度也是非常快的)。
4.18 待機
[root@localhost ~]# systemctl suspendsuspend:暫停模式會將系統的狀態保存到內存中,然后關閉掉大部分的系統硬件,當然,并沒有實際關機。當用戶按下喚醒機器的按鈕,系統數據會從內存中回復,然后重新驅動被大部分關閉的硬件,所以喚醒系統的速度比較快。
4.19 混合休眠模式(同時休眠到硬盤并待機)
[root@localhost ~]# systemctl hybrid-sleep4.20 相當于telinit 3 或 telinit 5
[root@localhost ~]# systemctl isolate graphical.targetgraphical.target:就是文字界面再加上圖形界面,這個 target 已經包含了下面的 multi-user.target。
multi-user.target:純文本模式!
rescue.target:在無法使用 root 登陸的情況下,systemd 在開機時會多加一個額外的臨時系統,與你原本的系統無關。這時你可以取得 root 的權限來維護你的系統。
emergency.target:緊急處理系統的錯誤,在無法使用 rescue.target 時,可以嘗試使用這種模式!
shutdown.target:就是執行關機。
getty.target:可以設置 tty 的配置。
正常的模式是 multi-user.target 和 graphical.target 兩個,救援方面的模式主要是 rescue.target 以及更嚴重的 emergency.target。如果要修改可提供登陸的 tty 數量,則修改 getty.target。
4.21 列出所有已經啟動的服務
[root@localhost ~]# systemctl list-units --type=service4.22 查看目前是否運行指定服務
[root@localhost ~]# systemctl is-active sshd active [root@localhost ~]#4.23 列出unit的配置
[root@localhost ~]# systemctl show4.24 查看服務的配置
[root@localhost ~]# systemctl show sshd.service4.25 注銷服務
[root@localhost ~]# systemctl mask sshd.service Created symlink from /etc/systemd/system/sshd.service to /dev/null. [root@localhost ~]#4.26 反注銷服務
[root@localhost ~]# systemctl unmask sshd.service Removed symlink /etc/systemd/system/sshd.service. [root@localhost ~]#4.27 只查看服務類型的unit
[root@localhost ~]# systemctl list-units --type=service --allUNIT LOAD ACTIVE SUB DESCRIPTIONabrt-ccpp.service loaded active exited Install ABRT coredump hooabrt-oops.service loaded active running ABRT kernel log watcherabrt-vmcore.service loaded inactive dead Harvest vmcores for ABRTabrt-xorg.service loaded active running ABRT Xorg log watcherabrtd.service loaded active running ABRT Automated Bug Reportaccounts-daemon.service loaded active running Accounts Servicealsa-restore.service loaded inactive dead Save/Restore Sound Card Salsa-state.service loaded active running Manage Sound Card State ( ● apparmor.service not-found inactive dead apparmor.service4.28 進入救援模式
[root@localhost ~]# systemctl rescue4.29 進入緊急救援模式
[root@localhost ~]# systemctl emergency4.30 本機 socket 的服務
[root@localhost ~]# systemctl list-sockets05. 附錄
參考:【Linux】一步一步學Linux系列教程匯總
參考:https://blog.csdn.net/skh2015java/article/details/94012643
總結
以上是生活随笔為你收集整理的【Linux】一步一步学Linux——systemctl命令(147)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【Linux】一步一步学Linux——s
- 下一篇: 【Linux】一步一步学Linux——c