gpt4 book ai didi

hadoop - 使用分布式缓存访问 Hadoop 中的 Maxmind Geo API

转载 作者:行者123 更新时间:2023-12-02 19:34:55 25 4
gpt4 key购买 nike

我正在编写一个 MapReduce 作业来分析 Web 日志。我的代码旨在将 ip 地址映射到地理位置,为此我使用 Maxmind Geo API( https://github.com/maxmind/geoip-api-java )。我的代码有一个 LookupService 方法,该方法需要带有 ip 到位置匹配的数据库文件。我正在尝试使用分布式缓存传递此数据库文件。我尝试以两种不同的方式做到这一点

案例1:

运行从 HDFS 传递文件的作业,但它总是抛出错误“ FILE NOT FOUND

sudo -u hdfs hadoop jar \
WebLogProcessing-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
GeoLocationDatasetDriver /user/hdfs/input /user/hdfs/out_put \
/user/hdfs/GeoLiteCity.dat

或者
sudo -u hdfs hadoop jar \
WebLogProcessing-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
GeoLocationDatasetDriver /user/hdfs/input /user/hdfs/out_put \
hdfs://sandbox.hortonworks.com:8020/user/hdfs/GeoLiteCity.dat

驱动程序类代码:
Configuration conf = getConf();
Job job = Job.getInstance(conf);
job.addCacheFile(new Path(args[2]).toUri());

映射器类代码:
public void setup(Context context) throws IOException
{
URI[] uriList = context.getCacheFiles();
Path database_path = new Path(uriList[0].toString());
LookupService cl = new LookupService(database_path.toString(),
LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE);
}

案例二:
通过 -files 选项从本地文件系统传递文件来运行代码。 错误:空指针异常 在 LookupService cl = new LookupService(database_path)
sudo -u hdfs hadoop jar  \
WebLogProcessing-0.0.1-SNAPSHOT-jar-with-dependencies.jar \
com.prithvi.mapreduce.logprocessing.ipgeo.GeoLocationDatasetDriver \
-files /tmp/jobs/GeoLiteCity.dat /user/hdfs/input /user/hdfs/out_put \
GeoLiteCity.dat

驱动程序代码:
Configuration conf = getConf();
Job job = Job.getInstance(conf);
String dbfile = args[2];
conf.set("maxmind.geo.database.file", dbfile);

映射器代码:
public void setup(Context context) throws IOException
{
Configuration conf = context.getConfiguration();
String database_path = conf.get("maxmind.geo.database.file");
LookupService cl = new LookupService(database_path,
LookupService.GEOIP_MEMORY_CACHE | LookupService.GEOIP_CHECK_CACHE);
}

我在所有任务跟踪器中都需要这个数据库文件来完成这项工作。有人可以建议我这样做的正确方法吗?

最佳答案

尝试这样做:

从驱动程序中使用 Job 指定 HDFS 中文件的位置。目的:

job.addCacheFile(new URI("hdfs://localhot:8020/GeoLite2-City.mmdb#GeoLite2-City.mmdb"));

在哪里, #表示要由 hadoop 创建的别名(符号链接(symbolic link))

之后,您可以在 setup() 中从 Mapper 访问该文件。方法:

@Override
protected void setup(Context context) {
File file = new File("GeoLite2-City.mmdb");
}

这是一个例子:
  • 驱动代码:http://goo.gl/COqysa
  • 映射器代码:http://goo.gl/0SbQQP
  • 关于hadoop - 使用分布式缓存访问 Hadoop 中的 Maxmind Geo API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25193145/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com