搭建及修正Hadoop1.2.1 MapReduce Pipes C++开发环境

时间:2024-01-13 22:39:32

Hadoop目前人气超旺,返璞归真的KV理念让人们再一次换一个角度来冷静思考一些问题。

但随着近些年来写C/C++的人越来越少,网上和官方WIKI的教程直接落地的成功率却不高,多少会碰到这样那样的问题。

现在我就重新整理下搭建过程的一些细节,供同好者分享,也请多多指点。

1,一些条件:

VituralBox 4.3 Win7 x64

Centos 6.4 x64_86(来自某国内某镜像网站)

Hadoop-1.2.1.tar.gz

安装openssl、zlib、glib必备(之前cassandra的文章有提及)

2,搭建集群过程(这部分简写,网上很多参考)

2.1 ssh_key互信

主备:ssh-keygen -t rsa 回车到底
主备:chmod 755 .ssh
主:cd .ssh
主:cp id_rsa.pub authorized_keys
主:chmod 644 authorized_keys
主:scp authorized_keys 192.168.137.102:/root/.ssh
备:#scp id_rsa.pub 192.168.137.101:/root/.ssh/192.168.137.102.id_rsa.pub
主:
cat 192.168.137.102.id_rsa.pub >> authorized_keys
主备:
vim /etc/ssh/sshd_config
改为 RSAAuthentication yes
PubkeyAuthentication yes
主备:
service sshd restart

2.2 hadoop-env.sh 头上增补

export JAVA_HOME=/opt/java1.6
export HADOOP_HOME=/opt/hadoop
export HADOOP_CONF_DIRE=/opt/hadoop/conf

2.3 三大xml配置(此处略,网上都有,或者看老版本default)

2.4 master配置

192.168.137.101

2.5 slaver配置

192.168.137.102

2.6 同步

scp -r hadoop 192.168.137.102:/opt

2.7 格式化

hadoop namenode -format ,提升输入大写Y

2.8 拉起来

start-all.sh

2.9 初验

jps(主跑namenode*2+job,备跑task+data)

hadoop dfsadmin -report

或者开个IE,http://cent1:50070 看下日志,浏览下Hdfs

3,搭建C++ Pipes

cd /opt/hadoop/src/c++/pipes   ->  chmod 777 configure -> ./configure -> make -> make install

cd /opt/hadoop/src/c++/utils     ->  chmod 777 configure -> ./configure -> make -> make install

cd //opt/hadoop/src/c++/libhdfs ->  chmod 777 configure -> ./configure -> make -> make install

把生成的静、动库文件(比自带版本size打了3~4倍)扔到下面三个目录(为今后方便起见)

/opt/hadoop/c++/Linux-amd64-64/lib

/usr/lib64

/usr/lib

/usr/local/lib

及自己的开发目录

把hadoop自带的头文件/opt/hadoop/c++/Linux-amd64-64/include扔到

/usr/include

/usr/local/include

及自己的开发目录

重启hadoop。不做第三步,在开始reduce的过程中会遇到服务器认证失败的报错。

4,开发环境

4.1 用网上北美气象局的SAMPLE

[root@cent3 tt]# more sample.txt
0067011990999991950051507004+68750+023550FM-12+038299999V0203301N00671220001CN9999999N9+00001+99999999999
0043011990999991950051512004+68750+023550FM-12+038299999V0203201N00671220001CN9999999N9+00221+99999999999
0043011990999991950051518004+68750+023550FM-12+038299999V0203201N00261220001CN9999999N9-00111+99999999999
0043012650999991949032412004+62300+010750FM-12+048599999V0202701N00461220001CN0500001N9+01111+99999999999
0043012650999991949032418004+62300+010750FM-12+048599999V0202701N00461220001CN0500001N9+00781+99999999999

4.2 用网上max_temperature sample

#include "hadoop/Pipes.hh"
#include "hadoop/TemplateFactory.hh"
#include "hadoop/StringUtils.hh"

#include <algorithm>
#include <limits>
#include <stdint.h>
#include <string>
#include <stdio.h>

class MaxTemperatureMapper: public HadoopPipes::Mapper {
public:
MaxTemperatureMapper(HadoopPipes::TaskContext& context){}
void map(HadoopPipes::MapContext& context)
{
std::string line=context.getInputValue();
std::string year=line.substr(15,4);
std::string airTemperature=line.substr(87,5);
std::string q=line.substr(92,1);
if(airTemperature != "+9999" && (q == "0" || q == "1" || q == "4" || q == "5" || q == "9"))
{
context.emit(year, airTemperature);
}
}
};

class MapTemperatureReducer: public HadoopPipes::Reducer {
public:
MapTemperatureReducer(HadoopPipes::TaskContext& context){}
void reduce(HadoopPipes::ReduceContext& context)
{
int maxValue=0;
while(context.nextValue())
{
maxValue=std::max(maxValue,HadoopUtils::toInt(context.getInputValue()));
}
context.emit(context.getInputKey(),HadoopUtils::toString(maxValue));
}
};

int main()
{
return HadoopPipes::runTask(HadoopPipes::TemplateFactory<MaxTemperatureMapper,MapTemperatureReducer>());
}

4.3 设置Makefile或者VIM自带设置

CC=g++
PLATFORM=Linux-amd64-64
HADOOP_INSTALL=/opt/hadoop
CPPFLAGS = -m64 -I/usr/local/include
max_temperature: maxtemperature.cpp
  $(CC) $(CPPFLAGS) $< -Wall -L/usr/local/lib -lhadooppipes -lcrypto -lhadooputils -lpthread -g -O2 -o $@

==

52 "======================
53 "F5 Compile c
54 "======================
55 map <F5> :call Compilepp()<CR>
56 func! Compilepp()
57 if &filetype == 'cpp'
58 exec "w"
59 exec "! clear;
60 \ echo Compiling: ./% ...;
61 \ echo ;
62 \ g++ % -g -lstdc++  -L/usr/local/lib -lhadooppipes -lcrypto -lhadooputils -lpthread  -o %<.o;
63 \ echo Complie Done;
64 \ echo Start Testing;
65 \ echo ;
66 \ echo ;
67 \ echo ;
68 \ ./%<.o;"
69 endif
70 endfunc

==

4.4 开始实验

hadoop dfs -rmr output
hadoop dfs -rm bin/max_temperature
hadoop dfs -put max_temperature bin/max_temperature
haddop dfs -put sample.txt sample.txt

hadoop pipes -D hadoop.pipes.java.recordreader=true -D hadoop.pipes.java.recordwriter=true -input sample.txt -output output -program bin/max_temperature

搭建及修正Hadoop1.2.1 MapReduce Pipes C++开发环境

大致基本上就是这样了,对重新编译一事,wiki也没有多说什么,也是从别家了解到一些信息,在此要感谢某位前辈。

最后再附上一张我自己理解的MP流程图供参考

搭建及修正Hadoop1.2.1 MapReduce Pipes C++开发环境