linux卸载rsyslog,Syslog-ng+Rsyslog收集日志:rsyslog-V5.x版 配置(二)

上一篇我们把日志服务器搭建和配置讲解完成,这节讲rsyslog客户端配置。因为系统默认已经安装rsyslo就不在复数了。只讲配置。

注意:本教程是Rsyslog v5.x版本讲解的,新版V8.x链接地址:点击跳转。

在rsyslog.conf中配置,在文件末尾添加如下,全局远程提交路径:

全局变量配置文件:/etc/rsyslog.conf

局部变量配置文件:/etc/rsyslog.d/*.conf ,比如我们想监控tomcat,还想监控nginx的日志,如果把这些配置都放到全局变量里配置文件里,即不方便维护,也使全局配置文件臃肿,然后,就把tomcat配置写成一个独立文件tomcatlog.conf放到/etc/rsyslog.d/;在把nginx配置文件写成nginxlog.conf,然后每次重启rsyslog是就会加载/etc/rsyslog.d/下的tomcatlog、nginxlog配置文件了,不想监控时,直接删除对应的文件即可。(注意:全局配置文件里$IncludeConfig /etc/rsyslog.d/*.conf要开启,把$前#号删掉就开启),操作完配置文件,一定要重启rsyslog服务。

如果客户端所有日志都提交到一个服务器,可以把IP定义在全局变量里,反之则在相关脚本中定义。

@代表UDF方式传输,@@代表是TCP方式传输。

*.* 左边的*是设备,右边*是类型(正常、一般、紧急等),这个不要理解成系统里的文件名和后缀。

rsyslog模块里O开头是输出模块,比如把数据写到数据库;I开头是输入模块,比如把一个日志读到rsyslog里。

重启日志服务,修改完配置文件一定要重启服务才能生效

测试:

一、查看rsyslog配置是否正确

显示配置成功

wKioL1cVnqTitzypAAA6bEQU7E0063.jpg

二、查看看能否产生日志

打开两个终端ssh窗口,可以通过观察系统中的Rsyslog日志,确定是否正常工作。

客户端手动产生日志

wKiom1cV-SyRvmPmAAAdjkCATE8263.jpg

rsyslog做服务端接收配置说明:

开启接收远程信息:edit /etc/sysconfig/rsyslog with option -r:修改成:SYSLOGD_OPTIONS=”-m 0 -r”默认开启UDP 514端口,请确保防火墙没有阻止

rsyslog配置文件说明:

在其它的节点的 Linux 上配置syslog日志功能,收集系统各方面日志主要包括以下日志内容

格式::日志设备(类型).(连接符号)日志级别   日志处理方式(action)日志设备(可以理解为日志类型):———————————————————————-auth        –pam产生的日志authpriv    –ssh,ftp等登录信息的验证信息cron        –时间任务相关kern        –内核lpr         –打印mail        –邮件mark(syslog)–rsyslog服务内部的信息,时间标识news        –新闻组user        –用户程序产生的相关信息uucp        –unix to unix copy, unix主机之间相关的通讯local 1~7   –自定义的日志设备日志级别:———————————————————————-debug       –有调式信息的,日志信息最多info        –一般信息的日志,最常用notice      –最具有重要性的普通条件的信息warning     –警告级别err         –错误级别,阻止某个功能或者模块不能正常工作的信息crit        –严重级别,阻止整个系统或者整个软件不能正常工作的信息alert       –需要立刻修改的信息emerg       –内核崩溃等严重信息none        –什么都不记录从上到下,级别从低到高,记录的信息越来越少详细的可以查看手册: man 3 syslog连接符号———————————————————————-.xxx: 表示大于等于xxx级别的信息.=xxx:表示等于xxx级别的信息.!xxx:表示在xxx之外的等级的信息Actions

———————————————————————

模板能使用的路径变量:

msg    the MSG part of the message (aka "the message" ;))

rawmsg the message exactly as it was received from the socket.

Should be useful for debugging.

HOSTNAME

hostname from the message

FROMHOST

hostname of the system the message was received from (in a

relay chain, this is the system immediately in front of us and

not necessarily the original sender)

syslogtag

TAG from the message

programname

the "static" part of the tag, as defined by BSD syslogd. For

example, when TAG is "named[12345]", programname is "named".

PRI    PRI part of the message - undecoded (single value)

PRI-text

the PRI part of the message in a textual form (e.g.

"syslog.info")

IUT   the monitorware InfoUnitType - used when talking to a

MonitorWare backend (also for phpLogCon)

syslogfacility

the facility from the message - in numerical form

syslogfacility-text

the facility from the message - in text form

syslogseverityseverity from the message - in numerical form

syslogseverity-textseverity from the message - in text form

timegenerated

timestamp when the message was RECEIVED. Always in high

resolution

timereported

timestamp from the message. Resolution depends on what was

provided in the message (in most cases, only seconds)

TIMESTAMPalias for timereported

PROTOCOL-VERSION

The contents of the PROTOCOL-VERSION field from IETF draft

draft-ietf-syslog-protocol

STRUCTURED-DATA

The contents of the STRUCTURED-DATA field from IETF draft

draft-ietf-syslog-protocol

APP-NAME

The contents of the APP-NAME field from IETF draft draft-ietf-syslog-protocol

PROCID The contents of the PROCID field from IETF draft draft-ietf-syslog-protocol

MSGID  The contents of the MSGID field from IETF draft draft-ietf-syslog-protocol

$NOW   The current date stamp in the format YYYY-MM-DD

$YEAR  #年The current year (4-digit)

$MONTH #月The current month (2-digit)

$DAY   #日The current day of the month (2-digit)

$HOUR  #时 The current hour in military (24 hour) time (2-digit)

$MINUTE The current minute (2-digit)

使用样例:

%HOSTNAME%        #主机名

%$YEAR%

%$MONTH%

%$DAY%

%$HOUR%

%timegenerated%

%syslogtag%

%property%

———————————————————————-

其他相关路径:

/etc/rc.d/init.d/rsyslog   #开机启动项

/etc/sysconfig/rsyslog    #接收远程信息配置

/etc/pki/rsyslog

/lib64/rsyslog    #64位库

/var/lib/rsyslog

/var/spool/rsyslog

/var/log/rsyslog    #日志文件夹

/var/lock/subsys/rsyslog

参考文章:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值