您的位置:首页 > 运维架构 > Linux

Linux系统syslog

2015-12-05 16:51 726 查看
大纲

一、日志系统之syslog
二、syslog配置文件
三、定义格式实例

一、日志系统之syslog
syslog是Linux系统中默认的日志守护进程,RHEL5上默认是syslog,而RHEL6上则是syslog-ng(next generation),而syslog-ng不仅在配置上有了重大的改变,而且所支持的功能更强大。但是此处我们还是以RHEL5为例,先介绍syslog,以后有时间再介绍syslog-ng。
[root@soysauce ~]# chkconfig --list syslog
syslog         	0:off	1:off	2:on	3:on	4:on	5:on	6:off
[root@soysauce ~]# service syslog status
syslogd (pid  2887) is running...
klogd (pid  2890) is running...

syslogd: 系统,非内核产生的信息
klogd:内核,专门负责记录内核产生的日志信息


二、Syslog服务的配置详解
1、配置文件定义格式:facility.priority action
[root@soysauce ~]# 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;news.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

#
# INN
#
news.=crit                                        /var/log/news/news.crit
news.=err                                         /var/log/news/news.err
news.notice                                       /var/log/news/news.notice
2、配置文件之facility:日志的来源
auth      			                # 认证相关的

authpriv  			                    # 权限,授权相关的

cron      			                # 任务计划相关的

daemon    			                    # 守护进程相关的

kern      			                # 内核相关的

lpr      			                    # 打印相关的

mail     			                    # 邮件相关的

mark     			                    # 标记相关的

news     			                    # 新闻相关的

security 			                    # 安全相关的,与auth 类似

syslog  			                    # syslog自己的

user    			                    # 用户相关的

uucp    			                    # unix to unix cp 相关的

local0 到 local7 	                         # 用户自定义使用

*        			                   # *表示所有的facility
3、配置文件之priority:日志的级别
debug                                   # 程序或系统的调试信息

info                                    # 一般信息

notice                                 # 不影响正常功能,需要注意的消息

warning/warn                            # 可能影响系统功能,需要提醒用户的重要事件

err/error                               # 错误信息

crit                                    # 比较严重的

alert                                   # 必须马上处理的

emerg/panic                             # 会导致系统不可用的

*                                       # 表示所有的日志级别

none                                    # 跟* 相反,表示啥也没有
4、配置文件之action:日志记录的位置
系统上的绝对路径                        # 普通文件 如: /var/log/xxx

|                                       # 管道  通过管道送给其他的命令处理

终端                                  # 终端 如:/dev/console

@HOST                               # 远程主机 如: @10.0.0.1

用户                                  # 系统用户 如: root

*                                   # 登录到系统上的所有用户,一般emerg级别的日志是这样定义的
5、syslog服务脚本配置文件
[root@soysauce ~]# cat /etc/sysconfig/syslog
# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages recieved with -r
# See syslogd(8) for more details
SYSLOGD_OPTIONS="-m 0"                                # 此处添加"-r"即可接受其他主机发来的日志信息并记录
# Options to klogd
# -2 prints all kernel oops messages twice; once for klogd to decode, and
#    once for processing with 'ksymoops'
# -x disables all klogd processing of oops messages entirely
# See klogd(8) for more details
KLOGD_OPTIONS="-x"
#
SYSLOG_UMASK=077
# set this to a umask value to use for all log files as in umask(1).
# By default, all permissions are removed for "group" and "other".


三、定义格式实例
mail.info   /var/log/mail.log      # 表示将mail相关的,级别为info及以上级别的信息记录到mail.log文件中

auth.=info  @10.0.0.1               # 表示将auth相关的,基本为info的信息记录到10.0.0.1主机上去

user.!=error                     # 表示记录user相关的,不包括error级别的信息

user.!error                      # 与user.error相反

*.info                         # 表示记录所有的日志信息的info级别

mail.*                         # 表示记录mail相关的所有级别的信息

*.*                          # 所有子系统所有级别的信息

cron.info;mail.info                  # 多个日志来源可以用";" 隔开

cron,mail.info                     # 与cron.info;mail.info 是一个意思

mail.*;mail.!=info                   # 表示记录mail相关的所有级别的信息,但是不包括info级别的
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  日志 syslog