Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use the systemctl command

2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of how to use the systemctl command, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value. I believe you will gain something after reading this systemctl command how to use the article. Let's take a look.

Systemd is the latest initialization system (init) of Linux system. Its function is to improve the startup speed of the system, start as few processes as possible, and start as many processes concurrently as possible. The corresponding process management command of systemd is systemctl.

Use the systemctl command Start/Stop/Restart/Reload service

When starting the service using systemctl, the command format is: systemctl start [service-name]. For example, start the firewalld service:

[root@localhost ~] # systemctl start firewalld

In contrast to the service command in previous versions of linux, the systemctl start command does not output anything.

To stop the service, use systemctl stop [service-name]. For example, stop the firewalld service:

[root@localhost ~] # systemctl stop firewalld

To restart the service, use systemctl restart [service-name], for example:

[root@localhost ~] # systemctl restart firewalld

To reload the configuration of the service (for example, ssh) without restarting it, use systemctl reload [service-name], for example:

[root@localhost ~] # systemctl reload sshdsystemctl check service status

To see if the service is running, we can use systemctl status [service-name] to see.

[root@localhost ~] # systemctl status firewalld check whether the service is set to boot

To enable the service at boot time, use systemctl enable [service-name], for example:

[root@localhost] # systemctl enable httpd.serviceCreated symlink from / etc/systemd/system/multi-user.target.wants/httpd.service to / usr/lib/systemd/system/httpd.service.

Similarly, enable the service when you cancel booting on disable:

[root@localhost ~] # systemctl disable httpd.service

You can use the is-enabled option to check whether the service is started or not, run:

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

The output enabled indicates that the service is started on boot, and disabled indicates that the service is not started on boot.

Systemctl list unit

To list all active units, use the list-units option.

[root@localhost ~] # systemctl list-units

To list all active services, run:

[root@localhost ~] # systemctl list-units-t service uses systemctl to restart and shut down the system

Like the poweroff and shutdown commands, the systemctl command can shut down the system, restart, or go into hibernation.

Power off:

[root@localhost ~] # systemctl poweroff

Restart:

[root@localhost ~] # systemctl reboot

System hibernation:

[root@localhost ~] # systemctl hibernate uses systemclt to manage remote systems

Typically, all of the above systemctl commands can be used to manage remote hosts through the systemctl command itself. This will use ssh to communicate with the remote host. As follows:

[root@localhost] # systemctl status httpd-H root@192.168.0.12

The-H option specifies the user name and password of the remote host.

Manage Targets

Systemd has the concept of Targets, and the purpose of these Targets is similar to the run level in sysVinit systems. The running level in sysVinit is mainly numeric (0meme1mem2mai 6). The following are the runlevels in sysVinit and the target in their corresponding systemd:

0 runlevel0.target, poweroff.target1 runlevel1.target, rescue.target2,3,4 runlevel2.target, runlevel3.target,runlevel4.target, multi-user.target5 runlevel5.target, graphical.target6 runlevel6.target, reboot.target

If you want to see the current run level, you can use the following command:

[root@localhost ~] # systemctl get-defaultmulti-user.target

Set the default run level to graphical, with the following command:

[root@localhost] # systemctl set-default graphical.targetRemoved symlink / etc/systemd/system/default.target.Created symlink from / etc/systemd/system/default.target to / usr/lib/systemd/system/graphical.target.

To list all activated target, use the following command:

Other commands of the [root@localhost ~] # systemctl list-units-t targetsystemd tool journalctl log collection

Systemd has its own logging system, called journald. It replaces syslogd in sysVinit.

[root@localhost ~] # journalctl

To view all boot messages, run the command journalctl-b

[root@localhost] # journalctl-b

The following command tracks the system log in real time (similar to tail-f):

[root@localhost ~] # journalctl-f query the duration of the system startup process [root@localhost ~] # systemd-analyzeStartup finished in 497ms (kernel) + 1.836s (initrd) + 6.567s (userspace) = 8.901s

Finally, it shows that the startup time of the system is 8.901 seconds.

View the startup time of the service:

[root@localhost ~] # systemd-analyze blamehostnamectl command

View the host name:

[root@localhost ~] # hostnamectl, this is the end of the article on "how to use the systemctl command". Thank you for reading! I believe you all have a certain understanding of the knowledge of "how to use systemctl commands". If you want to learn more, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report