NetworkManager???? 0:off??? 1:off??? 2:on??? 3:on??? 4:on??? 5:on??? 6:off
abrt-ccpp????????? 0:off??? 1:off??? 2:off??? 3:on??? 4:off??? 5:on??? 6:off
abrtd????????????? 0:off??? 1:off??? 2:off??? 3:on??? 4:off??? 5:on??? 6:off
acpid????????????? 0:off??? 1:off??? 2:on??? 3:on??? 4:on??? 5:on??? 6:off
atd??????????????? 0:off??? 1:off??? 2:off??? 3:on??? 4:on??? 5:on??? 6:off
auditd???????????? 0:off??? 1:off??? 2:on??? 3:on??? 4:on??? 5:on??? 6:off
.
.

如何查看指定服務(wù)的狀態(tài)

如果你想查看運(yùn)行級(jí)別下某個(gè)服務(wù)的狀態(tài),你可以使用下面的格式匹配出需要的服務(wù)。

比如說(shuō)我想查看運(yùn)行級(jí)別中 auditd 服務(wù)的狀態(tài)

# chkconfig --list| grep auditd
auditd    0:off 1:off 2:on 3:on 4:on 5:on 6:off

如何在指定運(yùn)行級(jí)別中啟用服務(wù)

使用 –level 參數(shù)啟用指定運(yùn)行級(jí)別下的某個(gè)服務(wù),下面展示如何在運(yùn)行級(jí)別 3 和運(yùn)行級(jí)別 5 下啟用 httpd 服務(wù)。

# chkconfig --level 35 httpd on

如何在指定運(yùn)行級(jí)別下禁用服務(wù)

同樣使用 –level 參數(shù)禁用指定運(yùn)行級(jí)別下的服務(wù),下面展示的是在運(yùn)行級(jí)別 3 和運(yùn)行級(jí)別 5 中禁用 httpd 服務(wù)。

# chkconfig --level 35 httpd off

如何將一個(gè)新服務(wù)添加到啟動(dòng)列表中

-–add 參數(shù)允許我們添加任何新的服務(wù)到啟動(dòng)列表中,默認(rèn)情況下,新添加的服務(wù)會(huì)在運(yùn)行級(jí)別 2、3、4、5 下自動(dòng)開(kāi)啟。

# chkconfig --add nagios

如何從啟動(dòng)列表中刪除服務(wù)

可以使用 –del 參數(shù)從啟動(dòng)列表中刪除服務(wù),下面展示的是如何從啟動(dòng)列表中刪除 Nagios 服務(wù)。

# chkconfig --del nagios

如何使用 systemctl 命令啟用或禁用開(kāi)機(jī)自啟服務(wù)?

systemctl 用于命令行,它是一個(gè)用來(lái)管理 systemd 的守護(hù)進(jìn)程/服務(wù)的基礎(chǔ)工具,例如:(開(kāi)啟、重啟、關(guān)閉、啟用、禁用、重載和狀態(tài))。

所有服務(wù)創(chuàng)建的 unit 文件位與 /etc/systemd/system/。

如何列出全部的服務(wù)

使用下面的命令列出全部的服務(wù)(包括啟用的和禁用的)。

# systemctl list-unit-files --type=service
UNIT FILE          STATE
arp-ethers.service       disabled
auditd.service        enabled
autovt@.service        enabled
blk-availability.service      disabled
brandbot.service        static
chrony-dnssrv@.service      static
chrony-wait.service       disabled
chronyd.service        enabled
cloud-config.service       enabled
cloud-final.service       enabled
cloud-init-local.service      enabled
cloud-init.service       enabled
console-getty.service       disabled
console-shell.service       disabled
container-getty@.service      static
cpupower.service        disabled
crond.service         enabled
.
.
150 unit files listed.

使用下面的格式通過(guò)正則表達(dá)式匹配出你想要查看的服務(wù)的當(dāng)前狀態(tài)。下面是使用 systemctl 命令查看 httpd 服務(wù)的狀態(tài)。

# systemctl list-unit-files --type=service | grep httpd
httpd.service disabled

如何讓指定的服務(wù)開(kāi)機(jī)自啟

使用下面格式的 systemctl 命令啟用一個(gè)指定的服務(wù)。啟用服務(wù)將會(huì)創(chuàng)建一個(gè)符號(hào)鏈接,如下可見(jiàn):

# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

運(yùn)行下列命令再次確認(rèn)服務(wù)是否被啟用。

# systemctl is-enabled httpd
enabled

如何禁用指定的服務(wù)

運(yùn)行下面的命令禁用服務(wù)將會(huì)移除你啟用服務(wù)時(shí)所創(chuàng)建的符號(hào)鏈接。

# systemctl disable httpd
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.

運(yùn)行下面的命令再次確認(rèn)服務(wù)是否被禁用。

# systemctl is-enabled httpd
disabled

如何查看系統(tǒng)當(dāng)前的運(yùn)行級(jí)別

使用 systemctl 命令確認(rèn)你系統(tǒng)當(dāng)前的運(yùn)行級(jí)別,runlevel 命令仍然可在 systemd 下工作,不過(guò),運(yùn)行級(jí)別對(duì)于 systemd 來(lái)說(shuō)是一個(gè)歷史遺留的概念。所以我建議你全部使用 systemctl 命令。

我們當(dāng)前處于運(yùn)行級(jí)別 3, 它等同于下面顯示的 multi-user.target。

# systemctl list-units --type=target
UNIT     LOAD ACTIVE SUB DESCRIPTION
basic.target   loaded active active Basic System
cloud-config.target loaded active active Cloud-config availability
cryptsetup.target  loaded active active Local Encrypted Volumes
getty.target   loaded active active Login Prompts
local-fs-pre.target loaded active active Local File Systems (Pre)
local-fs.target  loaded active active Local File Systems
multi-user.target  loaded active active Multi-User System
network-online.target loaded active active Network is Online
network-pre.target loaded active active Network (Pre)
network.target  loaded active active Network
paths.target   loaded active active Paths
remote-fs.target  loaded active active Remote File Systems
slices.target   loaded active active Slices
sockets.target  loaded active active Sockets
swap.target   loaded active active Swap
sysinit.target  loaded active active System Initialization
timers.target   loaded active active Timers
贊(0)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享網(wǎng)絡(luò)內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-62778877-8306;郵箱:fanjiao@west.cn。本站原創(chuàng)內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明出處:西部數(shù)碼知識(shí)庫(kù) » 使用chkconfig和systemctl命令啟用或禁用Linux服務(wù)的方法

登錄

找回密碼

注冊(cè)