在 win7 64 上编译 hadoop 2.7.3的经历

来源:互联网 发布:淘宝rx65电子狗 编辑:程序博客网 时间:2024/05/18 15:04

在 win7 64 上编译 hadoop 2.7.3的经历

---bySpring Pu

主要参考链接:https://wiki.apache.org/hadoop/Hadoop2OnWindows ;

                            http://hadoop.apache.org/docs/stable/ ;


想在本机上编译使用下 hadoop 2.7.3,本来想装个虚拟机的,但是我机子的配置是 Thinkpad E420 cpu i3 2330M , 8G 内存 ,发现也可以直接在 windows 上弄,那我就干脆优先用 windows 环境,这样使用可能会比较方便,不用分内存和硬盘给额外的虚拟机。

 

开始听说 CDH 的影响比较大,想去CDH下载下,CDH 上还要提交个人信息,目的啥的。就犹豫了下,去Apache 官网,用 Apache 的还有个好处,估计遇到问题,网上找到的答案也会比较多。而且后来做到一半,同时去CDH 去下个 VMvare 版本的虚拟机,结果下载速度很慢,老是断,断断续续下了几天,才下好,而那时候,我已经在 Windows 7 64上编译完 apache hadoop了。

   在编译 Apache Hadoop 的过程中,遇到了好几个问题,折腾了几天,不大顺利,才弄好,因此记录下。

   去 Apache 官网 http://hadoop.apache.org/ 找到下载页面,怕出错什么的,找了个稳定版本的链接,于是选择了较新的稳定版本2.7.3。然后查看官方文档,由于是本机单机使用,所以看了 http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html 这个链接。

   然后发现在 windows 上也可以直接部署使用,于是我点开了 https://wiki.apache.org/hadoop/Hadoop2OnWindows 里面提到 Windows 7 are also likely to work. 所以就一步步往下走了。

   1. 安装 JDK, 设置  JAVA_HOME

       -- 本机上本来就安装了oracle jdk 1.8. 于是加上了环境变量,我本地设置是 C:\Program Files\Java\jdk1.8.0_121 ,中间有空格,虽然文档上说路径不要有空格,有空格的要用Windows 8.3 Pathname 替代,但是我百度后,参照别人的改成类似 Progra^1 反而说找不到,点开那个文档后发现,空格的也可以用引号把路径引起来,所以加引号,当时好像是可以,但是编译到一半时,代码用有引用到这个环境变量的地方,报错了,查了一下,是引号的问题,JAVA_HOME 环境变量有空格的话,如果直接在路径首尾加上引号,会导致在某些引用了环境变量后再次加引号的字符串报错。比如 "${JAVA_HOME}\bin\xxx" 如果在 JAVA_HOME字串上本身加引号会有问题。我想后面空格没有问题,也许是因为后来装了类 Unix 命令行。

       所以这里有空格也是可以编译过的,至少在这个 2.7.3 版本上。但是建议jdk安装路径不要有空格,因为后来发现,install的时候会报错,说 JAVA_HOME设置得不正确。。


 2. 下载完代码后,在代码主目录下有个 BUILDING.txt

可以看到文档的前面部分都是讲的怎么在linux 环境下编译。可以一直拉到文件末尾看到 Building on Windows 部分的说明。

 这段不长,我贴下来:

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

 

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 2010Professional

* Windows SDK 8.1 (if building CPU rate control forthe container executor)

* zlib headers (if building native code bindingsfor zlib)

* Internet connection for first build (to fetch allMaven 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 theWindows Git package which

can be downloaded fromhttp://git-scm.com/download/win.

 

If using Visual Studio, it must be Visual Studio2010 Professional (not 2012).

Do not use Visual Studio Express.  It does not support compiling for 64-bit,

which is problematic if running a 64-bitsystem.  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 avoidrunning 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 CommandPrompt.)

 

JAVA_HOME must be set, and the path must notcontain spaces.  If the full path

would contain spaces, then use the Windows shortpath instead.

 

You must set the Platform environment variable toeither x64 or Win32 depending

on whether you're running a 64-bit or 32-bitsystem.  Note that this is

case-sensitive. It must be "Platform", not "PLATFORM" or"platform".

Environment variables on Windows are usuallycase-insensitive, but Maven treats

them as case-sensitive.  Failure to set this environment variablecorrectly will

cause msbuild to fail while building the nativecode in hadoop-common.

 

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

set Platform=Win32 (when building on a 32-bitsystem)

 

Several tests require that the user must have theCreate Symbolic Links

