In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces the relevant knowledge of "how to use systemd tools to manage the system on Debian". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
The philosophy of "one software only does one thing" has been completely subverted by this newcomer. In addition to replacing sysvinit as the new system initialization tool, systemd is also a system management tool. So far, because of the compatibility provided by the systemd-sysv package, the tools we are used to can continue to work. But when Debian upgraded systemd to version 214, this compatibility no longer existed. Upgrade measures are expected to take place on the stable branch of Debian 8 "Jessie". Henceforth users must use new commands to manage the system, perform tasks, change run levels, query system logs, and so on. However, here is a solution, which is to add some aliases to the .bashrc file.
Now let's take a look at how systemd changes the way you manage your system. Before using systemd, you have to save the sysvinit so that you can boot the system with sysvinit in the event of an systemd error. This method takes effect only if systemd-sysv is not installed. The specific operation method is as follows:
The code is as follows:
# cp-av / sbin/init / sbin/init.sysvinit
In case of emergency, you can put the following text:
The code is as follows:
Init=/sbin/init.sysvinit
Add to the kernel startup parameter item.
The basic usage of systemctl
The function of systemctl is to replace commands such as "/ etc/init.d/foo start/stop". In addition, it can also do other things, which you can refer to the man documentation.
Some basic uses:
Systemctl-lists all units (UNIT) and their status (UNIT here refers to job and service on the system)
Systemctl list-units-list all UNIT
Systemctl start [NAME...]-start one or more UNIT
Systemctl stop [NAME...]-stop one or more UNIT
Systemctl disable [NAME...]-sets UNIT to boot and does not boot
Systemctl list-unit-files-lists all installed UNIT and their status
Systemctl-- failed-lists the UNIT that failed to boot
Systemctl-- type=mount-lists a certain type of UNIT, which includes: service, mount, device, socket, target
Systemctl enable debug-shell.service-set a shell script to boot for debugging
To make it easier to deal with these UNIT, you can use the systemd-ui package, which you can use simply by typing the systemadm command.
You can also use systemctl to change runlevels, restart the system, and shut down the system:
Systemctl isolate graphical.target-switch to runlevel 5, which is the runlevel with desktops
Systemctl isolate multi-user.target-switch to runlevel 3, without the runlevel of the desktop
Systemctl reboot-restart the system
Systemctl poweroff-shutdown
All commands, including those that switch to other runlevels, can be executed under the authority of a normal user.
The basic usage of journalctl
Systemd not only provides faster startup speed than sysvinit, but also allows the logging system to start earlier, recording kernel initialization phases, memory initialization phases, pre-boot steps, and major system execution logs. So gone are the days when you needed to debug programs by taking pictures of the screen or pausing the system.
The log files for systemd are placed in the / var/log directory. If you want to use its logging function, you need to execute some commands because Debian does not turn on the logging function. The command is as follows:
The code is as follows:
# addgroup-system systemd-journal
# mkdir-p / var/log/journal
# chown root:systemd-journal / var/log/journal
# gpasswd-a $user systemd-journal
With the above settings, you can use journal software to view logs with normal user privileges. Using journalctl to query logs can get some more convenient ways to play than syslog software:
Journalctl-- all-- displays all logs on the system and its users
Journalctl-f-monitors changes in Syslog (similar to tail-f / var/log/messages effect)
Journalctl-b-displays the log after the system starts
Journalctl-k-b-1-displays kernel logs generated before the last (- b-1) system boot
Journalctl-b-p err-displays the "ERROR" log generated after the system boots
Journalctl-- since=yesterday-this command provides shorter logging than-b when the system does not restart frequently
Journalctl-u cron.service-- since='2014-07-06 07since='2014 00'-- until='2014-07-06 08since='2014 23'-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 are: emerg (0), alert (1), crit (2), err (3), warning (4), notice (5), info (6), debug (7)
Journalctl > yourlog.log-copy the binary log file to a text file and save it to the current directory
Journal and syslog can coexist well. On the other hand, once you are used to operating journal, you can also uninstall all syslog software, such as rsyslog or syslog-ng.
If you want more detailed log information, you can add "systemd.log_level=debug" to the kernel startup parameters and run the following command:
The code is as follows:
# journalctl-alb
You can also edit the / etc/systemd/system.conf file to change the log level.
Using systemd to analyze the startup process of the system
Systemd allows you to analyze and optimize your system startup process more effectively:
Systemd-analyze-shows the time spent in user mode and kernel state during this boot process
Systemd-analyze blame-displays a breakdown of the time spent on each startup item
Systemd-analyze critical-chain-print UNIT trees in chronological order
Systemd-analyze dot | dot-Tsvg > systemd.svg-generate a vector diagram for the boot process (graphviz package is required)
Systemd-analyze plot > bootplot.svg-generate the time chart of the boot process
Although systemd is a young project, it has a lot of documentation. The first thing I would like to introduce to you is Lennart Poettering's 0pointer series. This series is very detailed and technical. The other is the free desktop information document, which contains the most detailed links to systemd: the release feature file, the bug tracking system, and documentation. You can use the following command to query which documents are provided by systemd:
The code is as follows:
# man systemd.index
The commands provided by systemd between different distributions are basically the same, with the biggest difference being the packaging method.
This is the end of the content of "how to use systemd tools to manage the system on Debian". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.