2015.11.07_16_03_Linux日志系统syslog

来源:互联网 发布:来须苍真 知乎 编辑:程序博客网 时间:2024/06/14 19:55

linux上的日志系统有两个:
syslog
syslog-ng:ng :表示下一代,表示下一代的日志系统,有开源版本和商业版。
红帽子5上还是syslog,而红帽子6上,已经改为syslog-ng了。
syslog是一个服务,专门提供日志服务。
它有2个进程:syslogd:系统,非内核产生的信息
klogd:专门负责记录内核产生的日志信息

内核日志:kernel->物理终端(/dev/console) –>/var/log/dmesg
查看日志命令:dmesg 这个命令是专门看这个文件的。
和cat /var/log/dmesg看到的内容是一样的。

/sbin/init产生的日志都是非内核日志
/var/log/messages:系统标准错误日志信息,非内核产生引导信息,各子系统产生的信息
日志需要滚动,会把原来的messages命名为messages.1,然后重新开一个messages。
日志滚动就是日志切割,有一个专门的程序帮忙日志切割的:logrotate
计划任务中就有一个任务是负责进行日志切割的:ls /etc/cron.daily/
可以看到其中有一个计划任务:logrotate。
可以看看这个脚本:vim /etc/cron.daily/logrotate

#!/bin/sh/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1EXITVALUE=$?if [ $EXITVALUE != 0 ]; then    /usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"fiexit 0

/etc/logrotate.conf是它的配置文件:

vim /etc/logrotate.conf#see "man logrotate" for details# rotate log files weeklyweekly  #一周分割一次# keep 4 weeks worth of backlogsrotate 4    #只保留4个版本# create new (empty) log files after rotating old onescreate  #当日志滚动完成,创建一个新的日志# use date as a suffix of the rotated filedateext# uncomment this if you want your log files compressed#compress# RPM packages drop log rotation information into this directoryinclude /etc/logrotate.d #包含另一个文件# no packages own wtmp and btmp -- we'll rotate them here/var/log/wtmp {    monthly #按月滚动 以上是全局定义 如果某一个日志文件没定义,则使用默认定义。    create 0664 root utmp  #创建一个新的文件,权限是0664    minsize 1M  #最小大小    rotate 1  #保留几个历史版本}/var/log/btmp {    missingok    monthly    create 0600 root utmp    rotate 1}#system-specific logs may be also be configured here.

cd /etc/logrotate.d/
ls
cups dracut httpd ppp psacct sssd syslog wpa_supplicant yum
这是对应到每一个子系统

可以打开一个看看:
cat cups

/var/log/cups/*_log {    missingok    notifempty    sharedscripts}

/var/log/maillong:邮件系统产生的日志信息;
/var/log/secure; 可以看看这个文件的权限:

 ll /var/log/secure-rw-------. 1 root root 2990 117 12:31 /var/log/secure

查看一下:

[root@localhost logrotate.d]# tail /var/log/secure
Nov 7 12:17:36 localhost pam: gdm-password[2005]: pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=:0 ruser= rhost= user=root
Nov 7 12:17:46 localhost unix_chkpwd[2126]: password check failed for user (root)
Nov 7 12:17:46 localhost pam: gdm-password[2123]: pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=:0 ruser= rhost= user=root
Nov 7 12:18:05 localhost unix_chkpwd[2129]: password check failed for user (root)
Nov 7 12:18:05 localhost pam: gdm-password[2127]: pam_unix(gdm-password:auth): authentication failure; logname= uid=0 euid=0 tty=:0 ruser= rhost= user=root
Nov 7 12:18:13 localhost pam: gdm-password[2130]: pam_unix(gdm-password:session): session opened for user root by (uid=0)
Nov 7 12:18:13 localhost polkitd(authority=local): Unregistered Authentication Agent for session /org/freedesktop/ConsoleKit/Session1 (system bus name :1.24, object path /org/gnome/PolicyKit1/AuthenticationAgent, locale zh_CN.UTF-8) (disconnected from bus)
Nov 7 12:18:19 localhost polkitd(authority=local): Registered Authentication Agent for session /org/freedesktop/ConsoleKit/Session2 (system bus name :1.54 [/usr/libexec/polkit-gnome-authentication-agent-1], object path /org/gnome/PolicyKit1/AuthenticationAgent, locale zh_CN.UTF-8)
Nov 7 12:31:34 localhost sshd[3033]: Accepted password for root from 192.168.25.108 port 1673 ssh2
Nov 7 12:31:34 localhost sshd[3033]: pam_unix(sshd:session): session opened for user root by (uid=0)

syslog的两个服务:syslogdklogd 是开机启动的吗?
chkconfig –list syslog

service syslog status:查看syslog的服务的状态
syslog配置文件:/etc/syslog.conf
这个文件的格式:

0 0
原创粉丝点击