我应该定期更新GeoLiteCity.dat文件吗?

9

Logstash可以使用捆绑的GeoLiteCity.dat数据库进行IP地址地理位置查找。这个数据库和MaxMind提供的数据库是一样的吗?MaxMind每月的第一个星期二会更新数据库。

设立一个自动刷新数据库的工作,而不是等待ElasticSearch更新Logstash,这是明智的吗?

编辑:2014年12月1日 以下是我编写的bash脚本,用于执行数据库的自动更新。根据此过滤器源代码的解释,可能需要重新启动服务才能使用更新后的数据库文件。

#!/bin/bash

# Downloads the latest GeoLight DBs from maxmind.
# Updates/replaces the databases that logstash uses.
# These are the IP-to-location databases that logstash uses.
# Maxmind updates them once a month on the first Tuesday of the month.
# See http://dev.maxmind.com/geoip/legacy/geolite/

echo Beginning update of GeoIP databases for logstash.
cd /tmp
rm -f GeoIPASNum.dat.gz GeoIPASNum.dat GeoLiteCity.dat.gz GeoLiteCity.dat
echo Downloading latest files.
wget --quiet --output-document GeoIPASNum.dat.gz http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz || { echo 'Download of GeoIPASNum.dat.gz failed' ; exit 1; }
wget --quiet --output-document GeoLiteCity.dat.gz http://geolite.maxmind.com/download/geoip/database/GeoLiteCity.dat.gz || { echo 'Download of GeoLiteCity.dat.gz failed' ; exit 1; }

echo Unzipping
gunzip GeoIPASNum.dat.gz
gunzip GeoLiteCity.dat.gz

echo Setting permissions
chmod 664 GeoIPASNum.dat GeoLiteCity.dat
chown logstash:logstash GeoIPASNum.dat GeoLiteCity.dat

echo Replacing existing files and backing up the old.
cd /opt/logstash/vendor/geoip/
mv -f GeoIPASNum.dat GeoIPASNum.dat.bak && mv /tmp/GeoIPASNum.dat .
mv -f GeoLiteCity.dat GeoLiteCity.dat.bak && mv /tmp/GeoLiteCity.dat .

echo Restarting logstash
# Modify for your distro services model.
service logstash restart

echo Done

找到了地理过滤器的源代码:https://github.com/logstash-plugins/logstash-filter-geoip/blob/master/lib/logstash/filters/geoip.rb。这让我想起我可以在配置中设置这些数据库的备用位置,这可能比覆盖分布式数据库更好。 - Larry Silverman
每次放置新的GeoLiteCity.dat时都必须重新启动logstash是很愚蠢的。我看到有一个“periodic_flush”的选项,但我不确定它具体是做什么或者多久执行一次,因为它只是说:“在定期间隔调用过滤器刷新方法”(https://www.elastic.co/guide/en/logstash/2.4/plugins-filters-geoip.html#plugins-filters-geoip-periodic_flush)。 - totalflux
1个回答

5
是的,它使用同一个数据库,并且您可以使用来自maxmind网站的更新。我在ubuntu中使用geoip-database-contrib包,其中包括定期从maxmind自动更新数据库文件的cronjob。
我不知道maxmind数据集更改的速度,但是由于logstash(包括数据库文件)发布速度较慢(当前版本1.4.2已发布5个月),因此我使用最新的数据库。

似乎您需要商业许可证才能获得定期更新? - Larry Silverman
1
请参阅http://dev.maxmind.com/geoip/legacy/geolite/:每月免费更新。如果您需要更多的更新,您需要付费。 - whyscream
看起来不错。最后一个问题:您需要重新启动logstash以使用更新的.dat文件吗? - Larry Silverman
修改了问题。我对源代码的阅读让我认为需要重新启动。 - Larry Silverman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接