1. 虚拟机准备
(1) 硬件要求
硬件 | 大小 |
---|---|
CPU | 没啥要求 |
内存 | > 4G |
磁盘 | > 40G |
(2) 软件要求
我用的是CentOS7,要求是64位操作系统
软件 | 大小 |
---|---|
系统 | 64位 |
2. 编译环境的准备
2.1 准备linux 环境
2.2 虚拟机网络配置
(1) 配置联网模式
要求虚拟机可以连接外网
(2) 配置ip地址
# 修改ip地址
vim /etc/sysconfig/network-scripts/ifcfg-ens33
# 修改主机名
hostnamectl set-hostname hadoop180
# 重启网络服务
(3) 关闭防火墙
systemctl stop firewalld && systemctl disable firewalld
(4) 关闭selinux
vim /etc/selinux/config
2.3 安装包准备
2.4 安装jdk
基本过程省略 …
2.5 安装maven
(1) 解压安装包(我这里直接解压到root/路径了)
# 解压
[root@hadoop180 ~]# tar -zxvf apache-maven-3.0.5-bin.tar.gz
# 改个简单的名字
root@hadoop180 ~]# mv apache-maven-3.0.5 apache-maven
(2) 配置环境变量
[root@hadoop180 ~]# vim /etc/profile
追加如下内容
export MAVEN_HOME=/root/apache-maven
export PATH=$PATH:$MAVEN_HOME/bin
export MAVEN_OPTS="-Xms4096m -Xmx4096m"
(3) 使配置文件生效
[root@hadoop180 ~]# source /etc/profile
(4) 测试
[root@hadoop180 ~]# mvn -version
(5) 配置maven仓库的镜像源
[root@hadoop180 ~]# vim apache-maven/conf/settings.xml
增加如下内容
<mirrors>
<!-- mirror
| Specifies a repository mirror site to use instead of a given repository. The repository that
| this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
| for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
|
<mirror>
<id>mirrorId</id>
<mirrorOf>repositoryId</mirrorOf>
<name>Human Readable Name for this Mirror.</name>
<url>http://my.repository.com/repo/path</url>
</mirror>
-->
<mirror>
<id>nexus-aliyun</id>
<mirrorOf>central</mirrorOf>
<name>Nexus aliyun</name>
<url>http://maven.aliyun.com/nexus/content/groups/public</url>
</mirror>
</mirrors>
2.7 安装ant
(1) 解压ant安装包
# 解压
[root@hadoop180 ~]# tar -zxvf apache-ant-1.9.9-bin.tar.gz
(2) 配置环境变量
[root@hadoop180 ~]# vim /etc/profile
追加如下内容
export ANT_HOME=/root/apache-ant-1.9.9
export PATH=$PATH:$ANT_HOME/bin
(3) 使配置文件生效
[root@hadoop180 ~]# source /etc/profile
(4) 测试
[root@hadoop180 ~]# ant -version
Apache Ant(TM) version 1.9.9 compiled on February 2 2017
[root@hadoop180 ~]#
[root@hadoop180 ~]#
2.7 安装FindBugs
(1) 解压findbugs
[root@hadoop180 ~]# tar -zxvf findbugs-1.3.9.tar.gz
(2) 配置环境变量
[root@hadoop180 ~]# vim /etc/profile
增加如下内容
export FINDBUGS_HOME=/root/findbugs-1.3.9
export PATH=$PATH:$FINDBUGS_HOME/bin
(3) 使配置文件生效
[root@hadoop180 ~]# source /etc/profile
(4) 验证
[root@hadoop180 ~]# findbugs -version
1.3.9
[root@hadoop180 ~]#
[root@hadoop180 ~]#
[root@hadoop180 ~]#
2.8 在线安装一些依赖
[root@hadoop180 ~]# yum -y install autoconf automake libtool cmake make
[root@hadoop180 ~]# yum -y install ncurses-devel openssl-devel
[root@hadoop180 ~]# yum -y install lzo-devel zlib-devel gcc gcc-c++ glibc-headers
[root@hadoop180 ~]# yum -y install bzip2-devel
2.9 安装protobuf
(1) 解压安装包
[root@hadoop180 ~]# tar -zxvf protobuf-2.5.0.tar.gz
(2) 检查平台特性
# 进入到解压目录
[root@hadoop180 ~]# cd protobuf-2.5.0
# 检查平台特性,并进行相关配置
[root@hadoop180 protobuf-2.5.0]# ./configure
(3) 编译
[root@hadoop180 protobuf-2.5.0]# make
(4) 安装前检查
[root@hadoop180 protobuf-2.5.0]# make check
(5) 安装
[root@hadoop180 protobuf-2.5.0]# make install
(6) 刷新动态链接库
# 每次使用make 等命令安装组件后, 建议都ldconfig一下, 刷新下动态链接库 避免出现一些奇怪的问题
[root@hadoop180 protobuf-2.5.0]# ldconfig
(7) 验证
[root@hadoop180 ~]# protoc --version
libprotoc 2.5.0
[root@hadoop180 ~]#
[root@hadoop180 ~]#
2.10 安装snappy
(1) 解压安装包
[root@hadoop180 ~]# tar -zxvf snappy-1.1.3.tar.gz
(2) 检查平台特性
[root@hadoop180 ~]# cd snappy-1.1.3
[root@hadoop180 snappy-1.1.3]# ./configure
(3) 编译
[root@hadoop180 snappy-1.1.3]# ./make
(4) 安装前检查
[root@hadoop180 snappy-1.1.3]# make check
(5) 安装
[root@hadoop180 snappy-1.1.3]# make install
(6) 刷新动态链接库
[root@hadoop180 snappy-1.1.3]# ldconfig
3. 编译Hadoop 源码
(1) 源代码解压
# 解压
[root@hadoop180 ~]# tar -zxvf hadoop-2.7.2-src.tar.gz
# 进去解压目录
[root@hadoop180 ~]# cd hadoop-2.7.2-src
(2) 编译
# -Drequire.snappy 这个是设置支持snappy压缩算法的
mvn package -Pdist,native -DskipTests -Dtar -Drequire.snappy -e -X
(3) 等待编译成功 (这个过程很慢 ~~~ 网比较慢 搞了三小时)
(4) 查看编译的包
# 进入target 目录
[root@hadoop180 ~]# cd /root/hadoop-2.7.2-src/hadoop-dist/target
[root@hadoop180 target]#
# 查看所有的包
[root@hadoop180 target]# ll
total 580460
drwxr-xr-x 2 root root 28 Sep 10 19:31 antrun
-rw-r--r-- 1 root root 1862 Sep 10 19:31 dist-layout-stitching.sh
-rw-r--r-- 1 root root 635 Sep 10 19:31 dist-tar-stitching.sh
drwxr-xr-x 9 root root 149 Sep 10 19:31 hadoop-2.7.2
-rw-r--r-- 1 root root 197807438 Sep 10 19:31 hadoop-2.7.2.tar.gz
-rw-r--r-- 1 root root 2826 Sep 10 19:31 hadoop-dist-2.7.2.jar
-rw-r--r-- 1 root root 396567715 Sep 10 19:32 hadoop-dist-2.7.2-javadoc.jar
drwxr-xr-x 2 root root 51 Sep 10 19:32 javadoc-bundle-options
drwxr-xr-x 2 root root 28 Sep 10 19:31 maven-archiver
drwxr-xr-x 2 root root 6 Sep 10 19:31 test-dir
(5) 终于编译完成, 洗个脸冷静下 ~~~