CentOS7下编译Hadoop

准备工作

下载 Hadoop 源码 Source (当前最新 2.9.2)

https://hadoop.apache.org/releases.html

打开压缩包会看到 BUILDING.txt 文件,这是官方提供的编译说明,参看 Linux 部分

Requirements:

* Unix System
* JDK 1.7 or 1.8
* Maven 3.0 or later
* Findbugs 1.3.9 (if running findbugs)
* ProtocolBuffer 2.5.0
* CMake 2.6 or newer (if compiling native code), must be 3.0 or newer on Mac
* Zlib devel (if compiling native code)
* openssl devel (if compiling native hadoop-pipes and to get the best HDFS encryption performance)
* Linux FUSE (Filesystem in Userspace) version 2.6 or above (if compiling fuse_dfs)
* Internet connection for first build (to fetch all Maven and Hadoop dependencies)
* python (for releasedocs)
* Node.js / bower / Ember-cli (for YARN UI v2 building)

搭建编译环境

JDK(1.8)

https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

# 解压
tar -zxf /opt/bak/jdk-8u192-linux-x64.tar.gz -C /opt/app/

# 配置JDK环境变量
vi /etc/profile

# JAVA_HOME
# export为把变量导出为全局变量
export JAVA_HOME=/opt/app/jdk1.8.0_192/
# .表示当前路径,:表示分隔符
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASSPATH
# $PATH表示取出当前系统中的值,类似于i = 3 + i
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH

# 刷新环境变量
source /etc/profile

# 验证JDK
java -version
# java version "1.8.0_192"
# Java(TM) SE Runtime Environment (build 1.8.0_192-b12)
# Java HotSpot(TM) 64-Bit Server VM (build 25.192-b12, mixed mode)

Maven(3.6.0)

http://maven.apache.org/download.cgi

# 解压
tar -zxf /opt/bak/apache-maven-3.6.0-bin.tar.gz -C /opt/app/

# 配置环境变量
vi /etc/profile

# MAVEN_HOME
export MAVEN_HOME=/opt/app/apache-maven-3.6.0/
export PATH=$PATH:$MAVEN_HOME/bin

# 刷新环境变量
source /etc/profile

# 验证Maven
mvn -v
# Apache Maven 3.6.0 (97c98ec64a1fdfee7767ce5ffb20918da4f719f3; 2018-10-25T02:41:47+08:00)
# Maven home: /opt/app/apache-maven-3.6.0
# Java version: 1.8.0_192, vendor: Oracle Corporation, runtime: /opt/app/jdk1.8.0_192/jre
# Default locale: zh_CN, platform encoding: UTF-8
# OS name: "linux", version: "3.10.0-862.el7.x86_64", arch: "amd64", family: "unix"

# 配置 Maven 仓库 (阿里)
vim /opt/app/apache-maven-3.6.0/conf/settings.xml
<!-- 本地仓库路径 -->
<localRepository>/opt/repo</localRepository>

<!-- 网络仓库地址 -->
<mirrors>
    <mirror>
        <id>alimaven</id>
        <mirrorOf>central</mirrorOf>
        <name>aliyun maven</name>
        <url>https://maven.aliyun.com/repository/central</url>
    </mirror>
</mirrors>

Ant(1.10.5)

https://ant.apache.org/bindownload.cgi

# 解压
tar -zxf /opt/bak/apache-ant-1.10.5-bin.tar.gz -C /opt/app/

# 配置环境变量
vi /etc/profile

# ANT_HOME
export ANT_HOME=/opt/app/apache-ant-1.10.5/
export PATH=$PATH:$ANT_HOME/bin

# 刷新环境变量
source /etc/profile

# 验证
ant -version
# Apache Ant(TM) version 1.10.5 compiled on July 10 2018

Protobuf(版本必须为2.5)

https://github.com/protocolbuffers/protobuf/releases/tag/v2.5.0

# protobuf 需要编译安装,先配置 yum 源,安装编译工具

