Linux journald相关:修订间差异

来自三线的随记
(Admin移动页面Linux journal日志保存到文件Linux journald相关,不留重定向)
无编辑摘要
第18行: 第18行:
  [root@compute-2 ~]# cat /etc/redhat-release  
  [root@compute-2 ~]# cat /etc/redhat-release  
  CentOS Linux release 7.6.1810 (Core)
  CentOS Linux release 7.6.1810 (Core)


=== Links ===
https://www.freedesktop.org/software/systemd/man/journalctl.html


默认保存到 /run/log 下面
=== Save to files ===
- 令 journald 保存到文件中


对于某些场景的日志记录不足以满足需求
默认journald保存到 /run/log/journal 下面
 
该保存策略只有本次开机后的日志
 
对于某些场景的日志记录不足以满足需求(如机器异常关机,重新开机读取不了上一次的journal)




第30行: 第36行:
等一会日志就会迁移到/var/log/journal下面了
等一会日志就会迁移到/var/log/journal下面了


不需要重启services
不需要重启任何services
 
<br />
<br />


=== commands ===
=== Save to /run/log ===
- 令 journald 只记录从开机后到目前的信息
systemctl stop systemd-journald.socket
 
systemctl stop systemd-journald.service
(注意区分先后顺序,先 stop systemd-journald.socket 再 stop systemd-journald.service )
 
因为
Warning: Stopping systemd-journald.service, but it can still be activated by:
  systemd-journald.socket
 
mv /var/log/journal /root/
 
systemctl start systemd-journald.socket
这时候 systemd-journald.service 应该也 be activated 了
 
journalctl --list-boots 也可以看到只有开机后的日志信息了
<br />
===Related Commands===
  journalctl --list-boots
  journalctl --list-boots


第40行: 第65行:
  journalctl -b ********* -n ***
  journalctl -b ********* -n ***


  journalctl -u ****
  journalctl -u **** # -u --unit=UNIT          Show logs from the specified unit
<br />
 
==== To Be Continued ====
how to cancel it ? wdnmd
 


journalctl -D  #从指定目录读取日志文件(会被整合) -D --directory=PATH      Show journal files from directory
[[分类:Linux]]
[[分类:Linux]]

2019年12月26日 (四) 14:18的版本

[root@compute-2 ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

[root@compute-2 ~]# cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)

Links

https://www.freedesktop.org/software/systemd/man/journalctl.html

Save to files

- 令 journald 保存到文件中

默认journald保存到 /run/log/journal 下面

该保存策略只有本次开机后的日志

对于某些场景的日志记录不足以满足需求(如机器异常关机,重新开机读取不了上一次的journal)


mkdir /var/log/journal

等一会日志就会迁移到/var/log/journal下面了

不需要重启任何services


Save to /run/log

- 令 journald 只记录从开机后到目前的信息

systemctl stop systemd-journald.socket
systemctl stop systemd-journald.service

(注意区分先后顺序,先 stop systemd-journald.socket 再 stop systemd-journald.service )

因为

Warning: Stopping systemd-journald.service, but it can still be activated by:
  systemd-journald.socket
mv /var/log/journal /root/
systemctl start systemd-journald.socket

这时候 systemd-journald.service 应该也 be activated 了

journalctl --list-boots 也可以看到只有开机后的日志信息了

Related Commands

journalctl --list-boots
journalctl -b *********
journalctl -b ********* -n ***
journalctl -u ****  # -u --unit=UNIT           Show logs from the specified unit
journalctl -D  #从指定目录读取日志文件(会被整合) -D --directory=PATH      Show journal files from directory