红联Linux门户
Linux帮助

在Ubuntu 64位OS上运行Hadoop2.2.0[重新编译Hadoop]

发布时间:2015-04-20 15:16:45来源:linux网站作者:canlets

最近在学习搭建Hadoop,我们从Apache官方网站直接下载最新版本Hadoop2.2。官方目前是提供了linux32位系统可执行文件,结果运行时发现提示 “libhadoop.so.1.0.0 which might have disabled stack guard” 的警告。搜索了一下发现是因为 hadoop 2.2.0提供的是libhadoop.so库是32位的,而我们的机器是64位。解决的办法就是重新在64位的机器上编译hadoop。


编译环境
OS: Ubuntu 12.04 64-bit

hadoop version: 2.2.0

Java: Jdk1.7.0_45


安装依赖包
这些库啊包啊基本都会在编译过程中用到,缺少的话会影响编译,看到error了再找solution非常麻烦,提前装好一劳永逸。

$ sudo apt-get install g++ autoconf automake libtool make cmake zlib1g-dev pkg-config libssl-dev因为还要用到ssh,所以如果机器上没有的话,装个openssh的客户端就好啦 (ubuntu 12.04应该预装了)

$ sudo apt-get install openssh-client当然想装server的话就

$ sudo apt-get install openssh-server编译过程中还会用到protobuf 貌似需要最新的2.5.0,因此有低版本的也重新安装一下


安装配置 protobuf
下载最新的protobuf-2.5.0.tar.gz: https://code.google.com/p/protobuf/downloads/list
解压,依次运行

$ ./configure --prefix=/usr
$ sudo make
$ sudo make check
$ sudo make install检查一下版本

$ protoc --version
libprotoc 2.5.0安装配置 maven
ubuntu下用apt-get安装maven

$ sudo apt-get install maven


创建新用户及用户组
我们为hadoop创建一个新组叫“hadoop”,创建一个新用户叫“hduser”属于“hadoop”组 (网上都这么起名字,我们也跟风好了)

$ sudo addgroup hadoop
$ sudo adduser --ingroup hadoop hduser有了新用户以后,我们下面的操作就都要在新用户下完成了

$ su hduser建立ssh信任
hadoop启动的时候要ssh访问localhost,建立信任关系省得老输密码

$ cd /home/hduser
$ ssh-keygen -t rsa -P ""
$ cat .ssh/id_rsa.pub >> .ssh/authorized_keys用命令验证一下是否可以免密码链接localhost

$ ssh localhost这是没有给rsa密钥设密码的情况,但是我觉得吧,一般还是给个密码好,可以用ssh-agent管理,以后也不许要每次都输入

$ ssh-add ~/.ssh/id_rsa.pub  # 参数写成公钥了,应该传私钥进去,感谢twlkyao提醒
$ ssh-add ~/.ssh/id_rsa编译 hadoop 2.2.0
下载 hadoop 2.2.0  http://www.apache.org/dyn/closer.cgi/hadoop/common/

解压到用户目录 /home/hduser/. 进入 hadoop-2.2.0-src 目录

因为已经安装了maven, protobuf, java环境也有了,compiler也有了所以直接运行

$ mvn package -Pdist,native -DskipTests -Dtar正常应该不会有什么错误了, 参数和其他编译选择请看 hadoop目录下的 BUILDING.txt文件


如果在编译时出现如下的错误:

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1:29.469s
[INFO] Finished at: Mon Nov 18 12:30:36 PST 2013
[INFO] Final Memory: 37M/120M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:testCompile (default-testCompile) on project hadoop-auth: Compilation failure: Compilation failure:
[ERROR] /home/chuan/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/AuthenticatorTestCase.java:[84,13] cannot access org.mortbay.component.AbstractLifeCycle
[ERROR] class file for org.mortbay.component.AbstractLifeCycle not found
[ERROR] server = new Server(0);
[ERROR] /home/chuan/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/AuthenticatorTestCase.java:[94,29] cannot access org.mortbay.component.LifeCycle
[ERROR] class file for org.mortbay.component.LifeCycle not found
[ERROR] server.getConnectors()[0].setHost(host);
[ERROR] /home/chuan/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/AuthenticatorTestCase.java:[96,10] cannot find symbol
[ERROR] symbol  : method start()
[ERROR] location: class org.mortbay.jetty.Server
[ERROR] /home/chuan/trunk/hadoop-common-project/hadoop-auth/src/test/java/org/apache/hadoop/security/authentication/client/AuthenticatorTestCase.java:[102,12] cannot find symbol
[ERROR] symbol  : method stop()

目前的2.2.0 的Source Code 压缩包解压出来的code有个bug 需要patch后才能编译。否则编译Hadoop-auth 会提示上面错误。


解决办法如下:

修改下面的pom文件。该文件在hadoop源码包下寻找:

hadoop-common-project/hadoop-auth/pom.xml打开上面的的pom文件,在54行加入如下的依赖:

<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<scope>test</scope>
</dependency>


然后重新运行编译指令即可。编译是一个缓慢的过程,耐心等待哦。

当看到下面的信息时,编译成功。
在Ubuntu 64位OS上运行Hadoop2.2.0[重新编译Hadoop]

注:以上图片上传到红联Linux系统教程频道中。

安装配置 hadoop 2.2.0
此时编译好的文件位于 hadoop-2.2.0-src/hadoop-dist/target/hadoop-2.2.0/ 目录中。