linux syslog 使用例子,Linux系统syslog

大纲

一、日志系统之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:off1:off2:on3:on4:on5:on6: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级别的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值