CentOS 7下配置hadoop 2.8 分布式集群

简介:
Hadoop是一个由Apache基金会所开发的分布式系统基础架构,实现分布式文件系统HDFS,用于存储大数据集,以及可以以流的形式访问(streaming access)文件系统中的数据。Hadoop的框架最核心的设计就是:HDFS和MapReduce。HDFS为海量的数据提供了存储,则MapReduce为海量的数据提供了计算。本文描述了在CentOS 7下,基于三个节点安装hadoop 2.8,供大家参考。

一、基础环境描述


OS版本
[root@namenode ~]# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

JAVA环境
[root@namenode ~]# java -version
openjdk version "1.8.0_65"
OpenJDK Runtime Environment (build 1.8.0_65-b17)
OpenJDK 64-Bit Server VM (build 25.65-b01, mixed mode)

三个节点主机名及IP
192.168.81.142 namenode.example.com namenode
192.168.81.146 datanode1.example.com datanode1
192.168.81.147 datanode2.example.com datanode2

hadoop版本
[hadoop@namenode ~]$ hadoop version
Hadoop 2.8.1

二、主要步骤

配置Java运行环境
配置hosts文件
配置hadoop运行账户及数据存放目录
配置ssh等效连接
配置用户环境变量
下载解压hadoop安装包
配置hadoop相关配置文件
格式化namenode
启动hadoop
验证hadoop

三、配置及安装hadoop 2.8


1、配置java运行环境(所有节点)


[root@namenode ~]# vim /etc/profile.d/java.sh
export JAVA_HOME=/etc/alternatives/java_sdk_1.8.0_openjdk
export PATH=$PATH:$JAVA_HOME

[root@namenode ~]# source /etc/profile.d/java.sh
[root@namenode ~]# env |grep JAVA_HOME
JAVA_HOME=/etc/alternatives/java_sdk_1.8.0_openjdk

2、配置Hosts文件,添加用户及创建目录(所有节点)


[root@namenode ~]# vim /etc/hosts

192.168.81.142 namenode.example.com namenode
192.168.81.146 datanode1.example.com datanode1
192.168.81.147 datanode2.example.com datanode2

[root@namenode ~]# useradd hadoop
[root@namenode ~]# passwd hadoop
[root@namenode ~]# mkdir -pv /usr/local/hadoop/datanode
[root@namenode ~]# chmod 755 /usr/local/hadoop/datanode
[root@namenode ~]# chown hadoop:hadoop /usr/local/hadoop

3、配置等效性(所有节点)