# 清空原有 yum 源
rm -rf /etc/yum.repos.d/*
# 下载阿里 yum 源配置文件
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# 安装编译工具
yum install -y glibc-headers gcc-c++ make cmake

# 解压 protobuf
tar -zxf /opt/bak/protobuf-2.5.0.tar.gz -C /opt/app/

# 编译安装(需要一点时间)
cd /opt/app/protobuf-2.5.0/
# 检查当前的环境是否满足要安装软件的依赖关系,并设置安装目录
./configure --prefix=/opt/app/protobuf-2.5.0/
# 从 Makefile 中读取指令,编译
make
# 测试
make check
# 从 Makefile 中读取指令,安装到指定的位置
make install

# 让动态链接库为系统所共享
ldconfig

# 配置环境变量
vim /etc/profile

# 用于指定查找共享库(动态链接库)时除了默认路径之外的其他路径
# LD_LIBRARY_PATH
export LD_LIBRARY_PATH=/opt/app/protobuf-2.5.0/
export PATH=$PATH:$LD_LIBRARY_PATH

# 刷新环境变量
source /etc/profile

# 验证
protoc --version
# libprotoc 2.5.0

openssl devel

yum install -y openssl-devel ncurses-devel

Snappy(1.1.7,让 hadoop 支持压缩,非必须)

https://github.com/google/snappy/releases

Snappy 编译需要 CMake3 版本,先安装 CMake3(3.13.2)

https://cmake.org/download/

# 解压
tar -zxf /opt/bak/cmake-3.13.2.tar.gz -C /opt/app/

# 安装 gcc (若没有安装)
yum install -y gcc gcc-c++

# 编译安装 CMake3 (需要一点时间)
cd /opt/app/cmake-3.13.2/
# 检查依赖,设置安装路径
./bootstrap --prefix=/opt/app/cmake-3.13.2/
# 编译
gmake
# 安装
gmake install

# 移除旧的 cmake 版本
yum remove -y cmake

# 配置环境变量
vim /etc/profile

# CMake_HOME
export CMake_HOME=/opt/app/cmake-3.13.2/
export PATH=$PATH:$CMake_HOME/bin

# 刷新环境变量
source /etc/profile

# 验证
cmake --version
# cmake version 3.13.2
# CMake suite maintained and supported by Kitware (kitware.com/cmake).

安装 Snappy

# 解压
tar -zxf /opt/bak/snappy-1.1.7.tar.gz -C /opt/app/

# 编译安装
cd /opt/app/snappy-1.1.7/
# 创建构建文件夹
mkdir build
# 编译
cd build && cmake ../ && make
# 安装
make install

Install the project...
-- Install configuration: ""
-- Installing: /usr/local/lib64/libsnappy.a
-- Installing: /usr/local/include/snappy-c.h
-- Installing: /usr/local/include/snappy-sinksource.h
-- Installing: /usr/local/include/snappy.h
-- Installing: /usr/local/include/snappy-stubs-public.h
-- Installing: /usr/local/lib64/cmake/Snappy/SnappyTargets.cmake
-- Installing: /usr/local/lib64/cmake/Snappy/SnappyTargets-noconfig.cmake
-- Installing: /usr/local/lib64/cmake/Snappy/SnappyConfig.cmake
-- Installing: /usr/local/lib64/cmake/Snappy/SnappyConfigVersion.cmake

# 验证
ls -lh /usr/local/lib64 | grep snappy
# -rw-r--r--. 1 root root 184K 3月  13 22:23 libsnappy.a

开始编译

官方编译参数说明

Maven build goals:

 * Clean                     : mvn clean [-Preleasedocs]
 * Compile                   : mvn compile [-Pnative]
 * Run tests                 : mvn test [-Pnative]
 * Create JAR                : mvn package
 * Run findbugs              : mvn compile findbugs:findbugs
 * Run checkstyle            : mvn compile checkstyle:checkstyle
 * Install JAR in M2 cache   : mvn install
 * Deploy JAR to Maven repo  : mvn deploy
 * Run clover                : mvn test -Pclover [-DcloverLicenseLocation=${user.name}/.clover.license]
 * Run Rat                   : mvn apache-rat:check
 * Build javadocs            : mvn javadoc:javadoc
 * Build distribution        : mvn package [-Pdist][-Pdocs][-Psrc][-Pnative][-Dtar][-Preleasedocs][-Pyarn-ui]
 * Change Hadoop version     : mvn versions:set -DnewVersion=NEWVERSION

 Build options:

  * Use -Pnative to compile/bundle native code
  * Use -Pdocs to generate & bundle the documentation in the distribution (using -Pdist)
  * Use -Psrc to create a project source TAR.GZ
  * Use -Dtar to create a TAR with the distribution (using -Pdist)
  * Use -Preleasedocs to include the changelog and release docs (requires Internet connectivity)
  * Use -Pyarn-ui to build YARN UI v2. (Requires Internet connectivity)

 Snappy build options:

   Snappy is a compression library that can be utilized by the native code.
   It is currently an optional component, meaning that Hadoop can be built with
   or without this dependency.

  * Use -Drequire.snappy to fail the build if libsnappy.so is not found.
    If this option is not specified and the snappy library is missing,
    we silently build a version of libhadoop.so that cannot make use of snappy.
    This option is recommended if you plan on making use of snappy and want
    to get more repeatable builds.

  * Use -Dsnappy.prefix to specify a nonstandard location for the libsnappy
    header files and library files. You do not need this option if you have
    installed snappy using a package manager.
  * Use -Dsnappy.lib to specify a nonstandard location for the libsnappy library
    files.  Similarly to snappy.prefix, you do not need this option if you have
    installed snappy using a package manager.
  * Use -Dbundle.snappy to copy the contents of the snappy.lib directory into
    the final tar file. This option requires that -Dsnappy.lib is also given,
    and it ignores the -Dsnappy.prefix option. If -Dsnappy.lib isn‘t given, the
    bundling and building will fail.

 OpenSSL build options:

   OpenSSL includes a crypto library that can be utilized by the native code.
   It is currently an optional component, meaning that Hadoop can be built with
   or without this dependency.

  * Use -Drequire.openssl to fail the build if libcrypto.so is not found.
    If this option is not specified and the openssl library is missing,
    we silently build a version of libhadoop.so that cannot make use of
    openssl. This option is recommended if you plan on making use of openssl
    and want to get more repeatable builds.
  * Use -Dopenssl.prefix to specify a nonstandard location for the libcrypto
    header files and library files. You do not need this option if you have
    installed openssl using a package manager.
  * Use -Dopenssl.lib to specify a nonstandard location for the libcrypto library
    files. Similarly to openssl.prefix, you do not need this option if you have
    installed openssl using a package manager.
  * Use -Dbundle.openssl to copy the contents of the openssl.lib directory into
    the final tar file. This option requires that -Dopenssl.lib is also given,
    and it ignores the -Dopenssl.prefix option. If -Dopenssl.lib isn‘t given, the
    bundling and building will fail.

   Tests options:

  * Use -DskipTests to skip tests when running the following Maven goals:
    ‘package‘,  ‘install‘, ‘deploy‘ or ‘verify‘
  * -Dtest=<TESTCLASSNAME>,<TESTCLASSNAME#METHODNAME>,....
  * -Dtest.exclude=<TESTCLASSNAME>
  * -Dtest.exclude.pattern=**/<TESTCLASSNAME1>.java,**/<TESTCLASSNAME2>.java
  * To run all native unit tests, use: mvn test -Pnative -Dtest=allNative
  * To run a specific native unit test, use: mvn test -Pnative -Dtest=<test>
  For example, to run test_bulk_crc32, you would use:
  mvn test -Pnative -Dtest=test_bulk_crc32

