全部博文(38)
分类: LINUX
2010-06-16 18:03:42
日志文件由系统日志和内核日志监控程序syslogd与klogd控制,在/etc/syslog.conf文件中配置这两个监控程序默认活动。
日志文件按/etc/syslog.conf配置文件中的描述进行组织。下图是/etc/syslog.conf文件的内容:
[root@localhost ~]# cat /etc/syslog.conf # Log all kernel messages to the console. # Logging much else clutters up the screen. #kern.* /dev/console # Log anything (except mail) of level info or higher. # Don't log private authentication messages! *.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 higher in a special file. uucp,news.crit /var/log/spooler # Save boot messages also to boot.log local7.* /var/log/boot.log |
/etc/syslog.conf文件
syslog.conf行的基本语法是:
[消息类型][处理方案]
注意:中间的分隔符必须是Tab字符!
消息类型是由"消息来源"和"紧急程度"构成,中间用点号连接。例如上图中,news.crit表示来自news的“关键”状况。在这里,news是消息来源,crit代表关键状况。通配符*可以代表一切消息来源。
说明:
第一条语句*.info,将info级以上(notice,warning,err,crit,alert与emerg)的所有消息发送到相应日志文件。
日志文件类别(按重要程度分类)
日志文件可以分成八大类,下面按重要性从大到下列出:
emerg emergency,紧急
alert 警报
crit critical,关键
err error,错误
warning 警告
notice 通知
info 信息
debug 调试
简单列一下消息来源
auth 认证系统,如login或su,即询问用户名和口令
cron 系统执行定时任务时发出的信息
daemon 某些系统的守护程序的 syslog,如由in.ftpd产生的log
kern 内核的信息
lpr 打印机的信息
mail 处理邮件的守护进程发出的信息
mark 定时发送消息的时标程序
news 新闻组的守护进程的信息
user 本地用户的应用程序的信息
uucp uucp子系统的信息
* 表示所有可能的信息来源
系统日志
大多数日志位于/var/log目录中。日志通过标准cron任务logrotate维护,每周轮换日志文件。这样,/var/log/boot.log.1文件是上周的文件。
下图是我的fedora core3 /var/log目录中的内容:
[root@localhost var]# ls /var/log acpid cups maillog.1 scrollkeeper.log vbox anaconda.log dmesg messages secure welcome.msg anaconda.syslog gdm messages.1 secure.1 wtmp boot.log iiim ppp spooler Xorg.0.log boot.log.1 lastlog prelink.log spooler.1 Xorg.0.log.old cron mail rpmpkgs up2date cron.1 maillog rpmpkgs.1 up2date.1 |
May 22 12:15:39 localhost syslog: syslogd startup succeeded May 22 12:15:39 localhost syslog: klogd startup succeeded May 22 12:15:39 localhost irqbalance: irqbalance startup succeeded May 22 12:15:40 localhost portmap: portmap startup succeeded May 22 12:15:40 localhost nfslock: rpc.statd startup succeeded May 22 12:15:37 localhost sysctl: net.ipv4.conf.default.rp_filter = 1 May 22 12:15:37 localhost sysctl: net.ipv4.conf.default.accept_source_route = 0 May 22 12:15:37 localhost sysctl: kernel.sysrq = 0 May 22 12:15:40 localhost rpcidmapd: rpc.idmapd startup succeeded May 22 12:15:37 localhost sysctl: kernel.core_uses_pid = 1 May 22 12:15:37 localhost network: Setting network parameters: succeeded May 22 12:15:37 localhost network: Bringing up loopback interface: succeeded May 22 12:15:40 localhost netfs: Mounting other filesystems: succeeded May 22 12:15:41 localhost autofs: automount startup succeeded May 22 12:15:41 localhost mDNSResponder: startup succeeded May 22 12:15:42 localhost smartd: smartd startup succeeded May 22 12:15:42 localhost acpid: acpid startup succeeded May 22 12:15:44 localhost cups: cupsd startup succeeded May 22 12:15:44 localhost sshd: succeeded May 22 12:15:44 localhost xinetd: xinetd startup succeeded May 22 12:15:45 localhost sendmail: sendmail startup succeeded May 22 12:15:45 localhost sendmail: sm-client startup succeeded May 22 12:15:45 localhost gpm: gpm startup succeeded May 22 12:15:45 localhost iiim: htt startup succeeded May 22 12:15:46 localhost crond: crond startup succeeded May 22 12:15:47 localhost xfs: xfs startup succeeded May 22 12:15:47 localhost anacron: anacron startup succeeded May 22 12:15:47 localhost atd: atd startup succeeded May 22 12:15:47 localhost readahead: Starting background readahead: May 22 12:15:48 localhost rc: Starting readahead: succeeded May 22 12:15:48 localhost messagebus: messagebus startup succeeded May 22 12:15:48 localhost cups-config-daemon: cups-config-daemon startup succeeded May 22 12:15:49 localhost haldaemon: haldaemon startup succeeded May 22 13:20:59 localhost cups: cupsd shutdown succeeded May 22 13:21:03 localhost cups: cupsd startup succeeded |
[5] [02879] [4 ] [ ] [ ] [2.6.9-1.667 ] [0.0.0.0 ] [Mon May 22 12:15:49 2006 CST] [6] [02909] [5 ] [LOGIN ] [tty5 ] [ ] [0.0.0.0 ] [Mon May 22 12:15:49 2006 CST] [5] [02909] [5 ] [ ] [ ] [2.6.9-1.667 ] [0.0.0.0 ] [Mon May 22 12:15:49 2006 CST] [5] [02920] [6 ] [ ] [ ] [2.6.9-1.667 ] [0.0.0.0 ] [Mon May 22 12:15:49 2006 CST] [6] [02920] [6 ] [LOGIN ] [tty6 ] [ ] [0.0.0.0 ] [Mon May 22 12:15:50 2006 CST] [5] [02921] [x ] [ ] [ ] [2.6.9-1.667 ] [0.0.0.0 ] [Mon May 22 12:15:50 2006 CST] [7] [03397] [:0 ] [root ] [:0 ] [ ] [0.0.0.0 ] [Mon May 22 12:16:08 2006 CST] [7] [03630] [/0 ] [root ] [pts/0 ] [:0.0 ] [0.0.0.0 ] [Mon May 22 12:26:34 2006 CST] [7] [03700] [/0 ] [root ] [pts/0 ] [:0.0 ] [0.0.0.0 ] [Mon May 22 12:47:56 2006 CST] [7] [04458] [/0 ] [root ] [pts/0 ] [:0.0 ] [0.0.0.0 ] [Mon May 22 13:55:24 2006 CST] |
[root@localhost log]# cat /var/log/cron May 22 13:23:29 localhost anacron[2721]: Job `cron.daily' terminated May 22 13:23:29 localhost anacron[2721]: Normal exit (1 jobs run) May 22 14:01:01 localhost crond[4482]: (root) CMD (run-parts /etc/cron.hourly) May 22 15:01:01 localhost crond[4536]: (root) CMD (run-parts /etc/cron.hourly) |
/var/log/cron文件
从图中可以看出执行cron任务的日期和时间。这是标准cron任务。尽管这里的时间与/etc/crontab中指定的不同,但这只表明这台Linux计算机没有在指定的时间运行。
说明:
在Linux系统中增加更多监控程序时,/var/log目录中会出现更多日志文件。但是,日志文件也不一定放在/var/log目录中,这是由每个监控程序的配制文件确定的。
其他日志
在/var/log目录中还有几个其它日志文件。增加更多服务时,会出现更多日志文件。
Linux的系统停止与重启动命令详解
按照正确的过程来关闭Linux系统是很重要的。如果你没有这样做,你的文件系统很可能会变得毫无价值并且文件也会变得混乱。这是因为Linux有一个磁盘缓冲,它不会将数据立刻写入磁盘的,而是在一定的间隔时间。这极大地改进了性能,但也意味着如果你随意地关闭电源,此时缓冲中可能保存着许多数据并且磁盘上的数据会不完全而不能成为一个完整运行的文件系统(因为只有一些数据被写入硬盘)。
说明:
[root@localhost ~]# cat /boot/grub/grub.conf # grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You do not have a /boot partition. This means that # all kernel and initrd paths are relative to /, eg. # root (hd0,9) # kernel /boot/vmlinuz-version ro root=/dev/hda10 # initrd /boot/initrd-version.img #boot=/dev/hda default=1 timeout=30 splashimage=(hd0,9)/boot/grub/splash.xpm.gz hiddenmenu title Fedora Core (2.6.9-1.667) root (hd0,9) kernel /boot/vmlinuz-2.6.9-1.667 ro root=LABEL=/ rhgb quiet initrd /boot/initrd-2.6.9-1.667.img title Other rootnoverify (hd0,0) chainloader +1 |