EFK实现GeoIP定位全球访客
新钛云服已为您服务1289天
IP地理位置用于确定IP地址的物理位置,可被用于多种实际场景,包括内容个性化与流量分析等等。根据地理位置进行流量分析可帮助大家有效分析自己的用户群体,从而了解用户来自哪里、决定应用服务器的理想地理位置并明确掌握用户定位。
本教程中,我们将共同了解如何利用Fluentd、Kafka、Logstash、Elasticsearch与Kibana配合GeoIP数据库,从而建立应用用户IP地址的可视化地理位置映射,目的效果图如下图所示:
第一步:Fluentd收集nginx日志
#配置fluentd [root@fluent ~]# vim /etc/td-agent/td-agent.conf <source> @type tail path /var/log/nginx/access_json.log pos_file /var/log/nginx/access_json.log.pos tag nginx_json.access format json time_format %d/%b/%Y:%H:%M:%S %z </source> |
第二步:将Fluentd收集到的日志存放到kafka
使用kafka集群做缓存层,而不是直接将agent收集到的日志信息写入logstash节点,让整体结构更健壮。agent负责将收集到的数据写入kafka,logstash取出数据并处理。
第三步:logstash从kafka中取出日志
Logstash 是一款强大的数据处理工具,它可以实现数据传输,格式处理,格式化输出,还有强大的插件功能,常用于日志处理。
第四步:logstash中配置GeoIP解析地理信息
geoip主要用于kibana绘制地理区域图时使用,原理就是通过一个IP库,根据IP直接获取对应的地理坐标等信息,从而在地图上进行展示。
[root@logstash ~]# yum install GeoIP-data -y [root@logstash ~]# vim /etc/logstash/conf.d/kafka_log_es.conf filter{ if [remote] != "-" { geoip { source => "remote" target => "geoip" # database => "/usr/share/GeoIP/GeoIPCity.dat" add_field => [ "[geoip][coordinates]", "%{[geoip][longitude]}" ] add_field => [ "[geoip][coordinates]", "%{[geoip][latitude]}" ] } mutate { convert => [ "[geoip][coordinates]", "float"] } } } |
第五步:Logstash将处理后的日志传输给es
Logstash是一个日志收集、过滤、转发的中间件,主要负责将各条业务线的各类日志统一收集、过滤后,转发给 Elasticsearch (如下图所示)进行下一步处理。
[root@logstash ~]# vim /etc/logstash/conf.d/kafka_log_es.conf output { elasticsearch { hosts => ["http://node1.elastic.test.com:9200","http://node2.elastic.test.com:9200"] index => "logstash-nginx-log-%{+YYYY.MM}" codec => "json" } } |
第六步:kibana展示访问IP地图
Kibana是一个可视化工具,可以为 ElasticSearch 提供的日志分析友好的 Web 界面,可以帮助汇总、分析和搜索重要数据日志。
至此,EFK实现GeoIP定位全球访客完成。
了解新钛云服
往期技术干货
点👇分享
戳👇在看
关键词
日志
数据
架构
工具
新钛云服
最新评论
推荐文章
作者最新文章
你可能感兴趣的文章
Copyright Disclaimer: The copyright of contents (including texts, images, videos and audios) posted above belong to the User who shared or the third-party website which the User shared from. If you found your copyright have been infringed, please send a DMCA takedown notice to [email protected]. For more detail of the source, please click on the button "Read Original Post" below. For other communications, please send to [email protected].
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。
版权声明:以上内容为用户推荐收藏至CareerEngine平台,其内容(含文字、图片、视频、音频等)及知识版权均属用户或用户转发自的第三方网站,如涉嫌侵权,请通知[email protected]进行信息删除。如需查看信息来源,请点击“查看原文”。如需洽谈其它事宜,请联系[email protected]。