编译

# 解压 hadoop 源码
tar -zxf /opt/bak/hadoop-2.9.2-src.tar.gz -C /opt/app/

# 编译
cd /opt/app/hadoop-2.9.2-src/

mvn clean package -Pdist,native -DskipTests –Dtar

# 带 snappy 版本编译
mvn clean package -Pdist,native -DskipTests -Dtar -Dbundle.snappy -Dsnappy.lib=/usr/local/lib64

# -Pdist,native          :把重新编译生成的hadoop动态库
# -DskipTests           :跳过测试
# -Dtar               :最后把文件以tar打包
# -Dbundle.snappy         :添加snappy压缩支持(默认官网下载的是不支持的)
# -Dsnappy.lib=/usr/local/lib  :指snappy在编译机器上安装后的库路径

snappy 压缩支持,可以在安装 Hadoop 后用命令检查,在 lib/native 路径下也有相关文件

hadoop checknative

编译过程中请保持网络畅通,编译可能会因为包依赖下载出错而失败,可多试几次。

编译成功后生成的文件在 hadoop-dist/target 路径下


https://www.58jb.com/html/113.html

原文地址:https://www.cnblogs.com/jhxxb/p/10527491.html

时间: 2024-10-13 10:32:47

CentOS7下编译Hadoop的相关文章

