1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| cat logstash.conf input { beats { port => 5044 codec => json } }
filter { geoip { target => "geoip" source => "realip" add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] } mutate { convert => ["[geoip][coordinates]","float"] convert => [ "visit_host","string" ] convert => [ "status","integer" ] convert => [ "size","integer" ] convert => [ "upstreamtime","float" ] convert => [ "req_time","float" ] remove_field => [ "ecs","agent","host","cloud","@version","input","logs_type" ] # 去掉显示 geoip 显示的多余信息 remove_field => ["[geoip][latitude]", "[geoip][longitude]", "[geoip][country_code]", "[geoip][country_code2]", "[geoip][country_code3]", "[geoip][timezone]", "[geoip][continent_code]", "[geoip][region_code] "] }
# 根据 http_user_agent来自动处理区分用户客户端系统与版本 useragent { source => "user-agent" target => "ua" # 过滤useragent没用的字段 remove_field => [ "[ua][minor]","[ua][major]","[ua][build]","[ua][patch]","[ua][os_minor]","[ua][os_major]" ] } }
output { elasticsearch { hosts => ["http://192.168.1.37:30092"] index => "logstash-nginx-log-domain-access-%{+YYYY.MM}" #user => "elastic" #password => "changeme" } }
# vim /usr/lib/systemd/system/logstash.service [Unit] Description=logstash
[Service] ExecStart=/usr/local/logstash-7.16.2/bin/logstash -f /usr/local/logstash-7.16.2/config/logstash.conf ExecReload=/bin/kill -HUP $MAINPID KillMode=process Restart=on-failure
[Install] WantedBy=multi-user.target
systemctl daemon-reload systemctl restart logstash
|