64位os下为啥要编译hadoop就不解释了,百度一下就能知道原因,下面是步骤:
前提:编译源码所在的机器,必须能上网,否则建议不要尝试了
一. 下载必要的组件
a) 下载hadoop源码 (当前最新的稳定版是2.6.0)
地址 http://mirrors.hust.edu.cn/apache/hadoop/common/stable/hadoop-2.6.0-src.tar.gz
b) 下载apache-ant (centos自带的ant版本太低,编译过程中会报错)
地址: http://mirrors.cnnic.cn/apache//ant/binaries/apache-ant-1.9.4-bin.zip (最新版本即可)
c) 下载protobuf-2.5.0.tar.gz (这是google出品的一个数据传输格式)
地址: https://developers.google.com/protocol-buffers/docs/downloads (官网地址要翻!墙!,百度上也能找到国内下载地址)
注意:hadoop2.6.0必须配protobuf 2.5.0版本,版本不匹配,编译将失败
d) 下载findbugs
地址: http://prdownloads.sourceforge.net/findbugs/findbugs-3.0.1.tar.gz?download (最新版本即可)
e) 下载maven
地址: http://maven.apache.org/download.cgi (下载最新版即可,本文中用的是3.2.5)
f) 下载jdk
地址:这个比较容易找,大家自己去oracle官网找着,jdk1.6 及以上(本文用的是1.7)
二. 设置环境变量
(下面三种方式任选其一即可)
sudo vi /etc/profile
vi ~/.bashrc
vi ~/.bash_profile
上面3个命令随便用哪个,进入vi编辑器后,参考下面的内容设置环境变量:
(注: 下面的$ JAVA _ HOME部分,博客发表后,好象博客园会自动变成其它格式,正确内容参考图片)
export ANT_HOME=/home/cargo/apache-ant-1.9.4
export FINDBUGS_HOME=/home/cargo/findbugs-3.0.1
export JAVA_HOME=/home/cargo/jdk1.7.0_76
export M2_HOME=/home/cargo/apache-maven-3.2.5
export PATH=$JAVA_HOME/bin:$PATH:$HOME/bin:$M2_HOME/bin:$ANT_HOME/bin:$FINDBUGS_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
编译过程中,maven会从互联网下载很多jar包,强烈建议在局域网搭建一个nexus私服, 另外建议修改maven/conf/settings.xml文件,参考内容如下:
1 <?xml version="1.0" encoding="UTF-8"?> 2 <settings xmlns=" http://maven.apache.org/SETTINGS/1.0.0" 3 xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance" 4 xsi:schemaLocation=" http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> 5 6 <localRepository>/home/cargo/m2</localRepository> 7 8 <mirrors> 9 <mirror> 10 <id>nexus</id> 11 <mirrorOf>*</mirrorOf> 12 <url> http://172.21.129.57:8081/nexus/content/groups/public/</url> 13 </mirror> 14 </mirrors> 15 16 <profiles> 17 <profile> 18 <id>nexus</id> 19 <repositories> 20 <repository> 21 <id>nexus</id> 22 <name>Nexus</name> 23 <url> http://172.21.129.57:8081/nexus/content/groups/public/</url> 24 <releases><enabled>true</enabled></releases> 25 <snapshots><enabled>true</enabled></snapshots> 26 </repository> 27 </repositories> 28 <pluginRepositories> 29 <pluginRepository> 30 <id>nexus</id> 31 <name>Nexus</name> 32 <url> http://172.21.129.57:8081/nexus/content/groups/public/</url> 33 <releases><enabled>true</enabled></releases> 34 <snapshots><enabled>true</enabled></snapshots> 35 </pluginRepository> 36 </pluginRepositories> 37 </profile> 38 </profiles> 39 <activeProfiles> 40 <activeProfile>nexus</activeProfile> 41 </activeProfiles> 42 43 </settings>