1、nxlog简介
nxlog是个跨平台日志传输插件,支持linux、windows平台,支持window及linux内置的大部分系统日志及常见的web日志,支持tcp、udp、http(s)等协议传输。
安装包、指导手册及常用配置下载:/s/1qWTc2g0
2、配置目的
通过nxlog将iis日志按syslog以udp的方式发送到linux服务器中作为linux服务器的syslog。
特殊需求:is日志中日期和时间是两个字段,需要合并成一个字段。
3、系统及软件环境
OS:window server r2 Enterprise
IIS:7.5
Nxlog:2.9.1347
4、iis日志格式
5、nxlog配置步骤
1)安装nxlog
默认是安装在C:\Program Files (x86)\nxlog路径下。
2)修改nxlog.conf配置信息
位置:C:\Program Files (x86)\nxlog\conf\nxlog.conf
修改方式:请看下面
3)重启服务
4)验证
验证去data目录下看nxlog.log是否是否有异常,正常应该无异常,仅含启动成功的日志信息
通过资源监视器,看nxlog发送的网络流量是否存在,正常应该有
通过日志平台来验证日志是否发送成功。
6、nxlog配置示例
1)当日志文件都放在一个文件夹,nxlog.conf配置如下
defineROOTC:\ProgramFiles(x86)\nxlogdefineCERTDIR%ROOT%\certModuledir%ROOT%\modulesCacheDir%ROOT%\dataPidfile%ROOT%\data\nxlog.pidSpoolDir%ROOT%\dataLogFile%ROOT%\data\nxlog.log<Extensionw3c>Modulexm_csvFields$datetime,$s-ip,$cs-method,$cs-uri-stem,$cs-uri-query,$c-ip,$csUser-Agent,$cs-Referer,$cs-host,$sc-status,$sc-substatus,$sc-win32-status,$time-takenFieldTypesstring,string,string,string,string,string,string,string,string,string,string,string,stringDelimiter''QuoteChar'"'EscapeControlTRUEUndefValue-</Extension><Extensionsyslog>Modulexm_syslog</Extension><Inputin>Moduleim_file#iis日志目录,文件名支持通配符,文件夹不支持File"D:\iislog\W3SVC1\u_ex*.log"SavePosTRUE#合并iis日志中的时间与日志字段为一个字段Execif$raw_event=~/^#/drop();\else\{\$raw_event=replace($raw_event,'','@',1);\w3c->parse_csv();\$raw_event=replace($raw_event,'',"\t");\$raw_event=replace($raw_event,'@','',1);\}</Input><Outputout>Moduleom_udpHost192.168.108.2Port514Execto_syslog_bsd();</Output><Route1>Pathin=>out</Route>
2)日志文件都放在多个文件夹,nxlog.conf配置如下
defineROOTC:\ProgramFiles(x86)\nxlogdefineCERTDIR%ROOT%\certModuledir%ROOT%\modulesCacheDir%ROOT%\dataPidfile%ROOT%\data\nxlog.pidSpoolDir%ROOT%\dataLogFile%ROOT%\data\nxlog.log<Extensionw3c>Modulexm_csvFields$datetime,$s-ip,$cs-method,$cs-uri-stem,$cs-uri-query,$c-ip,$csUser-Agent,$cs-Referer,$cs-host,$sc-status,$sc-substatus,$sc-win32-status,$time-takenFieldTypesstring,string,string,string,string,string,string,string,string,string,string,string,stringDelimiter''QuoteChar'"'EscapeControlTRUEUndefValue-</Extension><Extensionsyslog>Modulexm_syslog</Extension><Inputin_machine_a>Moduleim_file#iis日志目录,文件名支持通配符,文件夹不支持File'D:\iislog\W3SVC2\u_ex*.log'SavePosTRUE#合并iis日志中的时间与日志字段为一个字段Execif$raw_event=~/^#/drop();\else\{\$raw_event=replace($raw_event,'','@',1);\w3c->parse_csv();\$raw_event=replace($raw_event,'',"\t");\$raw_event=replace($raw_event,'@','',1);\}</Input><Inputin_machine_b>Moduleim_file#iis日志目录,文件名支持通配符,文件夹不支持File'\\192.168.108.3\d$\iislog\W3SVC2\u_ex*.log'SavePosTRUE#合并iis日志中的时间与日志字段为一个字段Execif$raw_event=~/^#/drop();\else\{\$raw_event=replace($raw_event,'','@',1);\w3c->parse_csv();\$raw_event=replace($raw_event,'',"\t");\$raw_event=replace($raw_event,'@','',1);\}</Input><Outputout>Moduleom_udpHost192.168.108.2Port514Execto_syslog_bsd();</Output><Route1>Pathin_machine_a,in_machine_b=>out</Route>
3)支持多个数据源和多个输出
配置多个in及out,可以共用一个path配置输出。
7、nxlog配置过程中出现过的问题
1)nxlog2.8版本发送异常的问题
问题现象
-03-11 21:27:31 ERROR if-else failed at line 50, character 246 in C:\Program Files (x86)\nxlog\conf\nxlog.conf. statement execution has been aborted; procedure 'parse_csv' failed at line 50, character 103 in C:\Program Files (x86)\nxlog\conf\nxlog.conf. statement execution has been aborted; Not enough fields in CSV input, expected 14, got 0 in input ''
导致整个进程无法继续输出日志
解决方法
替换使用2.9.1347版本的nxlog
参考
/question/690/if-else-failed-not-enough-fields
8、性能分析
从使用来看,单台服务器一天内大约会发送4到6G大小的日志到远程linux中,nxlog进程占用的资源如下:cpu占用率一般在0%到3%之间;占用带宽300k-600k/s之间;内存一般小于10M。
总体而言对性能影响较小,注意对带宽的影响。
原文链接:/138487.htm