Home >Database >Mysql Tutorial >MongoDB+Hadoop运行环境搭建

MongoDB+Hadoop运行环境搭建

WBOY
WBOYOriginal
2016-06-07 17:56:48983browse

首先要下载mongo-hadoop adapter git clone https://github.com/mongodb/mongo-hadoop.git git checkout release-1.0 然后进入mongo-hadoop目录,找到build.sbt将 hadoopRelease in ThisBuild 修改成如下所示: hadoopRelease in ThisBuild := "0.20" 然后运

首先要下载mongo-hadoop adapter


git clone https://github.com/mongodb/mongo-hadoop.git

git checkout release-1.0


然后进入mongo-hadoop目录,找到build.sbt将 hadoopRelease in ThisBuild 修改成如下所示:


hadoopRelease in ThisBuild := "0.20"


然后运行 ./sbt package(关于sbt https://github.com/harrah/xsbt/wiki)

运行时需要翻墙才行。

运行结束之后会再core/target目录下生成一个jar文件mongo-hadoop-core_0.20.205.0-1.0.1.jar,香港服务器,然后下载mongodb的驱动包。


wget --no-check-certificate https://github.com/downloads/mongodb/mongo-java-driver/mongo-2.7.3.jar 下载完之后就可以开始开发mongo-hadoop的程序了。 运行自带示例: 首先将数据导入到mongodb中,美国服务器,命令如下。  ./sbt load-sample-data 然后再eclipe中新建一个项目,例如treasury,香港服务器,将mongo-hadoop/example/treasury_field中的源文件和资源文件复制到新建的项目下。如图所示:

然后修改mongo-treasury_yield.xml文件中mongodb的url和存放collection



mongo.input.uri
mongodb://127.0.0.1/mongo_hadoop.yield_historical.in



mongo.output.uri
mongodb://127.0.0.1/mongo_hadoop.yield_historical.out

 

然后修改TreasuryYieldXMLConfig.java如下:

Configuration.addDefaultResource( "resources/mongo-treasury_yield.xml");
Configuration.addDefaultResource( "resources/mongo-defaults.xml" );

 

后将项目打包成jar文件。

运行 hadoop jar treasury.jar com.mongodb.hadoop.treasury.TreasuryXMLConfig 即可运行hadoop程序。运行结果如下图:mongodb中的数据。



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn