1. 程式人生 > >在Windows 7中編譯Hadoop 2.7.7

在Windows 7中編譯Hadoop 2.7.7

一、下載Hadoop2.7.7原始碼

解壓後,檢視BUILDING.txt檔案,其中詳細描述了在windows下編譯hadoop需要的條件和步驟,具體見下:

----------------------------------------------------------------------------------

Building on Windows

----------------------------------------------------------------------------------
Requirements:

* Windows 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
* Windows SDK 7.1 or Visual Studio 2010 Professional
* Windows SDK 8.1 (if building CPU rate control for the container executor)
* zlib headers (if building native code bindings for zlib)
* Internet connection for first build (to fetch all Maven and Hadoop dependencies)
* Unix command-line tools from GnuWin32: sh, mkdir, rm, cp, tar, gzip. These
  tools must be present on your PATH.

Unix command-line tools are also included with the Windows Git package which
can be downloaded from http://git-scm.com/download/win.

If using Visual Studio, it must be Visual Studio 2010 Professional (not 2012).
Do not use Visual Studio Express.  It does not support compiling for 64-bit,
which is problematic if running a 64-bit system.  The Windows SDK 7.1 is free to
download here:

http://www.microsoft.com/en-us/download/details.aspx?id=8279

The Windows SDK 8.1 is available to download at:

http://msdn.microsoft.com/en-us/windows/bg162891.aspx

Cygwin is neither required nor supported.

----------------------------------------------------------------------------------
Building:

Keep the source code tree in a short path to avoid running into problems related
to Windows maximum path length limitation.  (For example, C:\hdc).

Run builds from a Windows SDK Command Prompt.  (Start, All Programs,
Microsoft Windows SDK v7.1, Windows SDK 7.1 Command Prompt.)

JAVA_HOME must be set, and the path must not contain spaces.  If the full path
would contain spaces, then use the Windows short path instead.

You must set the Platform environment variable to either x64 or Win32 depending
on whether you're running a 64-bit or 32-bit system.  Note that this is
case-sensitive.  It must be "Platform", not "PLATFORM" or "platform".
Environment variables on Windows are usually case-insensitive, but Maven treats
them as case-sensitive.  Failure to set this environment variable correctly will
cause msbuild to fail while building the native code in hadoop-common.

set Platform=x64 (when building on a 64-bit system)
set Platform=Win32 (when building on a 32-bit system)

Several tests require that the user must have the Create Symbolic Links
privilege.

All Maven goals are the same as described above with the exception that
native code is built by enabling the 'native-win' Maven profile. -Pnative-win
is enabled by default when building on Windows since the native components
are required (not optional) on Windows.

If native code bindings for zlib are required, then the zlib headers must be
deployed on the build machine.  Set the ZLIB_HOME environment variable to the
directory containing the headers.

set ZLIB_HOME=C:\zlib-1.2.7

At runtime, zlib1.dll must be accessible on the PATH.  Hadoop has been tested
with zlib 1.2.7, built using Visual Studio 2010 out of contrib\vstudio\vc10 in
the zlib 1.2.7 source tree.

http://www.zlib.net/

----------------------------------------------------------------------------------
Building distributions:

 * Build distribution with native code    : mvn package [-Pdist][-Pdocs][-Psrc][-Dtar]

二、環境準備

1.mvn

下載apache-maven-3.3.9-bin.zip,解壓到指定目錄,配置環境變數MAVEN_HOME,在Path中新增%MAVEN_HOME%\bin。

配置完成後, 在CMD中執行mvn -version檢查是否安裝成功。

2.jdk

下載jdk-8u152-windows-x64.exe,根據安裝指南進行安裝,配置環境變數JAVA_HOME,在Path中新增%JAVA_HOME%\bin和%JAVA_HOME%\jre\bin,在CLASSPATH中新增%JAVA_HOME%\lib;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar。

配置完成後, 在CMD中執行java -version檢查是否安裝成功。

3.findbug

下載findbugs-3.0.1.zip,https://nchc.dl.sourceforge.net/project/findbugs/findbugs/3.0.1/findbugs-3.0.1.tar.gz,解壓到指定目錄,配置環境變數FINDBUGS_HOME,在Path中新增%FINDBUGS_HOME%\bin。

