Table of Contents
Usage of systemctl command
Systemctl command introduction:" >Systemctl command introduction:
Common usage of Systemctl command: " >Common usage of Systemctl command:
Service命令用法" >Service命令用法
chkconfig命令用法
Home Operation and Maintenance Linux Operation and Maintenance Detailed explanation of the differences between systemctl, service and chkconfig commands under Linux

Detailed explanation of the differences between systemctl, service and chkconfig commands under Linux

Jan 29, 2023 pm 05:01 PM
linux

This article brings you relevant knowledge about Linux. It mainly introduces the relationship between systemctl and service and chkconfig commands, as well as the differences. Let’s take a look at them together. I hope it will be helpful to everyone.

Detailed explanation of the differences between systemctl, service and chkconfig commands under Linux

The relationship between systemctl and service and chkconfig commands

  • systemctl command: It is a systemd tool, mainly responsible for controlling the systemd system and service manager.
  • service command: You can start, stop, restart, and shut down system services, and you can also display the current status of all system services.
  • chkconfig command: It is a command line tool for managing system services (service). The so-called system service (service) is a program that starts when the system starts and closes when the system shuts down.

The systemctl command is a system service manager command, which actually combines the two commands service and chkconfig.

systemctl is the main tool among the service management tools of RHEL 7. It integrates the functions of the previous service and chkconfig. You can use it to enable/disable services permanently or only for the current session.

So the systemctl command is a collection and replacement of the service command and the chkconfig command.

For example: using service to start the service actually calls the systemctl command.

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

Usage of systemctl command

Systemctl is a systemd tool, mainly responsible for controlling the systemd system and service manager.

Systemd is a collection of system management daemons, tools and libraries used to replace the System V initial process. The function of Systemd is to centrally manage and configure UNIX-like systems.

Systemd is system daemon, which is an init software under Linux.

(1) List all available units:

[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
Copy after login

(2) List all available units:

[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
 ..............
Copy after login

(3) List all failed units:

[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'.
Copy after login

(4) Check whether a unit is started:

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

(5) Check the running status of a service:

[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
Copy after login

(6) List all services:

[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
Copy after login

(7) Start, stop, restart services, etc.:

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

(8) Check whether the service is activated and configured Start up:

[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.
Copy after login

(9) Use the systemctl command to kill the service:

[root@localhost ~]# systemctl kill httpd
Copy after login

(10) List the various services, mounts, devices, etc. of the system:

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

(11) Obtain the system default startup level and set the default startup level:

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

(12) Start the running level:

systemctl isolate multiuser.target
Copy after login

(13) Restart, stop, suspend, hibernate the system, etc.:

# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep
Copy after login

Service命令用法

service命令可以启动、停止、重新启动和关闭系统服务,还可以显示所有系统服务的当前状态。

service命令的作用是去/etc/init.d目录下寻找相应的服务,进行开启和关闭等操作。

使用示例:

开启关闭一个服务:service httpd start/stop

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

查看系统服务的状态: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
Copy after login

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>
Copy after login

(一)设置service开机是否启动:

chkconfig name on/off/reset
Copy after login
  • on、off、reset用于改变service的启动信息。
  • on表示开启,off表示关闭,reset表示重置。
  • 默认情况下,on和off开关只对运行级2,3,4,5有效,reset可以对所有运行级有效。

[root@localhost ~]# chkconfig httpd on
注意:正在将请求转发到“systemctl enable httpd.service”。
Copy after login

在Redhat7上,运行chkconfig命令,都会被转到systemcle命令上。

(2)设置service运行级别:

chkconfig --level levels
Copy after login

该命令可以用来指定服务的运行级别,即指定运行级别2,3,4,5等。

  • 等级0表示:表示关机
  • 等级1表示:单用户模式
  • 等级2表示:无网络连接的多用户命令行模式
  • 等级3表示:有网络连接的多用户命令行模式
  • 等级4表示:不可用
  • 等级5表示:带图形界面的多用户模式
  • 等级6表示:重新启动

例如:

[root@localhost ~]# chkconfig --level 5 httpd on
注意:正在将请求转发到“systemctl enable httpd.service”
Copy after login

(三)列出service启动信息:

# chkconfig --list [name]
Copy after login

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

每个service每个运行级别都会有一个启动和停止脚本;当切换运行级别时,init不会重启已经启动的service,也不会重新停止已经停止的service。

例如:

[root@localhost ~]# chkconfig --list

注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 
      如果您想列出 systemd 服务,请执行 &#39;systemctl list-unit-files&#39;。
      欲查看对特定 target 启用的服务请执行
      &#39;systemctl list-dependencies [target]&#39;。

netconsole      0:关    1:关    2:关    3:关    4:关    5:关    6:关
network         0:关    1:关    2:开    3:开    4:开    5:开    6:关
rhnsd           0:关    1:关    2:开    3:开    4:开    5:开    6:关
Copy after login

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

推荐学习:《Linux视频教程

The above is the detailed content of Detailed explanation of the differences between systemctl, service and chkconfig commands under Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

deepseek web version entrance deepseek official website entrance deepseek web version entrance deepseek official website entrance Feb 19, 2025 pm 04:54 PM

DeepSeek is a powerful intelligent search and analysis tool that provides two access methods: web version and official website. The web version is convenient and efficient, and can be used without installation; the official website provides comprehensive product information, download resources and support services. Whether individuals or corporate users, they can easily obtain and analyze massive data through DeepSeek to improve work efficiency, assist decision-making and promote innovation.

How to install deepseek How to install deepseek Feb 19, 2025 pm 05:48 PM

There are many ways to install DeepSeek, including: compile from source (for experienced developers) using precompiled packages (for Windows users) using Docker containers (for most convenient, no need to worry about compatibility) No matter which method you choose, Please read the official documents carefully and prepare them fully to avoid unnecessary trouble.

Ouyi okx installation package is directly included Ouyi okx installation package is directly included Feb 21, 2025 pm 08:00 PM

Ouyi OKX, the world's leading digital asset exchange, has now launched an official installation package to provide a safe and convenient trading experience. The OKX installation package of Ouyi does not need to be accessed through a browser. It can directly install independent applications on the device, creating a stable and efficient trading platform for users. The installation process is simple and easy to understand. Users only need to download the latest version of the installation package and follow the prompts to complete the installation step by step.

BITGet official website installation (2025 beginner's guide) BITGet official website installation (2025 beginner's guide) Feb 21, 2025 pm 08:42 PM

BITGet is a cryptocurrency exchange that provides a variety of trading services including spot trading, contract trading and derivatives. Founded in 2018, the exchange is headquartered in Singapore and is committed to providing users with a safe and reliable trading platform. BITGet offers a variety of trading pairs, including BTC/USDT, ETH/USDT and XRP/USDT. Additionally, the exchange has a reputation for security and liquidity and offers a variety of features such as premium order types, leveraged trading and 24/7 customer support.

Get the gate.io installation package for free Get the gate.io installation package for free Feb 21, 2025 pm 08:21 PM

Gate.io is a popular cryptocurrency exchange that users can use by downloading its installation package and installing it on their devices. The steps to obtain the installation package are as follows: Visit the official website of Gate.io, click "Download", select the corresponding operating system (Windows, Mac or Linux), and download the installation package to your computer. It is recommended to temporarily disable antivirus software or firewall during installation to ensure smooth installation. After completion, the user needs to create a Gate.io account to start using it.

Ouyi Exchange Download Official Portal Ouyi Exchange Download Official Portal Feb 21, 2025 pm 07:51 PM

Ouyi, also known as OKX, is a world-leading cryptocurrency trading platform. The article provides a download portal for Ouyi's official installation package, which facilitates users to install Ouyi client on different devices. This installation package supports Windows, Mac, Android and iOS systems. Users can choose the corresponding version to download according to their device type. After the installation is completed, users can register or log in to the Ouyi account, start trading cryptocurrencies and enjoy other services provided by the platform.

How to automatically set permissions of unixsocket after system restart? How to automatically set permissions of unixsocket after system restart? Mar 31, 2025 pm 11:54 PM

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Why does an error occur when installing an extension using PECL in a Docker environment? How to solve it? Apr 01, 2025 pm 03:06 PM

Causes and solutions for errors when using PECL to install extensions in Docker environment When using Docker environment, we often encounter some headaches...

See all articles