zoukankan      html  css  js  c++  java
  • 安装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即可。

  • 相关阅读:
    re正则表达式公式讲解3
    re正则表达式2
    re正则表达式公式讲解1
    洛谷 P2962 [USACO09NOV]灯Lights
    9.26模拟赛
    BZOJ 1567: [JSOI2008]Blue Mary的战役地图

    洛谷 P2919 [USACO08NOV]守护农场Guarding the Farm
    洛谷P3252 [JLOI2012]树
    P3183 [HAOI2016]食物链
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13350308.html
Copyright © 2011-2022 走看看