[转]CentOS7下编译openjdk

CentOS7下编译openjdk 编译环境: 操作系统: CentOS7 64位 BootStrap JDK: 1.7.0_76 1. 下载openjdk源码 下载openjdk1.7源码 openjdk-7u40-fcs-src-b43-26_aug_2013.zip 2. 安装编译环境 安装alsa包 yum install alsa-lib-devel 安装cups-devel yum install cups-devel 安装X相关的库 yum install libX* 安装g++

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

64位centos 下编译 hadoop 2.6.0 源码

64位os下为啥要编译hadoop就不解释了,百度一下就能知道原因,下面是步骤: 前提:编译源码所在的机器,必须能上网,否则建议不要尝试了 一. 下载必要的组件 a) 下载hadoop源码 (当前最新的稳定版是2.6.0)地址  http://mirrors.hust.edu.cn/apache/hadoop/common/stable/hadoop-2.6.0-src.tar.gz b) 下载apache-ant (centos自带的ant版本太低,编译过程中会报错)地址: http://mi

ubuntu下编译Hadoop

Ubuntu 下编译 Hadoop-2.9.2 系统环境 系统: ubuntu-18.10-desktop-amd64 maven: Apache Maven 3.6.0 jdk: jdk_1.8.0_201 ProtocolBuffer: portoc-2.5.0 OpenSSL: OpenSSL 1.1.1 cmake: cmake3.12.1 hadoop: hadoop-2.9.2 安装所需环境 # 安装各种所需依赖库 $ sudo apt-get install autoconf au

centos7下编译安装nginx并实现日志轮替

centos7编译安装nginx: 首先确保系统上存在编译安装使用的必要工具运行:  # yum groupinstall "development tools" "server platform development" 1 下载PCRE version 4.4 - 8.40 (ngx_http_rewrite_module模块需要)    # wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/p

centos7下编译安装lnmp和nginx代理实验

1.先安装mysql cd /usr/local/src wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz tar zxvf mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz mv mysql-5.6.35-linux-glibc2.5-x86_64 /usr/local/mysql cd /usr/local/mysql useradd

ubuntu 环境下编译 hadoop 2.6.0的简单方法

由于服务器一般都64位系统, hadoop网站的release版本32位native库不能运行,所以需要自己在编译一下.以下是我采用的一个编译的过程,比较简单,不用下载各种版本及环境配置,通过命令就能自动完成了.系统环境为ubuntu server 64位版. 1.安装JDK,我这里使用的是OenJDK sudo apt-get install default-jdk java -version 显示版本信息: java version "1.7.0_65" OpenJDK Runti

CentOS7下编译安装Python3.7.x【亲测有效】

所有操作都在root用户下操作 下载安装包 编译安装 建立软链接 验证 安装: 更新yum: yum update 安装Python依赖: yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel zlib-devel ncurses-devel tk-devel libffi-devel gcc make 下载python安装包: 这是安装的是Python3.7.4 由于可能

Centos 6.5 X64 环境下编译 hadoop 2.6.0 --已验证

Centos 6.5 x64 hadoop 2.6.0 jdk 1.7 protobuf-2.5.0 maven-3.0.5 set environment export JAVA_HOME=/home/linux/jdk export CLASSPATH=JAVA_HOME/lib/tools.jar export PROTOC_HOME=/home/linux/protobuf export MAVEN_HOME=/home/linux/maven export PATH=$PROTOC_H