一、安装所需要的工具
a) 下载hadoop源码 (当前最新的稳定版是2.7.4)
地址 http://mirrors.hust.edu.cn/apache/hadoop/common/stable/hadoop-2.7.4-src.tar.gz
b) 下载并解压apache-ant (centos自带的ant版本太低,编译过程中会报错)
地址: http://mirrors.cnnic.cn/apache//ant/binaries/apache-ant-1.10.1-bin.zip (最新版本即可)
c) 下载并解压protobuf-2.5.0.tar.gz (这是google出品的一个数据传输格式)
地址: https://developers.google.com/protocol-buffers/docs/downloads (官网地址要翻!墙!,百度上也能找到国内下载地址)
d) 下载并解压findbugs
地址: http://prdownloads.sourceforge.NET/findbugs/findbugs-3.0.1.tar.gz?download (最新版本即可)
e) 下载并解压maven
地址: http://maven.apache.org/download.cgi (下载最新版即可,本文中用的是3.5.0)
f) 下载并安装jdk,使用sudo安装
地址:这个比较容易找,大家自己去Oracle官网找着,jdk1.8 及以上(本文用的是1.8.111)
二、设置环境变量
vi ~/.bash_profile,添加以下命令:
export ANT_HOME=/home/myusr/apache-ant-1.10.1 export FINDBUGS_HOME=/home/myusr/findbugs-3.0.1 export JAVA_HOME=/usr/java/jdk1.8.0_111/ export M2_HOME=/home/myusr/apache-maven-3.5.0 export PATH=$PATH:$JAVA_HOME/bin:$M2_HOME/bin:$ANT_HOME/bin:$FINDBUGS_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
source ~/.bash_profile
三、设置maven的本地存储库(高亮显示)
<?xml version="1.0" encoding="UTF-8"?> <settings xmlns=" http://maven.apache.org/SETTINGS/1.0.0" xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <!-- 直接网络下载的话,只修改这句就可以 --> <localRepository>/home/zkpk/apache-maven-3.5.0/repo</localRepository> <mirrors> <mirror> <id>alimaven</id> <name>aliyun maven</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <mirrorOf>central</mirrorOf> </mirror> </mirrors> <profiles> <profile> <id>nexus</id> <repositories> <repository> <id>nexus</id> <name>Nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </repository> </repositories> <pluginRepositories> <pluginRepository> <id>nexus</id> <name>Nexus</name> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> <releases><enabled>true</enabled></releases> <snapshots><enabled>true</enabled></snapshots> </pluginRepository> </pluginRepositories> </profile> </profiles> <activeProfiles> <activeProfile>nexus</activeProfile> </activeProfiles> </settings>
验证:
ant -version
mvn -version
三、安装必要的软件
sudo yum -y install gcc* sudo yum -y install cmake sudo yum -y install glibc-headers sudo yum -y install gcc-c++ sudo yum -y install zlip-devel sudo yum -y install openssl-devel sudo yum -y install svn sudo yum -y install git sudo yum -y install ncurses-devel sudo yum -y install lzo-devel sudo yum -y install autoconf sudo yum -y install libtool sudo yum -y install automake
四、配置安装protobuf
进入protobuf所在目录,然后按下面顺序操作
./configure make make check sudo make install
五、修改源代码
将节点hadoop-annotations的值由provide 改成compile
进入hadoop-2.7.4所在目录,
vi hadoop-common-project/hadoop-auth/pom.xml
<dependency> <groupId>org.apache.hadoop</groupId> <artifactId>hadoop-annotations</artifactId> <scope>compile</scope> </dependency>
六、编译
进入hadoop源代码目录,输入
mvn clean package -DskipTests -Pdist,native -Dtar
上面这行命令大意是先清理target目录,再打包,同时跳过测试,应用dist,native这2种profile,且最终目标是生成tar包
(参考文档:http://blog.csdn.net/u013980127/article/details/52287545)