日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > linux >内容正文

linux

【Linux】一步一步学Linux——systemctl命令(147)

發布時間:2024/4/21 linux 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【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 onsystemctl enable httpd.service
使某服務不自動啟動chkconfig --level 3 httpd offsystemctl disable httpd.service
檢查服務狀態service httpd statussystemctl status httpd.service (服務詳細信息) systemctl is-enabled httpd.service (僅顯示是否 Active)
顯示所有已啟動的服務chkconfig --listsystemctl list-units --type=service
啟動某服務service httpd startsystemctl start httpd.service
停止某服務service httpd stopsystemctl stop httpd.service
重啟某服務service httpd restartsystemctl restart httpd.service
某服務重新加載配置文件service httpd reloadsystemctl reload httpd.service

02. 命令格式

格式:systemctl [選項...] {命令} ...

03. 常用選項

-start 啟動服務 -stop 停止服務 -restart 重啟服務 -enable 使某服務開機自啟 -disable 關閉某服務開機自啟 -status 查看服務狀態 -list-units –type=service 列舉所有已啟動服務

04. 參考示例

4.1 輸出所有已經啟動服務

[deng@localhost ~]$ systemctl

4.2 輸出所有已經啟動的單元

[deng@localhost ~]$ systemctl list-units

4.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 Agent

4.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 static

4.5 啟動服務

[root@localhost ~]# systemctl start sshd

4.6 停止服務

[root@localhost ~]# systemctl stop sshd

4.7 重啟服務

[root@localhost ~]# systemctl restart sshd

4.8 重新加載服務配置

[root@localhost ~]# systemctl reload sshd

4.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 ago

4.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 sshd

4.14 重新加載systemd

[root@localhost ~]# systemctl daemon-reload

4.15 重新啟動系統

[root@localhost ~]# systemctl reboot

4.16 關機

[root@localhost ~]# systemctl poweroff

4.17 休眠

[root@localhost ~]# systemctl hibernate

hibernate:休眠模式則是將系統狀態保存到硬盤當中,保存完畢后,將計算機關機。當用戶嘗試喚醒系統時,系統會開始正常運行,然后將保存在硬盤中的系統狀態恢復回來。因為數據需要從硬盤讀取,因此喚醒的速度比較慢(如果你使用的是 SSD 磁盤,喚醒的速度也是非常快的)。

4.18 待機

[root@localhost ~]# systemctl suspend

suspend:暫停模式會將系統的狀態保存到內存中,然后關閉掉大部分的系統硬件,當然,并沒有實際關機。當用戶按下喚醒機器的按鈕,系統數據會從內存中回復,然后重新驅動被大部分關閉的硬件,所以喚醒系統的速度比較快。

4.19 混合休眠模式(同時休眠到硬盤并待機)

[root@localhost ~]# systemctl hybrid-sleep

4.20 相當于telinit 3 或 telinit 5

[root@localhost ~]# systemctl isolate graphical.target

graphical.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=service

4.22 查看目前是否運行指定服務

[root@localhost ~]# systemctl is-active sshd active [root@localhost ~]#

4.23 列出unit的配置

[root@localhost ~]# systemctl show

4.24 查看服務的配置

[root@localhost ~]# systemctl show sshd.service

4.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.service

4.28 進入救援模式

[root@localhost ~]# systemctl rescue

4.29 進入緊急救援模式

[root@localhost ~]# systemctl emergency

4.30 本機 socket 的服務

[root@localhost ~]# systemctl list-sockets

05. 附錄

參考:【Linux】一步一步學Linux系列教程匯總

參考:https://blog.csdn.net/skh2015java/article/details/94012643

總結

以上是生活随笔為你收集整理的【Linux】一步一步学Linux——systemctl命令(147)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。