最近因为要改Hadoop的一些代码,需要重新编译,测试环境是用cdh4.6.0做debug,简单记录下hadoop的编译方法:
1)编译环境需要下面几个包
yum install lzo-devel zlib-devel gcc autoconf automake libtool ncurses-devel openssl-devel cmake
2)需要mvn/ant环境
3)在src目录下运行
mvn package -DskipTests -Pdist,native -Dtar -e -X
4)protobuf的版本要求,cdh4.6.0需要 *2.4*版本
如果protobuf版本不匹配会报如下错误,并导致hadoop-common无法编译完成:
[exec] Required version of 'protoc' is 2.4.0a, reported libprotoc 2.5.0
....
Caused by:
/home/caiguangguang/hadoop-2.0.0-cdh4.6.0/src/hadoop-common-project/hadoop-common/target/antrun/build-main.xml:33:
exec returned: 1
通过这个build-main.xml文件,可以看到是和protobuf有关
错误由下面脚本导致(也可以看出protobuf是2.4.x版本即可):
hadoop-common-project/hadoop-common/target/compile-proto.sh
#!/bin/bash
PROTOC="$HADOOP_PROTOC_CDH4_PATH"
if [ "${PROTOC}X" = "X" ]; then
PROTOC="protoc"
fi
PROTOC_VERSION=`${PROTOC} --version`
if [[ "${PROTOC_VERSION}" != *2.4* ]]; then
echo "Required version of 'protoc' is 2.4.0a, reported ${PROTOC_VERSION}"
exit 1
fi
....
编译安装protobuf的方法:
./configure --prefix=/home/protobuf && make && make install (安装完成后注意加载lib目录)
protoc --version #PATH增加这个/home/protobuf/bin目录