ELK+syslog+nginx访问日志收集+分词处理

发布时间:2020-06-27 08:41:32 作者:lrtao2010
来源:网络 阅读:2239

一、nginx访问日志配置:

1、日志格式配置:

log_format json '{"@timestamp":"$time_iso8601",'

                    '"host":"$server_addr",'

                    '"clientip":"$remote_addr",'

                    '"size":$body_bytes_sent,'

                    '"xff":"$http_x_forwarded_for",'

                    '"upstreamhost":"$upstream_addr",'

                    '"status":"$status",'

                    '"responsetime":$request_time,'

                    '"upstreamtime":"$upstream_response_time",'

                    '"http_host":"$host",'

                    '"url":"$uri"}';

2、访问日志配置:

access_log   syslog:server=xx.xx.xx.xx:5140 json;


二、logstash配置


input {

     syslog{

           port => "5140"

          }

}

filter {

     json {

          source =>"message"

          remove_field => ["message"]

          }

}

output {

          elasticsearch { hosts => ['xx.xx.xx.xx:9200','xx.xx.xx.xx:9200']

                          index => 'nginx_rfd-%{+YYYY.MM.dd.HH}'

                          template => "/usr/local/logstash/nginx.json"

                          template_name => "nginx_*"

                          template_overwrite => true

                        }

}


注意index名称要包含到template_name里


三、自定义mappings

cat /usr/local/logstash/nginx.json

{

    "template": "nginx_*",

    "order":1,

    "settings": { "index.refresh_interval" : "60s" },

    "mappings": {

        "_default_": {

            "_all" : { "enabled" : false },

            "properties": {

                "@timestamp" : { "type" : "date" },

                "@version" : { "type" : "integer", "index" : "not_analyzed" },

                "url": {

                    "type": "string",

                    "index": "not_analyzed"

                },

                "host": {

                    "type": "ip",

                    "index": "not_analyzed"

                },

                "clientip": {

                    "type": "ip",

                    "index": "not_analyzed"

                },

                "size": {

                    "type": "integer"

                },

                "xff": {

                    "type": "string",

                    "index": "not_analyzed"

                },

                "upstreamhost": {

                    "type": "string",

                    "index": "not_analyzed"

                },

                "http_host": {

                    "type": "string",

                    "index": "not_analyzed"

                },

                "status": {

                    "type": "integer"

                },

                "responseTime": {

                    "type": "string",

                    "index": "not_analyzed"

                },

                "upstreamtime": {

                    "type": "string",

                    "index": "not_analyzed"

                }

            }

        }

    }

}


四、生成统计图形

ELK+syslog+nginx访问日志收集+分词处理


五、参考文档

https://elasticsearch.cn/article/154

http://blog.csdn.net/choelea/article/details/53320140

http://www.cnblogs.com/hanyifeng/p/5860731.html


推荐阅读:
  1. IK分词器安装
  2. ELK日志收集demo

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nginx syslog mapping

上一篇:这篇文章带你彻底理解synchronized

下一篇:Cocos2D-Android-1之源码详解:3.ActionsTest

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》