Win10+VS2015 编译win平台hadoop2.9.0

    项目里包含并行处理部分,为了以后服务化做准备,准备上hadoop来替换掉原来的并行框架,原来的是前辈手写的C++,实在难以维护,而且hadoop有自己的文件系统。。

    之前了解hadoop都是在linux平台下,然而这次服务器全是Windows的,网上查了查,感觉还是直接自己编译一个版本靠谱,省着以后跑起来以后再遇到什么问题就悲剧了。

    流程如下:

  • 去官方下载源码,本次选择Hadoop 2.9.0 版本,解压后,找到文件夹内的BUILDING.txt 编译说明文件,windows平台在最下面,先放上镇楼

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

Building on Windows

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

* Windows System
* JDK 1.8+
* Maven 3.3 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.
* Python ( for generation of docs using 'mvn site')

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

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]

说明说的不是很详细,不是按StepByStep来说的,最开始是编译所需的其他支撑软件,详细如下

首先,下载支撑软件,hadoop为java开发,编译工具为Maven,对于Maven,去网上下载3.x.x版本,JDK我安装的是1.8.0版本,下载好这两个软件之后,先安装jdk,对于JDK的安装,说一下,路径选择Win平台下不要安装在Program Files文件夹中,因为win7之后的Program Files文件夹都有空格,带的jre无所谓,有空格不仅影响安装,还会在之后使用hadoop时候,提示无法打开jar包的各种奇怪问题。maven直接解压在目录然后添加系统路径。

jdk安装好后,配置系统Path以及Classpath

如下图所示:

首先,设置环境变量,现在不设置之后配置hadoop也要设置


之后是path设置


随后下载Findbugs,解压,配置路径


然后是protocbuff的下载,这里说一下,网上好多人说要对源码编译,其实是不需要的只是我这没编译也可以,直接下载win32zip,解压得到exe,将路径配置到系统路径中,protoc.exe是一个编译工具,会被maven调用,而protobuff是google内部使用的文件交换格式开发代码,完全开源,之后有时间好好研究一下,性能非常不错。protoc一定下载2.5.0版本,不然后续编译过不去


最后安装CMake,安装选择时候把添加环境路径和系统路径选择上,之后就 不用配置了。

左后下载ZLib源码,解压

=============================================================

安装好了相关软件,开始编译工作,我是用的VS2015进行的编译,那么问题来了,原文要求,vs2010,直接编译会报错。

首先,明确vs编译在源码编译过程中的作用,

        切换到该路径

有如下工程


那么,与vs相关的工程为native,与winutils,native工程最后生成的就是hadoop.dll,而winutils最后生成的是libwinutils.lib和winutils.exe;想在win下部署hadoop的同学应该不陌生,最开始查资料的时候,网上提的最多的就是这些。这些生成的二进制文件最终都会编译到hadoop的bin路径下,提供运行时的支持,而且,根据vs版本的不同,需要不同的微软运行时的库作为支撑。

那么,如何解决版本的问题,因为实在不想再装vs2010,参照网上的做法,将winutils工程与native工程打开,按照提示升级项目,然后跑一遍编译,报错不管,关闭

而与平台相关的C工程还有一处,即hdfs下,


这里全是C代码,最终生成一个hdfs.dll 和对应的hdfs.lib 应该是hdfs相关操作的运行时支持,

由于hadoop代码由maven驱动编译,因此我们去pom文件中找一下相关参数,改成vs2015 支持的就好

pom路径


找到如下xml段

                    <condition property="generator" value="Visual Studio 14" else="Visual Studio 14 2015 Win64">
                      <equals arg1="Win32" arg2="${env.PLATFORM}" />
                    </condition>

原文为vs2010 相关的,改成2015相关即可

基本上,准备工作已经做好, 开始编译过程:首先,以管理员身份运行vs开发者命令行工具

然后 set目标平台,我需要到64位下,因此,输入 set Platform=x64 回车

然后设置ZLIB_HOME set ZLIB_HOME = 你的zlib路径 


然后命令行切换到hadoop 源码路径下,

输入

mvnpackage -Pdist -DskipTests –Dtar

编译开始,这里说一下,许多jar包要去网上下载,建议切换到国内的repo库,aliyun的就行,下载好久进行不下去,可以ctrl c 停止再开始。


最后  编译完成,提示build success

===================================================================

后记

关于hadoop win 支撑环境的生成,也就是hadoop.dll, winutils, hdfs.dll/lib,其实后来发现大可不必走mvn这一套,可以单独用vs进行编译,这样一来,可以用不同的vs编译出不同的版本,最后替换到一套执行文件中即可,后续会添加相关内容



评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值