说明:
CentOS 7 以后版,利用Systemd 统一管理所有 Unit 的启动日志。可以只用journalctl一个命令,查看所有日志(内核日志和应用日志)。
journalctl配置文件:
/etc/systemd/journald.conf
journalctl用法:
查看系统的所有日志:
[root@LogServer log]# journalctl
查看最后的几行日志:
[root@LogServer log]# journalctl -f
-- Logs begin at Fri 2022-09-30 08:01:27 CST. --
Oct 20 10:01:01 LogServer anacron[33999]: Anacron started on 2022-10-20
Oct 20 10:01:01 LogServer anacron[33999]: Will run job `cron.daily' in 36 min.
Oct 20 10:01:01 LogServer anacron[33999]: Jobs will be executed sequentially
Oct 20 10:01:01 LogServer run-parts[34001]: (/etc/cron.hourly) finished 0anacron
Oct 20 10:08:53 LogServer nss[841]: Enumeration requested but not enabled
Oct 20 10:37:01 LogServer anacron[33999]: Job `cron.daily' started
Oct 20 10:37:01 LogServer run-parts[34344]: (/etc/cron.daily) starting logrotate
Oct 20 10:37:01 LogServer run-parts[34349]: (/etc/cron.daily) finished logrotate
Oct 20 10:37:01 LogServer anacron[33999]: Job `cron.daily' terminated
Oct 20 10:37:01 LogServer anacron[33999]: Normal exit (1 job run)
查看指定进程的日志:
[root@LogServer log]# journalctl _PID=2
-- Logs begin at Fri 2022-09-30 08:01:27 CST, end at Thu 2022-10-20 10:08:53 CST. --
-- No entries --
查看指定unit的日志:
[root@LogServer log]# journalctl -u mysqld
-- Logs begin at Fri 2022-09-30 08:01:27 CST, end at Thu 2022-10-20 10:08:53 CST. --
Oct 18 23:04:31 CentOS8.cc systemd[1]: Starting MySQL 8.0 database server...
Oct 18 23:04:31 CentOS8.cc mysql-prepare-db-dir[27080]: Initializing MySQL database
Oct 18 23:04:37 CentOS8.cc systemd[1]: Started MySQL 8.0 database server.
实时显示某个unit的日志:
[root@LogServer log]# journalctl -u mysqld -f
查看指定用户的日志
[root@LogServer log]# journalctl _UID=0
查看系统启动日志:
journalctl -b
查看系统内核日志:
[root@LogServer log]# journalctl -k
标签:10,01,20,管理工具,LogServer,journalctl,日志,Oct
From: https://www.cnblogs.com/heyongshen/p/16808951.html