Giter Site home page Giter Site logo

geo's Introduction

Geo

收集nginx日志信息,对日志信息IP地址过滤分析

Flow

                                                                +------------------------+
                        +--------+                              |                        |
+-----------+           |        |          +----------+        |                        |
|fluent-bit |---------->| kafka  |<---------|  golang  |------->|     elasticsearch      |
+-----------+           |        |          +----------+        |                        |
                        +--------+                              |                        |
                                                                +------------------------+

入门开始

Nginx日志输出配置

http {
        # Logging Settings
        log_format main   '{"@timestamp":"$time_iso8601",'
                        '"@source":"$server_addr",'
                        '"hostname":"$hostname",'
                        '"ip":"$http_x_forwarded_for",'
                        '"client":"$remote_addr",'
                        '"request_method":"$request_method",'
                        '"scheme":"$scheme",'
                        '"domain":"$server_name",'
                        '"referer":"$http_referer",'
                        '"request":"$request_uri",'
                        '"args":"$args",'
                        '"size":$body_bytes_sent,'
                        '"status": $status,'
                        '"responsetime":$request_time,'
                        '"upstreamtime":"$upstream_response_time",'
                        '"upstreamaddr":"$upstream_addr",'
                        '"http_user_agent":"$http_user_agent",'
                        '"https":"$https"'
                        '}';

        access_log /var/log/nginx/access.log main;
        error_log /var/log/nginx/error.log;
}

Fluent-bit配置

[INPUT]
    name              tail
    path              /var/log/nginx/*.log
    DB                /fluent-bit/etc/fluent-bit.db
    Mem_Buf_Limit     5MB
    Skip_Long_Lines   On
    Refresh_Interval  10
    Parser            json

[OUTPUT]
    Name        kafka
    Match       *
    Brokers     192.168.52.172:9092
    Topics      nginx-log

安装和运行

./geo

配置说明

kafka:
  host: "kafka:9092"                        # kafka服务器ip,多个kafka以逗号隔开 例如:"kafka1:9092,kafka2:9092,kafka3:9092"
  topic: "nginx-log"                        # 消费topic
  groupId: "1"                              # kafka groupid
  numPartitions: 3                          # 自动创建kafka分区数量
  replication: -1                           # 自动创建kafka副本数量
es:
  host: http://es:9200                      # es地址
  preName: logstash-                        # es文档前缀

chunzhen:                          
  path: config/qqwry.dat                    # 纯真离线库路径
ip2location:
  path: config/IP2LOCATION-LITE-DB11.BIN    # ip2location离线数据库路径

源码安装

go mod download
go build

geo's People

Contributors

jidancong avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.