1、nginx配置
log_format format_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" }';
2、在logstash服务器下载IP地址归类查询库
#/usr/local/logstash-7.1.1/config
#wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-City.mmdb.gz
#gunzip GeoLite2-City.mmdb.gz
3、在logstash的filter中添加geoip
filter {
if [type] == "nginx-accesslog" {
json {
source => "message"
remove_field => [ "message" ] #删除重复的message收集。
}
mutate {
split => { "request" => " " }
}
mutate {
add_field => {
"httpversion" => "%{[request][2]}"
}
}
mutate { #这里应该是选取xff,这里没有可以删掉,
split => { "xff" => "," }
}
mutate {
add_field => {
"realip" => "%{[xff][0]}"
}
}
geoip {
source => "clientip"
target => "geoip"
database => "/usr/local/logstash-7.1.1/config/GeoLite2-City.mmdb"
add_field => ["[geoip][coordinates]","%{[geoip][longitude]}"]
add_field => ["[geoip][coordinates]","%{[geoip][latitude]}"]
}
}
map.tilemap.url: 'http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
kibana 6版本添加以下参数
tilemap.url: 'http://webrd02.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=7&x={x}&y={y}&z={z}'
这个地方困惑了很久,启动就报错,七版本多了个map参数
官网地址: https://www.elastic.co/guide/en/kibana/7.1/settings.html#tilemap-settings
4、添加地图展示
可视化–添加
修改成高德地图