So useful! Run the systemd command to manage the Linux system!
Systemd is a new linux System Service Manager.
It replaces the init system and can manage the system startup process and some system services. once started, it will supervise the entire system. In this article, we use centos 216 installed with systemd 7.0. The latest version can be downloaded from freeyuntop.org.
Linux boot mode: systemd upstart sysV
Why is systemd so quickly adopted?
Systemd and sysVinit Color comparison table
Linux Kernel EMD -- start/stop/restart the service in RHEL/CentOS 7
Because of this newcomer in the linux operating system, PID 1 is occupied by "systemd", which can be seen through the pstree command.
- [Root @ linoxide ~] # Pstree
Now let's explore what systemd is good at and how likely it is to become a new alternative to sysVinit.
1. Faster startup
Sysvinit starts the process one by one at a time.
While Systemd starts the system service process in parallel, and initially only starts those services that are actually dependent, greatly reducing the system boot time.
You can use the following command to view the system boot time:
- [Root @ linoxide ~] # Systemd-analyze
The same content can be displayed using the time parameter.
- [Root @ linoxide ~] # Systemd-analyze time
If you want to print out a list of all running units by sorting the time occupied by process initialization, The systemd-analyze command can help you complete this task.
- [Root @ linoxide ~] # Systemd-analyze blame
The screenshot above only shows a small part of the process. You can use arrows to scroll the list like the less page splitter.
2. systemctl command
The systemctl command has been widely discussed since the emergence of systemd. You can use this command to manage your entire system. Let's explore this command further.
2.1 list units
The systemctl command can contain list-units, or does not contain any options to list all running units.
- [Root @ linoxide ~] # Systemctl
Or
- [Root @ linoxide ~] # Systemctl list-units
2.2 list failed units
Units that fail to run can be displayed using commands with the -- failed option.
- [Root @ linoxide ~] # Systemctl -- failed
You can see the usage of systemctl in many parts of this article.
3. Management Service
Let's take a look at how systemd manages system services.
3.1 activated services
All activated services can be viewed using the following command.
- [Root @ linoxide ~] # Systemctl list-units-t service
3.2 service status
In sysvinit, we can use the "service" command to manage services, but in systemd, we use the systemctl command. We can use the following command to check whether the service is running.
- [Root @ linoxide ~] # Systemctl status dnsmasq
3.3 start a service
Run the following command to start the service.
- [Root @ linoxide ~] # Systemctl start dnsmasq
Corresponds to the service command, which is not output. But there is no doubt that we can check the status of the service that has just been started again to check whether it has been started successfully.
3.4 stop a service
Now, you must know how to use commands in systemd to close the service.
- [Root @ linoxide ~] # Systemctl stop dnsmasq
3.5 restart a service
Similarly, 'systemctl restart' is used to restart system services.
- [Root @ linoxide ~] # Systemctl restart dnsmasq
3.6 reload a service
When we need to reload the service configuration file and do not want to restart the service (such as ssh), we can use this command.
- [Root @ linoxide ~] # Systemctl reload sshd
Although the syntax of the above commands can work, the official documentation suggests that we use the following syntax to run commands (LCTT annotation, even if it is used after the service name to keep up with ". service ):
- [Root @ linoxide ~] # Systemctl status dnsmasq. service
! Click_multi!
For more details, please continue to read the highlights on the next page: