• 安装GeoIP数据库


    1.安装GeoIP数据库
    
    cd /usr/local/logstash/etc
    curl -O "http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz"
    gunzip GeoLiteCity.dat.gz
    1
    2
    3
    2.配置logstash使用GeoIP
    
    只需要在原来的logstash.conf中添加filter即可
    
    vim /usr/local/logstash/etc/logstash.conf
    input {
            file {
                    path => "/data/nginx/logs/access_java.log"
                    type => "nginx-access"
                    start_position => "beginning"
                    sincedb_path => "/usr/local/logstash/sincedb"
                    codec => "json"
            }
    }
    filter {
            if [type] == "nginx-access" {
                    geoip {
                            source => "clientip"
                            target => "geoip"
                            database => "/usr/local/logstash/etc/GeoLiteCity.dat"
                            add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
                            add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}"  ]
                    }
                    mutate {
                            convert => [ "[geoip][coordinates]", "float"]
                    }
            }
    }
    output {
            if [type] == "nginx-access" {
                    elasticsearch {
                            hosts => ["10.10.20.16:9200"]
                            manage_template => true
                            index => "nginx-access-%{+YYYY-MM}"
                    }
            }
    
    }
    
    注意如果是haproxy 作为代理,nginx需要修改为;
    filter {
        grok {
            match => {
                 "message" => "%{IPORHOST:clientip} [%{HTTPDATE:time}] "%{WORD:verb} %{URIPATHPARAM:request} HTTP/%{NUMBER:httpversion}" - %{NUMBER:http_status_code} %{NUMBER:bytes} "(?<http_referer>S+)" "(?<http_user_agent>(S+s+)*S+)" (%{BASE16FLOAT:request_time}) (%{IPORHOST:http_x_forwarded_for}|-)"
            }
        }
            geoip {
                            source => "http_x_forwarded_for"
                            target => "geoip"
                            database => "/usr/local/logstash/etc/GeoLiteCity.dat"
                            add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ]
                            add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}"  ]
                    }
                    mutate {
                            convert => [ "[geoip][coordinates]", "float"]
                    }
    
    }
    
    
    
    
    3.重启logstash即可。

  • 相关阅读:
    python应用之文件属性浏览
    python进阶之路之文件处理
    magento安装时的数据库访问错误
    magento麦进斗客户地址属性不保存在sales_flat_order_address
    自动填写麦进斗Magento进货地址字段
    麦进斗magentoRequireJs回调失败
    如何在麦进斗magento2中调用站外的JS?
    在magento1.9结账地址中删除验证
    麦进斗:在windows系统里面刷新magento2的缓存
    如何安装麦进斗Magento2
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350308.html
Copyright © 2020-2023  润新知