privilege.

 

All Maven goals are the same as described abovewith the exception that

native code is built by enabling the 'native-win'Maven profile. -Pnative-win

is enabled by default when building on Windowssince the native components

are required (not optional) on Windows.

 

If native code bindings for zlib are required, thenthe 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 thePATH.  Hadoop has been tested

with zlib 1.2.7, built using Visual Studio 2010 outof contrib\vstudio\vc10 in

the zlib 1.2.7 source tree.

 

http://www.zlib.net/

 

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

Building distributions:

 

 * Builddistribution with native code    : mvnpackage [-Pdist][-Pdocs][-Psrc][-Dtar]

 

  首先呢,确实一定要认真仔细地看这个说明,然后逐个执行,比如要设置环境变量Platform,不然编译过程中会说找不到这个环境变量。可以在命令行中,编译前设置下。我是直接在环境变量里面设置了,估计一般的程序不会用到这个同名变量。因为我电脑是64位的所以我设置了Platform=x64。

下面逐个再讲下上面要点中要注意的:

* 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 2010Professional

* Windows SDK 8.1 (if building CPU rate control forthe container executor)

* zlib headers (if building native code bindingsfor zlib)

* Internet connection for first build (to fetch allMaven and Hadoop dependencies)

* Unix command-line tools from GnuWin32: sh, mkdir,rm, cp, tar, gzip. These tools must be present on your PATH.

第一个第二个条件,前面都讲了。

 

Maven我下载的 3.5版本的。安装后,设置环境变量MAVEN_HOME ,程序是免安装的版本。

 

Findbugs我也下载了,下的是findbugs-3.0.1版本。是免安装的,放好位置后,设置环境变量FINDBUGS_HOME,开始我没有设置这个,编译会报错。

 

ProtocolBuffer下的是protoc-2.5.0-windows-x86_64.exe, 这个不是安装程序,就是目标程序。我没有把它的路径放到 Path中,是直接把它拷贝到C:\Windows\System32下,要注意要把它手动改名为protoc.exe,不然会找不到程序。

 

CMake我下载的是cmake-3.3.2-win32-x86.exe,运行安装后,把它安装目录下的 bin文件夹放到 Path路径中。

 

Winsdk 7.1 ,开始我以为装 vs2010更小,更方便,而且后面提到了用vs2010编译zlib 啥的,就先装的 vs2010,我这里建议装 sdk7.1,因为它提供的链接中,是sdk7.1+.net framework 4.0的,在安装过程中,可以看到组件中默认选择了 vs2010,所以我感觉直接装sdk7.1更省事。

 

Winsdk 8.1 这个,我都怀疑有没有必要装。因为后来发现这个工具,在编译 hadoop过程中,似乎会跟 sdk7.1有点冲突。Sdk8.1 配置的是 .net 4.5 和net 4.5.1 sdk。上面文档括号中说是编译cpu 速度控制的,我后来为了装虚拟机环境,打开了 bios 中的 vt-d 相关的2个开关,不知道跟这个项有没有关系,如果遇到未知问题,建议也去打开那2个 cpu虚拟化开关。编译过程中遇到过一个问题,卡了很久,后来根据http://stackoverflow.com/questions/31295963/hadoop-on-windows-building-installation-error/31331173#31331173 这个链接的建议解决了问题。就是在安装好 sdk8.1后,再去控制面板中卸载掉 .net 4.0以上的软件,由于我反复折腾,离线安装过 .net 4.0, 也做过那个 .net 4.0以上 .net版本的卸载,后来 sdk 8.1卸载或者重装不了了,说是缺少 .net 工具,我装上离线安装版本的 .net4.0还是不行,其实它需要的是 .net 4.5,所以我在 Microsoft 官网找到 .net 4.5 的 full安装包,安装后,又在控制面板中,对 sdk8.1进行了修复安装,它又下载了一个 .net 4.5 sdk 相关的软件。然后为了解决那个报错,我又把这个状态下的 .net 4.5 和 .net4.5 sdk这2个程序卸载了,虽然 sdk 8.1不能做修复安装或者卸载了,先不管。去 vs2010目录下的 .net framework64 目录下看 4.0的状态,可能在卸载4.5的 full版本时会同时remove掉这里的 4.0版本,因为.net4.0是必要组件,所以我又运行 sdk7.1的iso中的 autorun.exe执行修复操作,结束后会发现目录下原来的 .net4.0内容恢复过来了。这样状态确实能编译过,或许是不该装 sdk8.1…不知道。哈哈。安装卸载过程中提示你要重启电脑,可以先不理,到最后都弄完后正式编译前再重启。

 

