我想通过nginx发送日志到rsyslog,但似乎没有被发送。
这里是nginx conf,我定义了一个自定义的日志格式,
log_format rsyslog '$remote_addr - $remote_user [$time_iso8601] "$request "' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/api_access.log rsyslog; access_log syslog:server=localhost:514 rsyslog; error_log /var/log/nginx/api_error.log debug;
我也将这些日志存储在文件中,并发送到rsyslog也。
alphauser@AlphaServer:/etc/rsyslog.d$ sudo netstat -nulp | grep 514 udp 0 0 0.0.0.0:514 0.0.0.0:* 41335/rsyslogd udp6 0 0 :::514 :::* 41335/rsyslogd
rsyslog udp端口514已打开。
这里是rsyslogconfiguration,
template(name="all-json-nginx" type="list"){ constant(value="{ ") constant(value="\"level\":\"") property(name="syslogseverity-text") constant(value="\", ") constant(value="\"type\":\"") property(name="programname") constant(value="\", ") constant(value="\"from\":\"") property(name="hostname") constant(value="\", ") property(name="$!all-json" position.from="2") } if $syslogtag == 'nginx' then { action(type="mmnormalize" rulebase="/opt/rsyslog/nginx-logs.rb" ) action(type="omelasticsearch" template="all-json-nginx" # use the template defined earlier searchIndex="nginx-logs-alpha" searchType="nginx" server="xx.xx.xx.xx" serverport="9200" uid="****" pwd="****" bulkmode="on" # use the bulk API action.resumeretrycount="-1" # retry indefinitely if Elasticsearch is unreachable ) } else { action( name="all-logs-alpha" type="omelasticsearch" server="xx.xx.xx.xx" serverport="9200" searchIndex="all-logs-alpha" uid="****" pwd="****" bulkmode="on" action.resumeretrycount="-1") }
1 – 事情是nginx日志正在写入文件,但没有被发送到rsyslog。
2 – rsyslogconfiguration是正确的,因为我看到rsyslog状态没有错误,日志正在发送到“all-logs-alpha”索引中的elasticsearch。
我正在运行$ rsyslogd -dn通过$ rsyslogd -dn命令,我没有看到任何错误,并没有提到所有的nginx
此外,我testing了我的本地机器上的整个设置,它运作良好,但造成我的服务器上的问题。
这里有什么可能的问题,如何解决?