配置完成後, 在CMD中執行findbugs -version檢查是否安裝成功。

4.cmake

下載cmake-3.12.4-win64-x64.ziphttps://cmake.org/files/v3.12/cmake-3.12.4-win64-x64.zip

,解壓到指定目錄,配置環境變數CMAKE_HOME,在Path中新增%CMAKE_HOME%\bin。

配置完成後, 在CMD中執行cmake -version檢查是否安裝成功。

5.zlib

下載zlib128-dll.zip,http://zlib.net/zlib128-dll.zip,解壓到指定目錄,配置環境變數,將zlib128-dll的目錄新增到Path。

6.git

git安裝後可以在windows上執行linux
下載Git-2.19.1-64-bit.exe,https://github-production-release-asset-2e65be.s3.amazonaws.com/23216272/081b0800-c8c2-11e8-9f25-2e5ceff4ec71?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20181107%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20181107T072232Z&X-Amz-Expires=300&X-Amz-Signature=0307ffb083ee4c28ee0892840fd321972f45172768d9c7ed05da8bcbcdbcfaad&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3DGit-2.19.1-64-bit.exe&response-content-type=application%2Foctet-stream 。點選,根據安裝指南進行安裝,在安裝過程中,記得要勾選那些跟命令列工具相關的選項。

安裝完成後開啟cmd,輸入linux的命令測試下,比如ls,find等

7.protobuf

下載protobuf-2.5.0.zip和protoc-2.5.0-win32.zip,解壓到指定目錄。

解壓protoc-2.5.0-win32.zip會得到一個protoc.exe檔案;

解壓protobuf-2.5.0.tar.gz,我的解壓路徑是E:\work\hadoop\protobuf-2.5.0;
a) 將protoc.exe檔案拷貝到C:\Windows\System32目錄下;
b) 將protoc.exe拷貝到解壓後的E:\work\hadoop\protobuf-2.5.0\src目錄中
c) 在windows的cmd中進入E:\work\hadoop\protobuf-2.5.0\java 目錄,執行 "mvn package"命令,開始編譯,最終會在E:\work\hadoop\protobuf-2.5.0\java\target目錄下生成一個protobuf-java-2.5.0.jar包;
d) 如果命令列介面出現"BUILD SUCCESS"結果說明protobuf安裝成功,使用"protoc --version"命令來檢視安裝是否成功:


8.Windows SDK7.1

下載 window SDK 7.1, https://go.microsoft.com/fwlink/p/?LinkId=323507,點選進行安裝。

9. Visual Studio 2010 Professional

ps: 剛開始只安裝了Windows SDK7.1,編譯時報錯

E:\work\hadoop\hadoop-2.7.7-src\hadoop-common-project\hadoop-common\src\main\winutils\libwinutils.vcxproj(44,3): error MSB4019: 未找到匯入的專案“E:\Microsoft.Cpp.Default.props”。請確認 <Import> 宣告中的路徑正確,且磁碟上存在該檔案。

在網上查,網友回答可能是vs沒安裝,故又安裝vs2010(參考https://blog.csdn.net/huohuanyu1/article/details/73291800),但安裝後該問題仍然存在,不知是否是安裝問題。

三、編譯Hadoop原始碼

在所有程式裡,找到 Microsoft Visual Studio --> Visual Studio Tools --> Visual Studio x64 win64 命令提示(2010),然後進入到解壓後的hadoop 的主目錄中(要先進入碟符,再進入目錄),輸入命令編譯:

mvn package -Pdist -Pdocs -DskipTests -Dtar

編譯時仍報錯:

E:\work\hadoop\hadoop-2.7.7-src\hadoop-common-project\hadoop-common\src\main\winutils\libwinutils.vcxproj(44,3): error MSB4019: 未找到匯入的專案“E:\Microsoft.Cpp.Default.props”。請確認 <Import> 宣告中的路徑正確,且磁碟上存在該檔案。

最後無奈之下,手動設定了VCTargetsPath

set Platform=x64
set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0

至此,編譯正常進行。

參考文章:

https://blog.csdn.net/nidaye13123/article/details/78872329

https://blog.csdn.net/buxinchun/article/details/71335937