Zlibheaders,  这条也折腾了下。我下载的是按下方英文说明的zlib官网的 zlib1.2.7版本,但是说明中提到了用 Zlib 编译。。最后可行的是把它下下来解压,设置好ZLIB_HOME,然后在它文档中找来找去,说要编一个 zlib1.dll ,其实也不用,因为后来我发现其他比较新的软件中,比如我安装的 git,已经带了这个库,我估计也比较新,够用了,结果是能过编译。

 

电脑能连接互联网,这条,大概因为在编译过程中要通过maven 下载部分依赖的程序。但是网速不大好,下载比较慢,而且有时还会因为下载超时编译失败,这个一定要注意,不要弄错了,网络原因编译失败,再运行一次,它会很快接着跑到这个编译进度这里。凌晨的速度会比较好。。网上有人直接下离线的依赖包,我对相关需要的包不大熟悉,还是采用的联网自动下载方式。

 

Unix like 的命令行,这个地方推荐的是GnuWin32,我建议用Git也行,我是在上面下源码过程中,安装了64位的git,在安装过程中,记得要勾选那些跟命令行工具相关的选项,安装完后,不仅在命令行中能用 git还能用linux命令 ls之类的。而且可能还顺便解决了 zlib1.dll 问题。

 

编译过程中,还会碰到 ant 编译错误问题,上面没有提到要装 ANT,在错误发生后,我下载安装了apacheant 1.10.1 ,它是免安装的,解压放好后,设置好ANT_HOME。

 

文档中没有说要装 Git,上面我建议你装 Git。并设置好GIT_HOME,我本地 Git 在下载源码前装的,所以安装时没注意,路径中跟JAVA_HOME一样带了空格,也是没有问题的。

 

Home之类的环境变量,我本机设置的,在上面都提到了。环境变量很重要,path类的环境变量,我本地具体设置如下:

%ANT_HOME%\bin;C:\ProgramData\Oracle\Java\javapath;%ANDROID_HOME%\platform-tools\;%ANDROID_HOME%\tools\;%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;"%JAVA_HOME%\bin";%MAVEN_HOME%\bin;C:\ProgramFiles (x86)\Windows Kits\8.1\Windows PerformanceToolkit\;%GIT_HOME%\cmd;%GIT_HOME%\mingw64\bin;%GIT_HOME%\usr\bin;%FINDBUGS_HOME%\bin;C:\big_data\cmake-3.8.1-win64-x64\bin;C:\ProgramFiles (x86)\Windows Kits\8.1\bin;

Windowskits 8.1 相关的几个,不是我手动设置的,是安装sdk 8.1过程中自动加的。ANDROID_HOME 相关的路径,之前就安装了,应该没有影响。为了统一,我把这次编译中需要的大部分工具安装或放置在C:\big_data目录下。

 

3. 编译代码,在所有程序里,找到 Microsoft Visual Studio找到 Visual Studio Tools, 选择 Visual Studio x64 win64 命令提示(2010),然后进入到解压后的hadoop 的主目录中,输入命令编译:

mvn package -Pdist -DskipTests -Dtar

刚开始没带 –DskipTests 参数,在编译测试包时遇到问题。所以建议加入这个参数。然后这个版本中文档中提到,在 windows 下编译不需要加上-Pnative-win参数,因为这个版本,windows 默认会加上这个参数。

我刚开始用的普通的 cmd 编译的,后来碰到了 MSBuild命令找不到问题,这个命令是 .Net Framework 多个版本中含有的命令。网上查了下说是要把这个.net 4.0 版本中命令的路径放到环境变量 Path 中,我试过。但是我不建议这样做,因为设置个环境变量,是全局性的了。而每次在 cmd 中手动设又麻烦,而打开我上面说的那个 Visual Studio 的命令行,既保证了是64位的编译,又是以 Admin 的权限开的,打开后可以看到标题栏的提示为管理员。还能确保能调用 MSBuild.在这个里面输入 MSBuild,刚好会告诉你现在使用的 MSBuild 版本就是 4.0 版本的。

我用的编译命令是mvn package -Pdist -Pdocs-DskipTests –Dtar

我同时生成了下 docs。

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

后续,要进行安装,可以遵照 https://wiki.apache.org/hadoop/Hadoop2OnWindows 继续执行 install流程。用伪分布式部署在本机。

 

0 0