修改Nginx配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
| log_format json escape=json '{"@timestamp":"$time_iso8601",' '"domain":"$host",' '"host":"$server_addr",' '"clientip":"$remote_addr",' '"remote_user":"$remote_user",' '"request":"$request",' '"request_method":"$request_method",' '"uri":"$uri",' '"request_time":"$request_time",' '"status":"$status",' '"http_referrer":"$http_referer",' '"body_bytes_sent":"$body_bytes_sent",' '"xff":"$http_x_forwarded_for",' '"http_user_agent":"$http_user_agent",' '"upstream_addr":"$upstream_addr",' '"upstream_response_time":"$upstream_response_time"}'; access_log /var/log/nginx/access.log json;
|
添加高德地图
1.编辑kibana配置文件kibana.yml,最后面添加
1 2
| map.tilemap.url: 'http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
|
配置logstash
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
| cd /opt
wget https://raw.githubusercontent.com/texnikru/GeoLite2-Database/master/GeoLite2-City.mmdb.gz
gunzip GeoLite2-City.mmdb.gz
mv GeoLite2-City.mmdb /usr/local/elk/logstash/config/
vim /usr/local/elk/logstash/default.conf
input { beats { port => "5044" } }
filter { json { source => "message" remove_field => [ "message" ] } mutate { split => { "request" => " " } } mutate { add_field => { "httpversion" => "%{[request][2]}" } } mutate { split => { "xff" => "," } } mutate { add_field => { "realip" => "%{[xff][0]}" } } geoip { source => "clientip" target => "geoip" database => "/usr/local/elk/logstash/config/GeoLite2-City.mmdb" add_field => ["[geoip][coordinates]","%{[geoip][longitude]}"] add_field => ["[geoip][coordinates]","%{[geoip][latitude]}"] } mutate { convert => [ "[geoip][coordinates]", "float" ] } }
output { elasticsearch { hosts => ["192.168.10.129:9200"] index => "nginx-%{+YYYY.MM.dd}" } }
|
geoip
geoip 是 object 类型,它有几个子字段,含义如下:
- geoip.city_name:城市
- geoip.continent_name:大陆名称
- geoip.country_iso_code:国家编码
- geoip.location:经纬度坐标,必须是:geo_point 类型
- geoip.region_iso_code:地域编码
- geoip.region_name:地域名称
扩展程序是谷歌的
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
| http://192.168.10.129:9200/_template/geoip/
此字段需要配置成true,以防地理格式错误导致文档被拒绝
{ "index_patterns": [ "nginx*" ], "order": 10, "mappings": { "properties": { "clientip": { "type": "ip" }, "geoip": { "dynamic": true, "type": "object", "properties": { "location": { "type": "geo_point", "ignore_malformed": "true" }, "coordinates": { "type": "geo_point", "ignore_malformed": "true" }, "ip": { "type": "ip" } } } } }, "aliases": { "nginx": {} } }
|
以下就代表模板创建成功
Kibana加载地图