如何在CentOS6.5下编译64位的Hadoop2.x
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在CentOS6.5下编译64位的Hadoop2.x相关的知识,希望对你有一定的参考价值。
参考技术Ahadoop2.x在apache官网直接下载的并没有64位直接能用的版本,如果我们想在64位系统使用,那么就需要重新编译hadoop,否则直接使用32位的hadoop运行在64位的系统上,将会出现一些库不兼容的异常。如下图所示,最直接的一个异常:
在这之前,先用一个表格来描述下散仙的编译的环境的状况:
序号 描述 备注
1 centos6.5系统64位 linux环境
2 Apache Ant1.9 ant编译
3 Apache Maven3.2.1 maven打包部署
4 gcc,gcc-c++,make 依赖库
5 protobuf-2.5.0 序列化库
6 JDK1.7 JAVA 环境
7 Hadoop2.2.0源码包 官网下载
8 屌丝工程师一名 主角
9 hadoop交流群376932160 技术交流
下面进入正题,散仙的环境是在centos下,所以大部分安装编译依赖库,都可以很方便的使用yum命令来完成。
1,安装gcc,执行如下的几个yum命令即可
Java代码
yum -y install gcc
yum install -y bzip2-devel
yum -y install gcc-c++
yum install make
yum install autoconf automake libtool cmake ncurses-devel openssl-devel gcc*
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">yum -y install gcc
yum install -y bzip2-devel
yum -y install gcc-c++
yum install make
yum install autoconf automake libtool cmake ncurses-devel openssl-devel gcc*
</span>
2,安装JDK,并设置环境变量,完成后测试安装成功否
Java代码
[root@ganglia ~]# java -version
java version "1.5.0"
gij (GNU libgcj) version 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@ganglia ~]#
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">[root@ganglia ~]# java -version
java version "1.5.0"
gij (GNU libgcj) version 4.4.7 20120313 (Red Hat 4.4.7-4)
Copyright (C) 2007 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@ganglia ~]# </span>
3, 安装Maven,安装完成后测试安装与否
Java代码
[root@ganglia ~]# mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T01:37:52+08:00)
Maven home: /usr/local/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/local/jdk1.7.0_25/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-431.el6.x86_64", arch: "amd64", family: "unix"
[root@ganglia ~]#
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">[root@ganglia ~]# mvn -v
Apache Maven 3.2.1 (ea8b2b07643dbb1b84b6d16e1f08391b666bc1e9; 2014-02-15T01:37:52+08:00)
Maven home: /usr/local/maven
Java version: 1.7.0_25, vendor: Oracle Corporation
Java home: /usr/local/jdk1.7.0_25/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "2.6.32-431.el6.x86_64", arch: "amd64", family: "unix"
[root@ganglia ~]# </span>
4, 安装Ant, 安装完成后,依旧测试成功与否
Java代码
[root@ganglia ~]# ant -version
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
[root@ganglia ~]#
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">[root@ganglia ~]# ant -version
Apache Ant(TM) version 1.9.4 compiled on April 29 2014
[root@ganglia ~]# </span>
5,安装protobuf,安装方式,从官网下载tar.gz的包点击下载,并上传到linux上解压,然后进入根目录下,执行如下的几个命令:
wget https://protobuf.googlecode.com/files/protobuf-2.5.0.tar.bz2
Java代码
./configure
make
make check
make install
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">./configure
make
make check
make install</span>
然后,执行如下命令,进行测试安装成功与否
[root@ganglia protobuf-2.5.0]# protoc
Missing input file.
[root@ganglia protobuf-2.5.0]#
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">[root@ganglia protobuf-2.5.0]# protoc
Missing input file.
[root@ganglia protobuf-2.5.0]# </span>
6,从hadoop官网下载hadoop2.2.0的版本的源码的src的包,并查看目录
[root@ganglia ~]# cd hadoop-2.2.0-src
[root@ganglia hadoop-2.2.0-src]# ll
总用量 108
-rw-r--r--. 1 67974 users 9968 10月 7 2013 BUILDING.txt
drwxr-xr-x. 2 67974 users 4096 10月 7 2013 dev-support
drwxr-xr-x. 4 67974 users 4096 6月 9 17:05 hadoop-assemblies
drwxr-xr-x. 3 67974 users 4096 6月 9 17:27 hadoop-client
drwxr-xr-x. 9 67974 users 4096 6月 9 17:14 hadoop-common-project
drwxr-xr-x. 3 67974 users 4096 6月 9 17:26 hadoop-dist
drwxr-xr-x. 7 67974 users 4096 6月 9 17:20 hadoop-hdfs-project
drwxr-xr-x. 11 67974 users 4096 6月 9 17:25 hadoop-mapreduce-project
drwxr-xr-x. 4 67974 users 4096 6月 9 17:06 hadoop-maven-plugins
drwxr-xr-x. 3 67974 users 4096 6月 9 17:27 hadoop-minicluster
drwxr-xr-x. 4 67974 users 4096 6月 9 17:03 hadoop-project
drwxr-xr-x. 3 67974 users 4096 6月 9 17:05 hadoop-project-dist
drwxr-xr-x. 12 67974 users 4096 6月 9 17:26 hadoop-tools
drwxr-xr-x. 4 67974 users 4096 6月 9 17:24 hadoop-yarn-project
-rw-r--r--. 1 67974 users 15164 10月 7 2013 LICENSE.txt
-rw-r--r--. 1 67974 users 101 10月 7 2013 NOTICE.txt
-rw-r--r--. 1 67974 users 16569 10月 7 2013 pom.xml
-rw-r--r--. 1 67974 users 1366 10月 7 2013 README.txt
[root@ganglia hadoop-2.2.0-src]#
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">[root@ganglia ~]# cd hadoop-2.2.0-src
[root@ganglia hadoop-2.2.0-src]# ll
总用量 108
-rw-r--r--. 1 67974 users 9968 10月 7 2013 BUILDING.txt
drwxr-xr-x. 2 67974 users 4096 10月 7 2013 dev-support
drwxr-xr-x. 4 67974 users 4096 6月 9 17:05 hadoop-assemblies
drwxr-xr-x. 3 67974 users 4096 6月 9 17:27 hadoop-client
drwxr-xr-x. 9 67974 users 4096 6月 9 17:14 hadoop-common-project
drwxr-xr-x. 3 67974 users 4096 6月 9 17:26 hadoop-dist
drwxr-xr-x. 7 67974 users 4096 6月 9 17:20 hadoop-hdfs-project
drwxr-xr-x. 11 67974 users 4096 6月 9 17:25 hadoop-mapreduce-project
drwxr-xr-x. 4 67974 users 4096 6月 9 17:06 hadoop-maven-plugins
drwxr-xr-x. 3 67974 users 4096 6月 9 17:27 hadoop-minicluster
drwxr-xr-x. 4 67974 users 4096 6月 9 17:03 hadoop-project
drwxr-xr-x. 3 67974 users 4096 6月 9 17:05 hadoop-project-dist
drwxr-xr-x. 12 67974 users 4096 6月 9 17:26 hadoop-tools
drwxr-xr-x. 4 67974 users 4096 6月 9 17:24 hadoop-yarn-project
-rw-r--r--. 1 67974 users 15164 10月 7 2013 LICENSE.txt
-rw-r--r--. 1 67974 users 101 10月 7 2013 NOTICE.txt
-rw-r--r--. 1 67974 users 16569 10月 7 2013 pom.xml
-rw-r--r--. 1 67974 users 1366 10月 7 2013 README.txt
[root@ganglia hadoop-2.2.0-src]# </span>
7,修改/root/hadoop-2.2.0-src/hadoop-common-project/hadoop-auth/pom.xml文件,增加,补丁内容,这部分是hadoop2.2.0的bug,如果是其他的2.x的版本,可以视情况而定,内容如下:
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<!--新增的内容开始 -->
<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>
[xml] view plain copy
<span style="font-family:Arial;font-size:12px;"> <dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<scope>test</scope>
</dependency>
<!--新增的内容开始 -->
<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></span>
8,修改完毕后,回到hadoop-2.2.0-src的跟目录下执行编译打包命令:
mvn clean
mvn package -Pdist,native -DskipTests -Dtar
[java] view plain copy
<span style="font-family:Arial;font-size:12px;">mvn clean
mvn package -Pdist,native -DskipTests -Dtar
</span>
然后等待半个小时左右的编译时间,网速快的话,时间可能会更短,编译完成后,输出的打包信息如下:
[INFO]
[INFO] --- maven-resources-plugin:2.2:resources (default-resources) @ hadoop-minicluster ---
[INFO] Using default encoding to copy filtered resources.
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ hadoop-minicluster ---
[INFO] No sources to compile
[INFO]
[INFO] --- maven-resources-plugin:2.2:testResources (default-testResources) @ hadoop-minicluster ---
[INFO] Using default encoding to copy filtered resources.
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-
Centos7 下编译 Openjdk8
本文主要介绍如何在 Centos7 下编译 Openjdk8 源码,《深入理解java虚拟机》第二版网上好多 openjdk7 的帖子,编译 jdk8 和 7 还是有些差别的,比如大家经常提到的 make sanity 在 jdk8 源码里是没有的,下面我们一步步编译 openjdk8。
1 安装Bootstrap JDK
这里完全按照官方的说明来的。
1
|
yum install java-1.8.0-openjdk
|
然后 java -version
看下已安装的 jdk 版本,确实是 1.8.0 哈
1
|
[[email protected] ~]# java -version
|
2 下载openjdk1.8源码
首先安装 hd yum install hg
,接着开始下载源码,网络不好的话,这个下载会特别慢!
1
|
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u openjdk8
|
3 安装依赖
1
|
yum install alsa-lib-devel cups-devel libX* gcc gcc-c++ freetype-devel libstdc++-static ant make
|
4 编译配置
切换到 openjdk8 目录
1
|
chmod +x configure
|
5 编译
直接在openjdk8下执行make
,控制台提示
[[email protected] openjdk8]# make
No CONF given, but more than one configuration found in /app/openjdk8//build.
Available configurations:
* linux-x86_64-normal-server-fastdebug
* linux-x86_64-normal-server-release
Please retry building with CONF=<config pattern> (or SPEC=<specfile>)
Makefile:55: *** Cannot continue. Stop.
我们只需要安装提示重新 make CONF=linux-x86_64-normal-server-fastdebug
就行了, make 过程比较费时间,可能提出类似如下错误提示
[[email protected] openjdk8]# make
[Error] encoded value was less than 0: encode(-8.326673E-17, 5.0, 11.0, 16.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
[Error] encoded value was greater than 3: encode(15.029411, 1.0, 14.0, 15.0)
[Error] encoded value was less than 0: encode(-0.05882353, 1.0, 24.0, 25.0)
刚开始吓了一跳,网上搜了下,这是个 bughttps://bugs.openjdk.java.net/browse/JDK-8016451 ,最后编译成功会看到控制台提示
我们再看下这个jdk的版本,果然和系统环境变量的不是一个哈
[[email protected] openjdk8]# build/linux-x86_64-normal-server-fastdebug/jdk/bin/java -version
openjdk version "1.8.0-internal-fastdebug"
OpenJDK Runtime Environment (build 1.8.0-internal-fastdebug-_2017_09_04_11_45-b00)
OpenJDK 64-Bit Server VM (build 25.71-b00-fastdebug, mixed mode)
6 代码验证
我们写一段简单的 java 代码分别在两个 jdk 上编译 javac
并运行 java
以获取两个 jdk 的信息,代码如下
[[email protected] ~]# cat JvmTest.java
public class JvmTest {
public static void main(String[] args) {
System.out.println(System.getProperty("user.home"));
System.out.println(System.getProperty("java.version"));
System.out.println(System.getProperty("os.name"));
System.out.println(System.getProperty("java.vendor.url"));
}
}
- 使用已安装jdk
[[email protected] ~]# javac JvmTest.java
[[email protected] ~]# java JvmTest
/root
1.8.0_141
Linux
http://java.oracle.com/
- 使用自编译jdk
[[email protected] ~]# openjdk8/build/linux-x86_64-normal-server-fastdebug/jdk/bin/javac JvmTest.java
[[email protected] ~]# openjdk8/build/linux-x86_64-normal-server-fastdebug/jdk/bin/java JvmTest
/root
1.8.0-internal-fastdebug
Linux
http://java.oracle.com/
以上是关于如何在CentOS6.5下编译64位的Hadoop2.x的主要内容,如果未能解决你的问题,请参考以下文章