So useful! Run the systemd command to manage the Linux system!

Source: Internet
Author: User
Tags comparison table

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.

  1. [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:

  1. [Root @ linoxide ~] # Systemd-analyze

The same content can be displayed using the time parameter.

  1. [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.

  1. [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.

  1. [Root @ linoxide ~] # Systemctl

Or

  1. [Root @ linoxide ~] # Systemctl list-units

2.2 list failed units

Units that fail to run can be displayed using commands with the -- failed option.

  1. [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.

  1. [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.

  1. [Root @ linoxide ~] # Systemctl status dnsmasq

3.3 start a service

Run the following command to start the service.

  1. [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.

  1. [Root @ linoxide ~] # Systemctl stop dnsmasq

3.5 restart a service

Similarly, 'systemctl restart' is used to restart system services.

  1. [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.

  1. [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 ):

  1. [Root @ linoxide ~] # Systemctl status dnsmasq. service

! Click_multi!

For more details, please continue to read the highlights on the next page:

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.