Use the systemd Management System On Debian

Source: Internet
Author: User
Tags comparison table syslog

Use the systemd Management System On Debian

Humans can no longer prevent systemd from occupying Linux systems around the world. The only way to stop it is to manually uninstall it on your own machine. Until now, systemd has created more technical, emotional, and social problems than any software. This point can be seen from the battle for Linux Initialization software. This debate lasted for several months between Debian developers. When the Debian Technical Committee finally decided to put systemd in the release of Debian 8 (codenamed Jessie), its opponents tried to replace the resolution through multiple efforts, some even threatened to threaten the life security of developers who support systemd.

This also shows that systemd has a great deal of interference with the system processing methods inherited by Unix. The Philosophical Thought of "One software only does one thing" has been thoroughly overturned by this newcomer. In addition to replacing sysvinit as a new system initialization tool, systemd is also a system management tool. So far, thanks to the compatibility provided by the systemd-sysv package, the tools we used can continue to work. However, when Debian upgrades systemd to version 214, this compatibility will no longer exist. Upgrade measures are expected to be performed on the stable branch of Debian 8 "Jessie. From then on, you must use new commands to manage the system, execute tasks, change the running level, and query system logs. However, there is a solution, that is, adding some aliases in the. bashrc file.

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

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

Now let's take a look at how systemd changes your management system habits. Before using systemd, you must save sysvinit so that you can start the system with sysvinit when the systemd fails. This method takes effect only when systemd-sysv is not installed. The specific operation is as follows:

  1. # Cp-av/sbin/init. sysvinit

In an emergency, you can take the following text:

  1. Init =/sbin/init. sysvinit

Add to kernel startup parameters.

Basic usage of systemctl

The function of systemctl is to replace the commands such as "/etc/init. d/foo start/stop". In addition, it can do other things. You can refer to man documentation for this.

Some basic usage:

  • Systemctl-list all units and their statuses (here the UNIT refers to the job and service on the system)
  • Systemctl list-units-list all units
  • Systemctl start [NAME...]-start one or more units
  • Systemctl stop [NAME...]-stop one or more units
  • Systemctl disable [NAME...]-set UNIT to not start
  • Systemctl list-unit-files-list all installed units and their statuses
  • Systemctl -- failed-list units that fail to start
  • Systemctl -- type = mount-lists certain types of units, including: service, mount, device, socket, target
  • Systemctl enable debug-shell.service-set a shell script to boot for debugging

To make it easier to process these units, you can use the systemd-ui package. You only need to enter the systemadm command to use this software.

You can also use systemctl to convert the running level, restart the system, and disable the system:

  • Systemctl isolate graphical.tar get-switch to running level 5, that is, there is a desktop running level
  • Systemctl isolate multi-user.target-switch to runlevel 3, no desktop runlevel
  • Systemctl reboot-restart the system
  • Systemctl poweroff-Shutdown

All commands, including commands for switching to other running levels, can be executed with the permissions of common users.

Basic usage of journalctl

Systemd not only provides faster startup speed than sysvinit, but also enables the log system to start up earlier, logs of kernel initialization, memory initialization, startup steps, and major system execution processes can be recorded. So the days that used to take photos of the display or pause the system to debug the program are gone forever.

Logs of systemd are stored in the/var/log directory. If you want to use its log function, you need to execute some commands because Debian does not enable the log function. The command is as follows:

  1. # Addgroup -- system systemd-journal
  2. # Mkdir-p/var/log/journal
  3. # Chown root: systemd-journal/var/log/journal
  4. # Gpasswd-a $ user defined EMD-journal

With the above settings, you can use the journal software to view logs with common user permissions. Using journalctl to query logs can be used more conveniently than syslog software:

  • Journalctl -- all-display all logs on the system and its users
  • Journalctl-f-Monitor System log Changes (similar to the effect of tail-f/var/log/messages)
  • Journalctl-B-display logs after system startup
  • Journalctl-k-B-1-display the kernel logs generated before the previous (-B-1) system startup
  • Journalctl-B-p err-displays the "ERROR" log generated after the system is started.
  • Journalctl -- since = yesterday-this command provides shorter log records than-B when the system does not restart frequently
  • Journalctl-u cron. service -- since = '2017-07-06 '-- until = '2017-07-06'-displays the logs printed by the cron service within a certain period of time
  • Journalctl-p 2 -- since = today-displays logs with a priority of less than 2, including emerg, alert, and crit. All log levels include: emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6 ), debug (7)
  • Journalctl> yourlog. log-copy the binary log file into a text file and save it to the current directory.

Journal and syslog can coexist well. On the other hand, once you get used to journal operations, you can also Uninstall all syslog software, such as rsyslog or syslog-ng.

To obtain more detailed log information, add "systemd. log_level = debug" to the kernel startup parameters and run the following command:

  1. # Journalctl-alb

You can also edit the/etc/systemd/system. conf file to modify the log level.

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.