沒有誰必須要幫助你,任何事情都得靠自己去完成
Hadoop原始碼編譯
準備作業
(1)CentOS聯網
配置CentOS能連接外網,Linux虛擬機ping是暢通的
注意:采用root角色編譯,減少檔案夾權限出現問題
(2)jar包準備(hadoop原始碼、JDK8、maven、ant 、protobuf)
(1)hadoop-2.7.2-src.tar.gz
(2)jdk-8u144-linux-x64.tar.gz
(3)apache-ant-1.9.9-bin.tar.gz(build工具,打包用的)
(4)apache-maven-3.0.5-bin.tar.gz
(5)protobuf-2.5.0.tar.gz(序列化的框架)
編譯工具安裝
(1)安裝JDK
[root@hadoop101 software] # tar -zxf jdk-8u144-linux-x64.tar.gz -C /opt/module/
[root@hadoop101 software]# vi /etc/profile
\#JAVA_HOME:
export JAVA_HOME=/opt/module/jdk1.8.0_144
export PATH=$PATH:$JAVA_HOME/bin
[root@hadoop101 software]#source /etc/profile
驗證命令:java -version
(2)Maven解壓、配置 MAVEN_HOME和PATH
[root@hadoop101 software]# tar -zxvf apache-maven-3.0.5-bin.tar.gz -C /opt/module/
[root@hadoop101 apache-maven-3.0.5]# vi conf/settings.xml
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
? <id>mirrorId</id>
? <mirrorOf>repositoryId</mirrorOf>
? <name>Human Readable Name for this Mirror.</name>
? <url>http://my.repository.com/repo/path</url>
</mirror>
-->
? <mirror>
? <id>nexus-aliyun</id>
? <mirrorOf>central</mirrorOf>
? <name>Nexus aliyun</name>
? <url>http://maven.aliyun.com/nexus/content/groups/public</url>
? </mirror>
</mirrors>
[root@hadoop101 apache-maven-3.0.5]# vi /etc/profile
\#MAVEN_HOME
export MAVEN_HOME=/opt/module/apache-maven-3.0.5
export PATH=$PATH:$MAVEN_HOME/bin
[root@hadoop101 software]#source /etc/profile
驗證命令:mvn -version
(3)配置ANT
[root@hadoop101 software]# tar -zxvf apache-ant-1.9.9-bin.tar.gz -C /opt/module/
[root@hadoop101 apache-ant-1.9.9]# vi /etc/profile
\#ANT_HOME
export ANT_HOME=/opt/module/apache-ant-1.9.9
export PATH=$PATH:$ANT_HOME/bin
[root@hadoop101 software]#source /etc/profile
驗證命令:ant -version
(4)安裝 glibc-headers 和 g++
[root@hadoop101 apache-ant-1.9.9]# yum install glibc-headers
[root@hadoop101 apache-ant-1.9.9]# yum install gcc-c++
(5)安裝make和cmake
[root@hadoop101 apache-ant-1.9.9]# yum install make
[root@hadoop101 apache-ant-1.9.9]# yum install cmake
(6)安裝protobuf
[root@hadoop101 software]# tar -zxvf protobuf-2.5.0.tar.gz -C /opt/module/
[root@hadoop101 opt]# cd /opt/module/protobuf-2.5.0/
[root@hadoop101 protobuf-2.5.0]#./configure
[root@hadoop101 protobuf-2.5.0]# make
[root@hadoop101 protobuf-2.5.0]# make check
[root@hadoop101 protobuf-2.5.0]# make install
[root@hadoop101 protobuf-2.5.0]# ldconfig
[root@hadoop101 hadoop-dist]# vi /etc/profile
\#LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/module/protobuf-2.5.0
export PATH=$PATH:$LD_LIBRARY_PATH
[root@hadoop101 software]#source /etc/profile
驗證命令:protoc --version
(7)安裝openssl庫
[root@hadoop101 software]#yum install openssl-devel
(8)安裝 ncurses-devel庫
[root@hadoop101 software]#yum install ncurses-devel
到此,編譯工具安裝基本完成
編譯原始碼
(1)解壓原始碼到/opt/目錄
[root@hadoop101 software]# tar -zxvf hadoop-2.7.2-src.tar.gz -C /opt/
(2)進入到hadoop原始碼主目錄
[root@hadoop101 hadoop-2.7.2-src]# pwd
/opt/hadoop-2.7.2-src
(3)通過maven執行編譯命令
[root@hadoop101 hadoop-2.7.2-src]#mvn package -Pdist,native -DskipTests -Dtar
等待時間30分鐘左右,最終成功是全部SUCCESS
# 成功的64位hadoop包在/opt/hadoop-2.7.2-src/hadoop-dist/target下
[root@hadoop101 target]# pwd
/opt/hadoop-2.7.2-src/hadoop-dist/target
(4)編譯原始碼程序中常見的問題及解決方案
(1)MAVEN install時候JVM記憶體溢位
處理方式:在環境組態檔和maven的執行檔案均可調整MAVEN_OPT的heap大小,(詳情查閱MAVEN 編譯 JVM調優問題,如:http://outofmemory.cn/code-snippet/12652/maven-outofmemoryerror-method)
(2)編譯期間maven報錯,可能網路阻塞問題導致依賴庫下載不完整導致,多次執行命令(一次通過比較難):
[root@hadoop101 hadoop-2.7.2-src]#mvn package -Pdist,nativeN -DskipTests -Dtar
(3)報ant、protobuf等錯誤,插件下載未完整或者插件版本問題,最開始鏈接有較多特殊情況,同時推薦
2.7.0版本的問題匯總帖子 http://www.tuicool.com/articles/IBn63qf
相關資料

本文配套GitHub:https://github.com/zhutiansama/FocusBigData
本文配套公眾號:FocusBigData
回復【大資料面經】【大資料面試經驗】【大資料學習路線圖】會有驚喜哦
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/154282.html
標籤:Java
