利用rsyslog对非系统日志进行远程传输
环境说明:
系统:CentOS 6.5
rsyslog版本:5.8.10
在客户端的/etc/rsyslog.conf添加如下信息:
$ModLoad imfile # needs to be done just once 引入模板
# logstash - test - remote send file.
$InputFileName /opt/logstash-5.3.1/logs/logstash-plain.log #指定监控日志文件
$InputFilePollInterval 10 #指定每10秒轮询一次文件
$InputFileTag logstash-test #指定文件的tag
$InputFileStateFile /var/lib/rsyslog/logstash-test.log #指定状态文件存放位置,如不指定会报错。
$InputFileSeverity info #设置监听日志级别
$InputFileFacility local0 #指定设备
$InputRunFileMonitor #启动此监控,没有此项,上述配置不生效。
*.* @@目标ip:端口 #远程发送源tcp协议远程发送
代码说明:
利用以上模板对客户端内应用日志进行监控,并将日志文件每十秒扫描一次,发送至远程服务器,可以在远程服务器配置过滤条件,将日志文件进行分级别保存。
在服务器端的/etc/rsyslog.conf里面配置如下信息:
#指定使用设备名称和日志级别对系统日志进行过滤,日志文件名是年月日时.log
$template RemoteSyslogfacility-textSys,"/data/log/%syslogfacility-text%/%syslogseverity-text%/%$year%_%$month%_%$day%_%$hour%.log"
:syslogfacility-text, !isequal, "local0" ?RemoteSyslogfacility-textSys
#指定使用设备名称、日志tag信息和日志级别对系统日志进行过滤,日志文件名是年月日时.log
$template RemoteSyslogfacility-textApp,"/data/log/%syslogfacility-text%/%syslogtag%/%syslogseverity-text%/%$year%_%$month%_%$day%_%$hour%.log"
:syslogfacility-text, isequal, "local0" ?RemoteSyslogfacility-textApp
上述配置通过模板指定过滤条件,过滤条件可以自己指定。
参考:
远程配置信息:http://www.rsyslog.com/doc/v5-stable/configuration/modules/imfile.html
模板官方文档:http://www.rsyslog.com/doc/v5-stable/configuration/templates.html
模板属性:http://www.rsyslog.com/doc/v5-stable/configuration/properties.html