This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19103|Reply: 1

[linux] Linux looks at the log output of the Systemd service

[Copy link]
Posted on 11/15/2021 10:15:19 AM | | | |
systemd is the latest initialization system (init) of the Linux system, which is to improve the startup speed of the system, start as few processes as possible, and start as many processes as possible at the same time.

The process management command corresponding to systemd is systemctl

Check the service status through the systemctl command, and you can see the log output, the command is as follows:



The logs output by the service are written to/var/log/messageInside the file, you can view it with the journalctl command. journalctl can view all system log files, and due to the large amount of log information, journalctl also provides various parameters to help users locate log information more quickly.

journalctl common command

View all logs

By default, only the logs of this startup are saved

journalctl

View kernel logs (no application logs)

journalctl -k

.View the log of the system startup

journalctl   -b

journalctl  -b  -0

Review the log of the last launch

If you need to change the settings, such as the last system crash, you need to look at the last boot log when you need to view the logs.

journalctl  -b -1

View the log for the specified time

journalctl --since="2012-10-3018:17:16"

journalctl --since "20 minago"

journalctl --since yesterday

journalctl --since"2015-01-10" --until "2015-01-11 03:00"

journalctl --since 09:00 --until"1 hour ago"

journalctl --since"15:15" --until now

Displays the last 10 lines of the log at the tail

journalctl  -n

Displays a log with a specified number of rows at the end

I was looking at the logs in /var/log/messages, but the format was adjusted, such as the hostname format was different

journalctl -n 20

Real-time scrolling to display the latest logs

journalctl   -f

View logs for the specified service

journalctl  /usr/lib/systemd/systemd

View the logs for the specified process

journalctl   _PID=1

View the logs of scripts for a certain path

journalctl    /usr/bin/bash

View the logs of the specified user

journalctl _UID=33  --since today

Check the logs of a certain unit

journalctl  -u nginx.service

journalctl  -u nginx.service  --since  today

Real-time scrolling displays the latest log for a Unit

journalctl -u pmm-agent.service -f



Merge logs showing multiple units

journalctl  -u nginx.service  -u php-fpm.service  --since today





Previous:Spring Boot Kafka restarts to discard old data
Next:Install curl based on Debian (docker image).
 Landlord| Posted on 2/7/2025 9:03:37 AM |
systemd service log export
Export logs for systemd services

--since Export logs for the last 24 hours of the nginx service

-v View the detailed logs of the nginx service

The logs of the nginx service are exported in JSON format

Continuously export logs
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com