[root@namenode ~]# su - hadoop
[hadoop@namenode ~]$
[hadoop@namenode ~]$ ssh-keygen
[hadoop@namenode ~]$ ssh-copy-id localhost
[hadoop@namenode ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@192.168.81.146
[hadoop@namenode ~]$ ssh-copy-id -i ~/.ssh/id_rsa.pub hadoop@192.168.81.147

[hadoop@namenode ~]$ ssh namenode.example.com date;\
> ssh datanode1.example.com date;
> ssh datanode2.example.com date
Wed Nov 15 16:06:16 CST 2017
Wed Nov 15 16:06:16 CST 2017
Wed Nov 15 16:06:16 CST 2017

4、配置hadoop运行环境(所有节点)

[hadoop@namenode ~]$ vi ~/.bash_profile
export HADOOP_HOME=/usr/local/hadoop
export HADOOP_COMMON_HOME=$HADOOP_HOME
export HADOOP_HDFS_HOME=$HADOOP_HOME
export HADOOP_MAPRED_HOME=$HADOOP_HOME
export HADOOP_YARN_HOME=$HADOOP_HOME
export HADOOP_OPTS="-Djava.library.path=$HADOOP_HOME/lib/native"
export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
export PATH=$PATH:$HADOOP_HOME/sbin:$HADOOP_HOME/bin

[hadoop@namenode ~]$ source ~/.bash_profile

5、安装hadoop(所有节点)


[hadoop@namenode ~]$ wget http://mirror.bit.edu.cn/apache/hadoop/common/hadoop-2.8.1/hadoop-2.8.1.tar.gz -P /tmp
[hadoop@namenode ~]$ tar -xf /tmp/hadoop-2.8.1.tar.gz -C /usr/local/hadoop --strip-components 1

6、配置hadoop相关配置文件


[hadoop@namenode ~]$ vim /usr/local/hadoop/etc/hadoop/hdfs-site.xml
<configuration>
    <property>
        <name>dfs.replication</name>
        <value>2</value>
    </property>
    <property>
        <name>dfs.datanode.data.dir</name>
        <value>file:///usr/local/hadoop/datanode</value>
    </property>
</configuration>

[hadoop@namenode ~]$ scp /usr/local/hadoop/etc/hadoop/hdfs-site.xml \
> datanode1:/usr/local/hadoop/etc/hadoop

[hadoop@namenode ~]$ scp /usr/local/hadoop/etc/hadoop/hdfs-site.xml \
> datanode2:/usr/local/hadoop/etc/hadoop

[hadoop@namenode ~]$ vim /usr/local/hadoop/etc/hadoop/core-site.xml

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://namenode.example.com:9000/</value>
    </property>
</configuration>

[hadoop@namenode ~]$ scp /usr/local/hadoop/etc/hadoop/core-site.xml \
> datanode1:/usr/local/hadoop/etc/hadoop

[hadoop@namenode ~]$ scp /usr/local/hadoop/etc/hadoop/core-site.xml \
> datanode2:/usr/local/hadoop/etc/hadoop

再次编辑hdfs-site.xml,仅仅针对namenode节点
[hadoop@namenode ~]$ mkdir -pv /usr/local/hadoop/namenode
[hadoop@namenode ~]$ vim /usr/local/hadoop/etc/hadoop/hdfs-site.xml
将以下内容添加到<configuration> - </configuration>
<property>
    <name>dfs.namenode.name.dir</name>
    <value>file:///usr/local/hadoop/namenode</value>
</property>

[hadoop@namenode ~]$ vi /usr/local/hadoop/etc/hadoop/mapred-site.xml
<configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
</configuration>

[hadoop@namenode ~]$ vi /usr/local/hadoop/etc/hadoop/yarn-site.xml
<configuration>
    <property>
        <name>yarn.resourcemanager.hostname</name>
        <value>namenode.example.com</value>
    </property>
    <property>
        <name>yarn.nodemanager.hostname</name>
        <value>namenode.example.com</value>
    </property>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce_shuffle</value>
    </property>
</configuration>

[hadoop@namenode ~]$ vi /usr/local/hadoop/etc/hadoop/slaves
# add all nodes (remove localhost)
namenode.example.com
datanode1.example.com
datanode2.example.com

7、格式化


[hadoop@namenode ~]$ hdfs namenode -format
17/11/16 16:32:20 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG: user = hadoop
STARTUP_MSG: host = namenode.example.com/192.168.81.142
STARTUP_MSG: args = [-format]
STARTUP_MSG: version = 2.8.1
........

17/11/16 16:32:21 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at namenode.example.com/192.168.81.142
************************************************************/

8、启动hadoop


[hadoop@namenode ~]$ start-dfs.sh
Starting namenodes on [namenode.example.com]
namenode.example.com: starting namenode, logging to /usr/...-namenode-namenode.example.com.out
datanode2.example.com: starting datanode, logging to /usr/...-datanode-datanode2.example.com.out
namenode.example.com: starting datanode, logging to /usr/...-datanode-namenode.example.com.out
datanode1.example.com: starting datanode, logging to /usr/...-datanode-datanode1.example.com.out
Starting secondary namenodes [blogs.jrealm.net]
blogs.jrealm.net: starting secondarynamenode, logging to /usr/...-secondarynamenode-namenode.example.com.out

[hadoop@namenode ~]$ start-yarn.sh
starting yarn daemons
starting resourcemanager, logging to /usr/...-resourcemanager-namenode.example.com.out
datanode2.example.com: starting nodemanager, logging to /usr/...-datanode2.example.com.out
datanode1.example.com: starting nodemanager, logging to /usr/...-datanode1.example.com.out
namenode.example.com: starting nodemanager, logging to /usr/...-namenode.example.com.out

[root@namenode ~]# jps
12995 Jps
10985 ResourceManager
11179 NodeManager  ## Author : Leshami
10061 NameNode     ## QQ/Weixin : 645746311 
10301 DataNode
10655 SecondaryNameNode

9、测试hadoop


[hadoop@namenode ~]$ hdfs dfs -mkdir /test       ##创建测试目录
上传文件到hadoop集群
[hadoop@namenode ~]$ hdfs dfs -copyFromLocal /usr/local/hadoop/NOTICE.txt /test  
查看已上传的文件
[hadoop@namenode ~]$ hdfs dfs -cat /test/NOTICE.txt
This product includes software developed by The Apache Software
Foundation (http://www.apache.org/).

The binary distribution of this product bundles binaries of
org.iq80.leveldb:leveldb-api (https://github.com/dain/leveldb), which has the
following notices:
* Copyright 2011 Dain Sundstrom <dain@iq80.com>
* Copyright 2011 FuseSource Corp. http://fusesource.com

使用自带的jar包map-reduce 测试字数统计
[hadoop@namenode ~]$ hadoop jar \
> /usr/local/hadoop/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.8.1.jar wordcount /test/NOTICE.txt /output01
17/11/17 14:14:39 INFO client.RMProxy: Connecting to ResourceManager at namenode.example.com/192.168.81.142:8032
17/11/17 14:14:49 INFO input.FileInputFormat: Total input files to process : 1
17/11/17 14:14:49 INFO mapreduce.JobSubmitter: number of splits:1
17/11/17 14:14:50 INFO mapreduce.JobSubmitter: Submitting tokens for job: job_1510837568617_0001
17/11/17 14:14:56 INFO impl.YarnClientImpl: Submitted application application_1510837568617_0001
17/11/17 14:14:56 INFO mapreduce.Job: The url to track the job: http://namenode.example.com:8088
           /proxy/application_1510837568617_0001/
17/11/17 14:14:56 INFO mapreduce.Job: Running job: job_1510837568617_0001
17/11/17 14:16:05 INFO mapreduce.Job: Job job_1510837568617_0001 running in uber mode : false
17/11/17 14:16:05 INFO mapreduce.Job: map 0% reduce 0%
17/11/17 14:16:56 INFO mapreduce.Job: map 100% reduce 0%
17/11/17 14:17:10 INFO mapreduce.Job: map 100% reduce 100%
17/11/17 14:17:14 INFO mapreduce.Job: Job job_1510837568617_0001 completed successfully
17/11/17 14:17:16 INFO mapreduce.Job: Counters: 49
File System Counters
FILE: Number of bytes read=12094

查看输出日志文件及结果
[hadoop@namenode ~]$ hdfs dfs -ls /output01
Found 2 items
-rw-r--r-- 2 hadoop supergroup 0 2017-11-17 14:17 /output01/_SUCCESS
-rw-r--r-- 2 hadoop supergroup 9485 2017-11-17 14:17 /output01/part-r-00000

[hadoop@namenode ~]$ hdfs dfs -cat /output01/part-r-00000
"AS 1
"GCC 1
"License"); 1
& 1
'Aalto 1
'Apache 4
'ArrayDeque', 1

10、Web界面控制台

查看集群摘要信息
984d3d1a92fe8f4ead80975b4ac754654027d77b

查看集群信息  
94afbf82ddeec39bddc2a63c7c31678df7c48d05
 

目录
相关文章
|
28天前
|
存储 分布式计算 负载均衡
分布式计算模型和集群计算模型的区别
【10月更文挑战第18天】分布式计算模型和集群计算模型各有特点和优势,在实际应用中需要根据具体的需求和条件选择合适的计算架构模式,以达到最佳的计算效果和性能。
54 2
|
25天前
|
存储 监控 大数据
构建高可用性ClickHouse集群:从单节点到分布式
【10月更文挑战第26天】随着业务的不断增长,单一的数据存储解决方案可能无法满足日益增加的数据处理需求。在大数据时代,数据库的性能、可扩展性和稳定性成为企业关注的重点。ClickHouse 是一个用于联机分析处理(OLAP)的列式数据库管理系统(DBMS),以其卓越的查询性能和高吞吐量而闻名。本文将从我的个人角度出发,分享如何将单节点 ClickHouse 扩展为高可用性的分布式集群,以提升系统的稳定性和可靠性。
55 0
|
1月前
|
分布式计算 Hadoop
Hadoop-27 ZooKeeper集群 集群配置启动 3台云服务器 myid集群 zoo.cfg多节点配置 分布式协调框架 Leader Follower Observer
Hadoop-27 ZooKeeper集群 集群配置启动 3台云服务器 myid集群 zoo.cfg多节点配置 分布式协调框架 Leader Follower Observer
48 1
|
1月前
|
Kubernetes Ubuntu Linux
Centos7 搭建 kubernetes集群
本文介绍了如何搭建一个三节点的Kubernetes集群,包括一个主节点和两个工作节点。各节点运行CentOS 7系统,最低配置为2核CPU、2GB内存和15GB硬盘。详细步骤包括环境配置、安装Docker、关闭防火墙和SELinux、禁用交换分区、安装kubeadm、kubelet、kubectl,以及初始化Kubernetes集群和安装网络插件Calico或Flannel。
155 0
|
1月前
|
存储 SQL 消息中间件
Hadoop-26 ZooKeeper集群 3台云服务器 基础概念简介与环境的配置使用 架构组成 分布式协调框架 Leader Follower Observer
Hadoop-26 ZooKeeper集群 3台云服务器 基础概念简介与环境的配置使用 架构组成 分布式协调框架 Leader Follower Observer
49 0
|
3月前
|
分布式计算 资源调度 Hadoop
centos7二进制安装Hadoop3
centos7二进制安装Hadoop3
|
11月前
|
分布式计算 Hadoop Java
Centos7下安装hadoop单节点
Centos7下安装hadoop单节点
97 0
|
分布式计算 Hadoop Linux
Centos7安装hadoop
Centos7安装hadoop
147 0
|
分布式计算 Hadoop Java
centos7 安装hadoop 2.7.6
centos7 安装hadoop 2.7.6
164 0
centos7 安装hadoop 2.7.6
|
SQL MySQL Java
CentOS7下安装CDH,clouderamanager,hadoop
一、实验背景 我们是四台电脑一起搭建Hadoop集群 A,B,C,D四个人个有一台电脑,分别在各自的电脑上安装虚拟机,虚拟机装centOS7。(我们建议主机namenode内存大一点8g,硬盘最好100g以上,其余节点2g,50g即可,下文会阐述原因) 系统:VMware下的centOS7 jdk:1.
2177 0

热门文章

最新文章

下一篇
无影云桌面