跳至主要內容

Chapter10 - Analyzing and Storing Logs

Change Lee...大约 2 分钟LinuxRHEL124

Analyzing and Storing Logs

rhel124-10-1.png
*.info;mail.none;authpriv.none;cron.none常规日志messages
authpriv.*认证日志secure
mail.*邮件日志maillog
cron.*任务计划cron
local7.*启动信息boot.log
uucp,news.crit新闻类错误spooler
kern.*内核类/dev/console

可以在/etc/rsyslog.conf里配置额外的日志文件,类型如下表,例如

*.debug   /var/log/messages.debug
rhel124-10-2.png

journalctl

/run/log/journal 默认位置重启后会清除

如果/var/log/journal 存在,则journalctl 会将日志存放过来,存储大小一般不超过当前文件系统的10%,所以要保留15%的空间

/var/log/journal 文件的权限

chown root:systtemd-journal /var/log/journal
chmod 2755 /var/log/journal
drwxr-sr-x. 2 root systemd-journal 6 49 16:33 journal/

重启journald服务:

killall -USR1 systemd-journald

或 reboot

==========================================================

journalctl -n 5     #显示最后5条
journalctl -p err     #指定日志的优先级类型
journalctl -f     #等同于 tail -f

指定日志的日期:

journalctl --since today  
journalctl --since 15:30:00  --until 15:35:00
journalctl --since "2018-04-09 15:30:00" --until "2018-04-09 16:00:00"

查看详情,可是加在其它参数后面或者前面

journalctl -o verbose
journalctl   _SYSTEMD_UNIT=sshd.service   _PID=1182     #查看指定进程或服务的日志
journalctl --since 15:00:00 _SYSTEMD_UNIT=sshd.service

==========================================================

rsyslog

  • /etc/rsyslog.conf
  • /etc/rysylog.d/*.conf
man 5 rsyslog.conf

http:// /usr/share/doc/rsyslog-*/manual.html

==========================================================

logrotate 日志轮巡

  • /etc/logrotate.conf

  • /etc/logrotate.d/*.conf

==========================================================

标准rsyslog格式

Apr  9 14:59:44 client systemd: Starting Session 2 of user root.

#发生的日期  主机  产生日志的程序 :日志内容

==========================================================

logger 程序生成日志记录到文件

logger -p local7.notice "Log entry created on ServerX" #生产notice 日志
logger -p user.debug "debug message test"  #产生debug 日志

==========================================================

时间的维护:

tzselect     #交互式设备时区tz=timezone
timedatectl
timedatectl  list-timezones
timedatectl  set-timezone America/Phoenix
timedatectl  set-timezone Asia/Shanghai
timedatectl  set-time 9:00:00   #(YYYY-MM-DD hh:mm:ss)
timedatectl  set-ntp true/false

==========================================================

Configuring chronyd

/etc/chrony.conf

修改文件中的服务器位置

chronyc souces -v   #验证NTP服务器,并显示详情

ntpd、ntpq 在Redhat7以前使用,用来管理NTP服务器

上次编辑于:
贡献者: change,lichangyangccm@163.com
评论
  • 按正序
  • 按倒序
  • 按热度
Powered by Waline v3.1.3