ELK+syslog+nginx访问日志收集+分词处理
admin
2023-03-17 13:21:19
0

一、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


相关内容

热门资讯

特朗普还有一场硬仗 新华社北京5月9日电 美国民主、共和两党当前正推动有利本党的国会选区重划,并为此大打官司。弗吉尼亚州...
美国佛州发生疑似船只爆炸事故,... 当地时间5月9日,总台记者获悉,美国佛罗里达州迈阿密海滩附近一处热门水上聚会区域发生疑似船只爆炸事故...
【快看】涉及手机、电脑、电视等... 工业和信息化部、商务部、市场监管总局等部门近日联合启动实施《人工智能终端智能化分级》系列国家标准。 ...
中锂电取得锂电池安全保护装置专... 国家知识产权局信息显示,浙江中锂电科技有限公司取得一项名为“一种锂电池安全保护装置”的专利,授权公告...
奥特曼“官宣” OpenAI ... 文 | AI唱反调 今早,奥特曼发布了一条 X,几乎坐实了近半个月来的传闻。 X正文只有三个词:“...
普京:收到泽连斯基希望会晤的口... 俄罗斯总统普京当地时间5月9日晚召开记者会,回答相关提问。普京表示,此次红场阅兵未展示军事装备,并不...
将论文“写”在秦岭云端 5月7日,团队成员正在进行激光光谱分光测试实验。 “我们在太白山主峰架起自主研制的激光雷达,可以实时...
成都人工智能产业实力领跑西部,... 近日,工业和信息化部发布2025年先进计算赋能新质生产力典型应用案例名单,成都3家人工智能领域企业 ...
铭凡发布「智能体NAS」:第三... 如果说过去几年,NAS市场的关键词还是“私有云”“家庭存储”和“影音库”,那么现在的情况已经悄然发生...
药王更替GIP靶点锋芒毕露 博... 来源:滚动播报 (来源:北京商报) 过去两年,减重药赛道极速完成了路径更迭。以礼来替尔泊肽为代表的G...