久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

Linux的systemctl、service與chkconfig命令有什么區別

204次閱讀
沒有評論

共計 7263 個字符,預計需要花費 19 分鐘才能閱讀完成。

本篇內容介紹了“Linux 的 systemctl、service 與 chkconfig 命令有什么區別”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓丸趣 TV 小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

systemctl 和 service、chkconfig 命令的關系

systemctl 命令:是一個 systemd 工具,主要負責控制 systemd 系統和服務管理器。

service 命令:可以啟動、停止、重新啟動和關閉系統服務,還可以顯示所有系統服務的當前狀態。

chkconfig 命令:是管理系統服務 (service) 的命令行工具。所謂系統服務(service),就是隨系統啟動而啟動,隨系統關閉而關閉的程序。

systemctl 命令是系統服務管理器指令,它實際上將 service 和 chkconfig 這兩個命令組合到一起。

systemctl 是 RHEL 7 的服務管理工具中主要的工具,它融合之前 service 和 chkconfig 的功能于一體??梢允褂盟谰眯曰蛑辉诋斍皶捴袉⒂?/ 禁用服務。

所以 systemctl 命令是 service 命令和 chkconfig 命令的集合和代替。

例如:使用 service 啟動服務實際上也是調用 systemctl 命令。

[root@localhost ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service

systemctl 命令的用法 Systemctl 命令簡介:

Systemctl 是一個 systemd 工具,主要負責控制 systemd 系統和服務管理器。

Systemd 是一個系統管理守護進程、工具和庫的集合,用于取代 System V 初始進程。Systemd 的功能是用于集中管理和配置類 UNIX 系統。

systemd 即為 system daemon, 是 linux 下的一種 init 軟件。

Systemctl 命令常見用法:

(1)列出所有可用單元:

[root@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  
sys-kernel-config.mount                    static  
sys-kernel-debug.mount                     static  
tmp.mount                                  disabled
var-lib-nfs-rpc_pipefs.mount               static  
brandbot.path                              disabled
cups.path                                  enabled

(2)列出所有可用單元:

[root@localhost ~]# systemctl list-units
 UNIT                      LOAD      ACTIVE SUB       DESCRIPTION
 proc-sys-fs-binfmt_misc.automount loaded    active waiting   Arbitrary
 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda
 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda
 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:0-2:0:0:0-block-sda
 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:1-2:0:1:0-block-sdb
 sys-devices-pci0000:00-0000:00:10.0-host2-target2:0:1-2:0:1:0-block-sdb
 sys-devices-pci0000:00-0000:00:11.0-0000:02:01.0-net-ens33.device loade
 sys-devices-pci0000:00-0000:00:11.0-0000:02:02.0-sound-card0.device lo
..............

(3)列出所有失敗單元:

[root@localhost ~]# systemctl --failed 
 UNIT                LOAD   ACTIVE SUB    DESCRIPTION
● network.service     loaded failed failed LSB: Bring up/down networking
● teamd@team0.service loaded failed failed Team Daemon for device team0

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB
SUB    = The low-level unit activation state, values depend on unit type.

2 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use systemctl list-unit-files .

(4)檢查某個單元是否啟動:

[root@localhost ~]# systemctl is-enabled httpd.service 
enabled

(5)檢查某個服務的運行狀態:

[root@localhost ~]# systemctl status httpd.service     
● httpd.service - The Apache HTTP Server
  Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
  Active: active (running) since 日 2018-10-14 18:21:46 CST; 1 day 2h ago
    Docs: man:httpd(8)
          man:apachectl(8)
Main PID: 19020 (httpd)
  Status: Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec
  CGroup: /system.slice/httpd.service
          ├─19020 /usr/sbin/httpd -DFOREGROUND
          ├─27310 /usr/sbin/httpd -DFOREGROUND
          ├─27311 /usr/sbin/httpd -DFOREGROUND
          ├─27312 /usr/sbin/httpd -DFOREGROUND
          ├─27313 /usr/sbin/httpd -DFOREGROUND
          └─27314 /usr/sbin/httpd -DFOREGROUND

10 月 14 18:21:46 localhost systemd[1]: Starting The Apache HTTP Serv....
10 月 14 18:21:46 localhost httpd[19020]: AH00558: httpd: Could not r...e

(6)列出所有服務:

[root@localhost ~]# systemctl list-unit-files --type=service
UNIT FILE                                  STATE  
abrt-ccpp.service                          enabled
abrt-oops.service                          enabled
abrt-pstoreoops.service                    disabled
abrt-xorg.service                          enabled
abrtd.service                              enabled
accounts-daemon.service                    enabled
alsa-restore.service                       static  
alsa-state.service                         static  
alsa-store.service                         static  
arp-ethers.service                         disabled
atd.service                                disabled
auditd.service                             enabled
auth-rpcgss-module.service                 static

(7)啟動,停止,重啟服務等:

[root@localhost ~]# systemctl restart httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service

(8)查詢服務是否激活,和配置是否開機啟動:

[root@localhost ~]# systemctl is-active httpd
active
[root@localhost ~]# systemctl disable httpd
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@localhost ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

(9)使用 systemctl 命令殺死服務:

[root@localhost ~]# systemctl kill httpd

(10)列出系統的各項服務,掛載,設備等:

[root@localhost ~]# systemctl list-unit-files --type 
automount  device     path       snapshot   swap       timer
busname    mount      service    socket     target

(11)獲得系統默認啟動級別和設置默認啟動級別:

[root@localhost ~]# systemctl get-default 
graphical.target
[root@localhost ~]# systemctl set-default multi-user.target

(12)啟動運行等級:

systemctl isolate multiuser.target

(13)重啟、停止,掛起、休眠系統等:

# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep

Service 命令用法

service 命令可以啟動、停止、重新啟動和關閉系統服務,還可以顯示所有系統服務的當前狀態。

service 命令的作用是去 /etc/init.d 目錄下尋找相應的服務,進行開啟和關閉等操作。

使用示例:

開啟關閉一個服務:service  httpd  start/stop

[root@localhost ~]# service httpd start
Redirecting to /bin/systemctl start  httpd.service

查看系統服務的狀態:service –status-all

[root@localhost ~]# service --status-all
未加載 netconsole 模塊
已配置設備:
lo ens33 ens33.old team0 team0-port1 team0-port1.old team0-port2 team0-port2.old team0.old
當前活躍設備:
lo ens33 virbr0 ens38 ens39 team0
● rhnsd.service - LSB: Starts the Spacewalk Daemon
  Loaded: loaded (/etc/rc.d/init.d/rhnsd; bad; vendor preset: disabled)
  Active: active (running) since 五 2018-10-12 14:53:19 CST; 3 days ago
    Docs: man:systemd-sysv-generator(8)
Main PID: 1380 (rhnsd)
  CGroup: /system.slice/rhnsd.service
          └─1380 rhnsd

chkconfig 命令用法

chkconfig 是管理系統服務 (service) 的命令行工具。所謂系統服務(service),就是隨系統啟動而啟動,隨系統關閉而關閉的程序。

chkconfig 可以更新 (啟動或停止) 和查詢系統服務 (service) 運行級信息。更簡單一點,chkconfig 是一個用于維護 /etc/rc[0-6].d 目錄的命令行工具。

chkconfig 常見用法:

[root@localhost ~]# chkconfig  --help
chkconfig 版本 1.7.2 - 版權 (C) 1997-2000 紅帽公司
在 GNU 公共許可條款下,本軟件可以自由重發行。

用法:  chkconfig [--list] [--type 類型] [名稱]
        chkconfig --add 名稱
        chkconfig --del 名稱
        chkconfig --override 名稱
        chkconfig [--level 級別] [--type 類型] 名稱 on|off|reset|resetpriorities

(一)設置 service 開機是否啟動:

chkconfig name on/off/reset

on、off、reset 用于改變 service 的啟動信息。

on 表示開啟,off 表示關閉,reset 表示重置。

默認情況下,on 和 off 開關只對運行級 2,3,4,5 有效,reset 可以對所有運行級有效。

[root@localhost ~]# chkconfig httpd on
注意:正在將請求轉發到“systemctl enable httpd.service”。

在 Redhat7 上,運行 chkconfig 命令,都會被轉到 systemcle 命令上。

(2)設置 service 運行級別:

chkconfig --level levels

該命令可以用來指定服務的運行級別,即指定運行級別 2,3,4,5 等。

等級 0 表示:表示關機

等級 1 表示:單用戶模式

等級 2 表示:無網絡連接的多用戶命令行模式

等級 3 表示:有網絡連接的多用戶命令行模式

等級 4 表示:不可用

等級 5 表示:帶圖形界面的多用戶模式

等級 6 表示:重新啟動

例如:

[root@localhost ~]# chkconfig --level 5 httpd on
注意:正在將請求轉發到“systemctl enable httpd.service”

(三)列出 service 啟動信息:

# chkconfig --list [name]

如果不指定 name,會列出所有 services 的信息。

每個 service 每個運行級別都會有一個啟動和停止腳本;當切換運行級別時,init 不會重啟已經啟動的 service,也不會重新停止已經停止的 service。

例如:

[root@localhost ~]# chkconfig --list

注意:該輸出結果只顯示 SysV 服務,并不包含原生 systemd 服務。SysV 配置數據可能被原生 systemd 配置覆蓋。
      如果您想列出 systemd 服務, 請執行 systemctl list-unit-files。
      欲查看對特定 target 啟用的服務請執行
      systemctl list-dependencies [target]。

netconsole      0: 關    1: 關    2: 關    3: 關    4: 關    5: 關    6: 關
network         0: 關    1: 關    2: 開    3: 開    4: 開    5: 開    6: 關
rhnsd           0: 關    1: 關    2: 開    3: 開    4: 開    5: 開    6: 關

總結:service 命令的功能基本都被 systemct 取代。直接使用 systemctl 命令即可。

“Linux 的 systemctl、service 與 chkconfig 命令有什么區別”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注丸趣 TV 網站,丸趣 TV 小編將為大家輸出更多高質量的實用文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-12發表,共計7263字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 赫章县| 灌南县| 朝阳县| 辉南县| 若羌县| 依安县| 厦门市| 诸暨市| 广德县| 安泽县| 青铜峡市| 安乡县| 灵璧县| 平度市| 东宁县| 米易县| 九江县| 内乡县| 秦皇岛市| 洛川县| 垦利县| 宝山区| 广南县| 禄劝| 左云县| 宿松县| 永顺县| 安岳县| 玛曲县| 清水县| 页游| 北京市| 堆龙德庆县| 启东市| 壶关县| 临湘市| 南漳县| 黑龙江省| 陇西县| 田阳县| 禹城市|