Nxlog日志采集配置手册.docx
《Nxlog日志采集配置手册.docx》由会员分享,可在线阅读,更多相关《Nxlog日志采集配置手册.docx(11页珍藏版)》请在冰豆网上搜索。
Nxlog日志采集配置手册
文档编号:
Nxlog日志采集配置手册
2017年3月10日
文档控制
作者:
审核:
标准化:
读者:
版本控制
版本
提交日期
相关组织和人员
版本描述
1.0
2017年3月10日
创建文档
1.Nxlog安装
1.1Windows操作系统安装
软件版本:
nxlog-ce-2.9.1716.msi
支持操作系统:
winxp-win2012
安装步骤:
双击安装包,一键安装
安装目录路径:
Ø64位操作系统:
C:
\ProgramFiles(x86)\nxlog
Ø32位操作系统
C:
\ProgramFiles\nxlog
配置文件路径:
C:
\ProgramFiles(x86)\nxlog\conf\nxlog.conf#此文件非常重要,基本所有操作都在此文件进行
Nxlog日志文件路径:
C:
\ProgramFiles(x86)\nxlog\data\nxlog.log#此文件用来排查问题,确认nxlog运行是否正常
注意:
如果操作系统是32位的,则nxlog安装路径默认为C:
\ProgramFiles\nxlog,此时需要修改配置文件:
否则nxlog服务无法启动。
1.2Linux/Centos操作系统安装
1.3AIX
2.Nxlog配置
Nxlog配置分为输入(Input)、输出(Output)、路径(Route);
输入为需要采集的数据源;
输出为日志需要发往的目的地,比如文件、数据库、日志服务器,在我们的环境中一般为探针地址。
2.1Windows操作系统
2.1.1Windows操作系统日志采集
Modulexm_syslog#收集事件日志,所有的事件日志默认都被收集
#如果包含多个输入,名称可以修改,如in1、in2等
Moduleim_msvistalog
#Forwindows2003andearlierusethefollowing:
#如果是win2003或以前的操作系统,需要使用下面的Module
#Moduleim_mseventlog
#配置输出
Moduleom_udp#安装完默认为om_tcp,需要修改成om_udp
Host10.16.106.33#探针地址
Port514
Pathin=>out#源输入对应输出
2.1.2Windows下文本文件日志采集
文本文件如中间件日志(apache、tomcat、IIS等)。
注:
此处为一行代表一条日志
修改配置文件输入即可:
SavePosfalse#记录读取位置,默认为True
Readfromlastfalse#从最后一行开始读,默认为True
Moduleim_file
File"E:
\\03PaserFile\\web-mysql-logs\\apache_error.log"#文件路径
2.1.3使用通配符
文件读取支持通配符,如果目录下有多个文件,则可以使用通配符,使用通配符的时候注意转义,如:
‘C:
\test\\*.log’
‘C:
\\test\\*.log’
若要使用双引号,则应为:
“C:
\\test\\\\*.log”
此功能其它操作系统同样适用,不再赘述;
2.1.4Windows下CSV格式日志采集
Modulexm_csv
Fields$id,$name,$number#文件包含的所有字段名
#FieldTypesinteger,string,integer
Delimiter,
Moduleim_file
File"C:
\\Users\\chengtao\\Downloads\\test.csv"
Execparse_csv();
Moduleom_udp
Host10.16.106.33
Port514
Pathfilein=>out
2.1.5Windows下多行日志采集
Modulexm_multiline
HeaderLine/^\[\w{3}\s\w{3}\s\d{2}\s\d{2}:
\d{2}:
\d{2}\.\d{6}\s\d{4}\]/#日志开始标志
SavePosfalse
Readfromlastfalse
Moduleim_file
InputTypemultiline
File"E:
\\03PaserFile\\web-mysql-logs\\apache_error.log"
2.1.6nxlog采集数据过滤
if$raw_event!
~/^%%/drop();#如果日志不是以“%%”开始,则丢弃;
或者:
Modulexm_exec
Moduleim_file
File"C:
\\dnsredir\\dailylogs\\\\*.txt"
SavePosTRUE
Execifnot($raw_event=~/^%%/)drop();
2.1.7日志编码转换
Modulexm_charconv
AutodetectCharsetsutf-8,euc-jp,utf-16,utf-32,iso8859-2,GB2312,GBK
Moduleim_file
File"tmp/input"
Execconvert_fields("AUTO","utf-8");
2.1.8添加日志标识
如果一个主机需要发送多类日志,且日志格式比较接近,为了防止日志解析出现问题,则需要对采集的日志添加标识。
Moduleim_file
SavePosfalse
ReadFromLastfalse
File"/var/log/secure"
Exec$raw_event='linuxlog'+$raw_event;
2.1.9读取日志文件后删除文件
Modulexm_exec
Modulexm_fileop
Every1min
Execfile_remove('C:
\\www\\data\\soc\\'+strftime((now()-86400),"%Y%m%d")+'*.csv');#删除前一天日志文件
2.1.10设置nxlog日志文件重写
#defineLOGFILEC:
\ProgramFiles\nxlog\data\nxlog.log
defineLOGFILE/var/log/nxlog/nxlog.log
Modulexm_fileop
#Checkthesizeofourlogfileeveryhourandrotateifitislargerthan1Mb
Every1hour
Execif(file_size(’%LOGFILE%’)>=1M)file_cycle(’%LOGFILE%’,2);
#Rotateourlogfileeveryweekonsundayatmidnight
When@weekly
Execfile_cycle(’%LOGFILE%’,2);
1.1Centos/Redhat操作系统
1.1.1Apache访问日志
/etc/nxlog.conf
##Thisisasampleconfigurationfile.Seethenxlogreferencemanualaboutthe
##configurationoptions.Itshouldbeinstalledlocallyunder
##/usr/share/doc/nxlog-ce/andisalsoavailableonlineat
##http:
//nxlog.org/docs
########################################
#Globaldirectives#
########################################
Usernxlog
Groupnxlog
LogFile/var/log/nxlog/nxlog.log
LogLevelINFO
NocacheTrue
########################################
#Modules#
########################################
Modulexm_syslog
SavePosTRUE
ReadfromlastTRUE
Moduleim_file
File"/var/log/apache/access.log"
Moduleom_udp
Host10.16.106.33
Port514
########################################
#Routes#
########################################
#
Pathapache_access_in=>apache_access_out
1.1.2Apache访问日志
如果日志为多行,则请参考2.1.5
##Thisisasampleconfigurationfile.Seethenxlogreferencemanualaboutthe
##configurationoptions.Itshouldbeinstalledlocallyunder
##/usr/share/doc/nxlog-ce/andisalsoavailableonlineat
##http:
//nxlog.org/docs
########################################
#Globaldirectives#
########################################
Usernxlog
Groupnxlog
LogFile/var/log/nxlog/nxlog.log
LogLevelINFO
NocacheTrue
########################################
#Modules#
########################################
Modulexm_syslog
SavePosfalse
Readfromlastfalse
Moduleim_file
File"/var/log/apache/error.log"
Moduleom_tcp
Hostlocalhost
Port25555
########################################
#Routes#
########################################
#
Pathapache_error_in=>apache_error_out