首先要下载hadoop源码包,并放在linux目录中进行解压。解压后能够看到文件目录的结构:linux
leiline@master:~/Documents/CompileHadoop/hadoop-2.7.5-src$ ll total 220 drwxr-xr-x 19 leiline leiline 4096 12月 16 07:26 ./ drwxrwxr-x 3 leiline leiline 4096 1月 7 15:16 ../ -rw-r--r-- 1 leiline leiline 13050 12月 16 04:02 BUILDING.txt drwx------ 3 leiline leiline 4096 1月 7 15:16 dev-support/ drwx------ 4 leiline leiline 4096 1月 7 15:16 hadoop-assemblies/ drwx------ 3 leiline leiline 4096 1月 7 15:16 hadoop-build-tools/ drwx------ 3 leiline leiline 4096 1月 7 15:16 hadoop-client/ drwxr-xr-x 9 leiline leiline 4096 12月 16 04:02 hadoop-client-modules/ drwxr-xr-x 3 leiline leiline 4096 12月 16 04:02 hadoop-cloud-storage-project/ drwx------ 10 leiline leiline 4096 1月 7 15:16 hadoop-common-project/ drwx------ 3 leiline leiline 4096 1月 7 15:16 hadoop-dist/ drwx------ 8 leiline leiline 4096 1月 7 15:16 hadoop-hdfs-project/ drwx------ 9 leiline leiline 4096 1月 7 15:16 hadoop-mapreduce-project/ drwx------ 4 leiline leiline 4096 1月 7 15:16 hadoop-maven-plugins/ drwx------ 3 leiline leiline 4096 1月 7 15:16 hadoop-minicluster/ drwx------ 4 leiline leiline 4096 1月 7 15:16 hadoop-project/ drwx------ 3 leiline leiline 4096 1月 7 15:16 hadoop-project-dist/ drwx------ 21 leiline leiline 4096 1月 7 15:16 hadoop-tools/ drwx------ 3 leiline leiline 4096 1月 7 15:16 hadoop-yarn-project/ -rw-r--r-- 1 leiline leiline 86424 12月 16 04:02 LICENSE.txt -rw-r--r-- 1 leiline leiline 14978 12月 16 04:02 NOTICE.txt -rw-r--r-- 1 leiline leiline 18993 12月 16 06:53 pom.xml -rw-r--r-- 1 leiline leiline 1366 7月 25 09:19 README.txt drwxrwxr-x 2 leiline leiline 4096 1月 7 15:16 .settings/
在BUILDING.txt文件中有对编译的要求。maven
Requirements: * Unix System * JDK 1.7+ * Maven 3.0 or later * Findbugs 1.3.9 (if running findbugs) * ProtocolBuffer 2.5.0 * CMake 2.6 or newer (if compiling native code), must be 3.0 or newer on Mac * Zlib devel (if compiling native code) * openssl devel ( if compiling native hadoop-pipes and to get the best HDFS encryption performance ) * Linux FUSE (Filesystem in Userspace) version 2.6 or above ( if compiling fuse_dfs ) * Internet connection for first build (to fetch all Maven and Hadoop dependencies)
* Maven $ sudo apt-get -y install maven * Native libraries $ sudo apt-get -y install build-essential autoconf automake libtool cmake zlib1g-dev pkg-config libssl-dev * ProtocolBuffer 2.5.0 (required) $ sudo apt-get -y install libprotobuf-dev protobuf-compiler
进入hadoop source src目录oop
mvn package -Pdist,native -DskipTests -Dtar
编译好的二进制包在以下目录:fetch
hadoop-2.7.5-src/hadoop-dist/target/