Linux?命令?systemctl?基本介紹和常用選項(xiàng)
Linux systemctl 命令是 systemd 系統(tǒng)和服務(wù)管理器的主要命令之一,它可以啟動(dòng)、停止、重啟、重新加載和查詢系統(tǒng)服務(wù)狀態(tài)等操作。以下是 systemctl 命令的常用選項(xiàng)和用法:
語(yǔ)法
systemctl [OPTIONS] COMMAND [UNIT]OPTIONS: 可選參數(shù),用于指定 systemctl 的行為。COMMAND: 必需參數(shù),用于執(zhí)行特定的 systemd 命令,例如啟動(dòng)、停止或重新啟動(dòng)服務(wù)。UNIT: 可選參數(shù),用于指定要操作的服務(wù)或單元。常用選項(xiàng)
-H, --host: 指定要在遠(yuǎn)程主機(jī)上運(yùn)行的 systemd 實(shí)例的主機(jī)名或 IP 地址。-a, --all: 顯示所有已加載的單位,而不僅僅是當(dāng)前活動(dòng)的單位。-t, --type: 根據(jù)指定的單元類型篩選單元列表。支持的單元類型包括 service、socket、mount 等。-u, --user: 執(zhí)行與當(dāng)前用戶相關(guān)聯(lián)的用戶級(jí)服務(wù)。常用命令
systemctl 是 Linux 操作系統(tǒng)中用于管理系統(tǒng)服務(wù)的命令行工具。它可以啟動(dòng)、停止、重啟、啟用或禁用服務(wù),并提供有關(guān)服務(wù)狀態(tài)和控制的信息。下面是對(duì) systemctl 命令的全面詳細(xì)解釋:
1. 查看服務(wù)狀態(tài):systemctl status <service>:顯示指定服務(wù)的運(yùn)行狀態(tài)、日志信息和依賴關(guān)系。systemctl is-active <service>:檢查指定服務(wù)是否處于激活狀態(tài)(運(yùn)行中)。systemctl is-enabled <service>:檢查指定服務(wù)是否已啟用(將在系統(tǒng)引導(dǎo)時(shí)自動(dòng)啟動(dòng))。systemctl is-failed <service>:檢查指定服務(wù)是否處于失敗狀態(tài)。2. 管理服務(wù):systemctl start <service>:?jiǎn)?dòng)指定服務(wù)。systemctl stop <service>:停止指定服務(wù)。systemctl restart <service>:重新啟動(dòng)指定服務(wù)。systemctl reload <service>:重新加載指定服務(wù)的配置文件。systemctl enable <service>:?jiǎn)⒂弥付ǚ?wù),使其在系統(tǒng)引導(dǎo)時(shí)自動(dòng)啟動(dòng)。systemctl disable <service>:禁用指定服務(wù),使其不會(huì)在系統(tǒng)引導(dǎo)時(shí)啟動(dòng)。3. 管理服務(wù)單元:systemctl list-units:列出所有已知的服務(wù)單元并顯示其當(dāng)前狀態(tài)。systemctl list-unit-files:列出所有已安裝的服務(wù)單元文件。systemctl show <unit>:顯示指定服務(wù)單元的詳細(xì)信息。4. 系統(tǒng)操作:systemctl poweroff:關(guān)閉系統(tǒng)。systemctl reboot:重啟系統(tǒng)。systemctl suspend:將系統(tǒng)置于掛起狀態(tài)(睡眠模式)。systemctl hibernate:將系統(tǒng)置于休眠狀態(tài)(保存當(dāng)前狀態(tài)到磁盤)。5. 日志查詢:systemctl status <service/unit>.service:顯示服務(wù)或單元的當(dāng)前狀態(tài)和日志。journalctl -u <service/unit>.service:查看指定服務(wù)或單元的日志。 示例啟動(dòng) Apache 服務(wù)器服務(wù):
systemctl start httpd.service停止 Apache 服務(wù)器服務(wù):
systemctl stop httpd.service查看 Apache 服務(wù)器服務(wù)狀態(tài):
systemctl status httpd.service設(shè)置 Apache 服務(wù)器在系統(tǒng)啟動(dòng)時(shí)自動(dòng)啟動(dòng):
systemctl enable httpd.service禁用 Apache 服務(wù)器在系統(tǒng)啟動(dòng)時(shí)自動(dòng)啟動(dòng):
systemctl disable httpd.service以上是 systemctl 命令的基本介紹和常用選項(xiàng)、命令及示例。需要注意的是,使用 systemctl 命令需要有管理員權(quán)限(例如 root 或具有 sudo 權(quán)限的用戶)。
到此這篇關(guān)于Linux 命令 systemctl 詳解的文章就介紹到這了,更多相關(guān)Linux 命令 systemctl內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!
