linux日志系统小结

日志系统:

syslog服务包括三大类:

         syslogd系统日志--配置一些系统应用的日志类型级别和存储地址。

         klogd 内核--内核启动信息存储下来。

         logrotate日志转储--日志的周期性处理。

1、查看/etc/rsyslog.conf,可以看到系统日志文件配置信息如下:

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                /dev/console
 
# Log anything (except mail) of level infoor higher.
# Don't log private authenticationmessages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages
 
# The authpriv file has restricted access.
authpriv.*                                             /var/log/secure
 
# Log all the mail messages in one place.
mail.*                                                 -/var/log/maillog
 
# Log cron stuff
cron.*                                                 /var/log/cron
 
# Everybody gets emergency messages
*.emerg                                                *
 
# Save news errors of level crit and higherin a special file.
uucp,news.crit                                         /var/log/spooler
 
# Save boot messages also to boot.log
local7.*                                               /var/log/boot.log
 


我们需要先了解一下系统日志级别,就明白配置文件的内容了。

priority 日志级别

         debug调试程序产生的信息

         info一般信息

         notice不影响正常功能,需要注意

         warn警告,影响部分功能

         error错误信息

         crit严重的,例如磁盘错误

         alert马上处理,例如系统数据库损坏。

         emerg/oanic系统不可用,紧急信息

         *所有

         none没有优先级                                                                         

所有的系统应用都会在 /var/log 目录下创建日志文件,或创建子目录再创建日志文件

/var/log/boot.log

开启或重启日志。

/var/log/cron

计划任务日志

/var/log/maillog

邮件日志。

/var/log/messages

该日志文件是许多进程日志文件的汇总,从该文件可以看出任何入侵企图或成功的入侵。

/var/log/httpd 目录

Apache HTTP 服务日志。

/var/log/samba 目录

samba 软件日志

 

然后返回来去看conf里面的内容就可以知道每行内容的含义。


2、内核日志:

kernel-->物理终端(/dev/console)-->/var/log/dmesg

#dmesg 可以查看物理内核的启动信息。只列出一部分,因为内容太多。

md: raid0 personality registered for level 0
bio: create slab <bio-1> at 1
md/raid0:md127: md_size is 6453248 sectors.
md: RAID0 configuration for md127 - 1 zone
md: zone0=[sdb5/sdb8]
      zone-offset=         0KB, device-offset=         0KB, size=   3226624KB

md127: detected capacity change from 0 to 3304062976
 md127: unknown partition table
EXT4-fs (sda1): mounted filesystem with ordered data mode. Opts: 
SELinux: initialized (dev sda1, type ext4), uses xattr
Adding 983036k swap on /dev/sda3.  Priority:-1 extents:1 across:983036k 
SELinux: initialized (dev binfmt_misc, type binfmt_misc), uses genfs_contexts
fuse init (API version 7.14)
SELinux: initialized (dev fuse, type fuse), uses genfs_contexts
NET: Registered protocol family 10
lo: Disabled Privacy Extensions
ip6_tables: (C) 2000-2006 Netfilter Core Team
nf_conntrack version 0.5.0 (16384 buckets, 65536 max)
ip_tables: (C) 2000-2006 Netfilter Core Team
e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: None
type=1305 audit(1476667322.754:4): audit_pid=1849 old=0 auid=4294967295 ses=4294967295 subj=system_u:system_r:auditd_t:s0 res=1
eth0: no IPv6 routers present
802.1Q VLAN Support v1.8 Ben Greear <greearb@candelatech.com>
All bugs added by David S. Miller <davem@redhat.com>
8021q: adding VLAN 0 to HW filter on device eth0
eth0: no IPv6 routers present


3、日志转储:

logrotate 的主要配置文件是/etc/logrotate.conf,/etc/logrotate.d 目录是对 /etc/logrotate.conf 的补充,或者说为了不使 /etc/logrotate.conf 过大而设置。

可以通过 cat 命令查看它的内容:

$cat /etc/logrotate.conf

# see "man logrotate" fordetails  //可以查看帮助文档
# rotate log files weekly
weekly                             //设置每周转储一次
# keep 4 weeks worth of backlogs
rotate 4                           //最多转储4次
# create new (empty) log files afterrotating old ones
create                             //当转储后文件不存储时创建它
# uncomment this if you want your log filescompressed
#compress                          //以压缩方式转储
# RPM packages drop log rotationinformation into this directory
include /etc/logrotate.d           //其他日志文件的转储方式,包含在该目录下
# no packages own wtmp -- we'll rotate themhere
/var/log/wtmp {                    //设置/var/log/wtmp日志文件的转储参数
   monthly                        //每月转储
   create 0664 root utmp          //转储后文件不存在时创建它,文件所有者为root,所属组为utmp,对应的权限为0664
   rotate 1                       //最多转储一次
}


注意:include 允许管理员把多个分散的文件集中到一个,类似于C语言的 #include,将其他文件的内容包含进当前文件。
include 非常有用,一些程序会把转储日志的配置文件放在 /etc/logrotate.d 目录,这些配置文件会覆盖或增加 /etc/logrotate.conf的配置项,如果没有指定相关配置,那么采用 /etc/logrotate.conf 的默认配置。
所以,建议将 /etc/logrotate.conf 作为默认配置文件,第三方程序在 /etc/logrotate.d目录下自定义配置文件。
logrotate 也可以作为命令直接运行来修改配置文件

 

参考地址:http://c.biancheng.net/cpp/html/2783.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值