基于Hadoop平台的电信客服数据的处理与分析③项目开发:搭建基于Hadoop的全分布式集群---任务6:安装并配置Hadoop

任务描述

项目的运行环境为基于Hadoop的全分布式模式集群。

任务的主要内容为安装Hadoop分布式集群环境。

任务指导

Hadoop集群需要整个集群所有节点安装的Hadoop版本保持一致,并且拥有相同的配置

具体配置步骤如下:

  1. 解压缩Hadoop的压缩包

  2. 配置Hadoop的环境变量

  3. 修改Hadoop的配置文件,Hadoop的配置文件存放在Hadoop安装目录下的etc/hadoop/中

  4. 首先在一台节点对整个Hadoop集群进行配置,再将此节点的配置发送到集群的其它节点上。

  5. 具体需要修改的Hadoop的配置文件包括 core-site.xml、hdfs-site.xml、mapred-site.xml、yarn-site.xml、hadoop-env.sh、slaves

任务实现

  1. 安装Hadoop。在【master1】服务器解压并配置完成后,再复制到其它服务器。

在/opt/software目录下解压Hadoop的安装包;

输入【cd /opt/software】命令转到/opt/software目录下;

输入【tar -xzf hadoop-2.10.1.tar.gz -C /opt/app/】命令解压;

  1. 配置Hadoop环境变量,修改系统配置文件/etc/profile。

在集群中所有节点添加Hadoop的环境变量

输入【vi /etc/profile】命令,编辑/etc/profile文件。

在/etc/profile文件尾部追加如下内容:

复制代码
export HADOOP_HOME=/opt/app/hadoop-2.10.1
export PATH=$PATH:$HADOOP_HOME/bin:$HADOOP_HOME/sbin

使用【source /etc/profile】使配置文件生效。

  1. 进入hadoop的配置文件夹。

    [root@master1 ~]# cd $HADOOP_HOME/etc/hadoop

  2. 配置core-site.xml文件。该文件存放在$HADOOP_HOME/etc/hadoop目录下,配置内容如下:

    <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
    复制代码
     http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License. See accompanying LICENSE file.
    -->

    <configuration> <property> <name>fs.defaultFS</name> <value>hdfs://master1:9000</value> </property> <property> <name>io.file.buffer.size</name> <value>131072</value> </property> <property> <name>hadoop.tmp.dir</name> <value>file:/opt/app/hadoop_path/tmp</value> </property> <property> <name>fs.trash.interval</name> <value>1440</value> </property> <property> <name>fs.trash.checkpoint.interval</name> <value>0</value> </property> </configuration>
  3. 配置 hdfs-site.xml 文件,该文件存放在$HADOOP_HOME/etc/hadoop目录下,配置内容如下:

    <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
    复制代码
     http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License. See accompanying LICENSE file.
    -->

    <configuration> <property> <name>dfs.namenode.secondary.http-address</name> <value>slave2:9001</value> </property> <property> <name>dfs.namenode.name.dir</name> <value>file:/opt/app/hadoop_path/hdfs/name</value> </property> <property> <name>dfs.datanode.data.dir</name> <value>file:/opt/app/hadoop_path/hdfs/data</value> </property> <property> <name>dfs.replication</name> <value>2</value> </property> </configuration>
  4. 配置 mapred-site.xml 文件。

首先,输入【cp mapred-site.xml.template mapred-site.xml】命令将mapred-site.xml.template命名为mapred-site.xml。

配置$HADOOP_HOME/etc/hadoop目录下的mapred-site.xml:

复制代码
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
<name>mapreduce.framework.name</name>  
<value>yarn</value>  
</property>  
<property>  
<name>mapreduce.jobhistory.address</name>  
<value>master1:10020</value>  
</property>  
<property>  
<name>mapreduce.jobhistory.webapp.address</name>  
<value>master1:19888</value>  
</property> 
<property>
<name>dfs.permissions</name>
<value>false</value>
</property>
<!-- 开启uber模式(针对小作业的优化) -->
<property>
<name>mapreduce.job.ubertask.enable</name>
<value>true</value>
</property>
<!-- 配置启动uber模式的最大map数 -->
<property>
<name>mapreduce.job.ubertask.maxmaps</name>
<value>9</value>
</property>
<!-- 配置启动uber模式的最大reduce数 -->
<property>
<name>mapreduce.job.ubertask.maxreduces</name>
<value>1</value>
</property>
</configuration>
  1. 配置yarn-site.xml文件,该文件存放在$HADOOP_HOME/etc/hadoop目录下,配置内容如下:

    <?xml version="1.0"?>
    复制代码
     http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License. See accompanying LICENSE file.
    -->
    <configuration>
    <property>
    <name>yarn.nodemanager.aux-services</name>
    <value>mapreduce_shuffle</value>
    </property>
    <property>
    <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
    <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    <property>
    <name>yarn.resourcemanager.address</name>
    <value>master1:8032</value>
    </property>
    <property>
    <name>yarn.resourcemanager.scheduler.address</name>
    <value>master1:8030</value>
    </property>
    <property>
    <name>yarn.resourcemanager.resource-tracker.address</name>
    <value>master1:8031</value>
    </property>
    <property>
    <name>yarn.resourcemanager.admin.address</name>
    <value>master1:8033</value>
    </property>
    <property>
    <name>yarn.resourcemanager.webapp.address</name>
    <value>master1:8088</value>
    </property>
    </configuration>

  2. 配置hadoop-env.sh文件,文件存放在$HADOOP_HOME/etc/hadoop目录下,配置文件的JAVA_HOME变量。如果不设置,无法正常启动集群。

输入【vim hadoop-env.sh打开准备修改的配置文件hadoop-env.sh,修改JAVA_HOME环境变量。

找到默认的JAVA_HOME配置修改为如下配置:

复制代码
export JAVA_HOME=/opt/app/jdk1.8.0_181

在【hadoop-env.sh】文件末尾添加如下内容,使Hadoop在操作HBase能使用对应的类库:

复制代码
export HADOOP_CLASSPATH=$HADOOP_CLASSPATH:/opt/app/hbase-2.3.5/lib/*
  1. 配置slaves文件,该文件存在在$HADOOP_HOME/etc/hadoop目录下,删除默认的localhost,增加3个从节点的IP地址或host主机名。

    slave1
    slave2

  2. 为Hadoop创建目录

    [root@master1 ~]# mkdir -p /opt/app/hadoop_path/tmp
    [root@master1 ~]# mkdir -p /opt/app/hadoop_path/hdfs/name
    [root@master1 ~]# mkdir /opt/app/hadoop_path/hdfs/data

  3. 将配置好的Hadoop复制到其他节点对应位置上,通过scp命令发送。

    [root@master1 ~]# scp -rq /opt/app/hadoop-2.10.1 slave1:/opt/app
    [root@master1 ~]# scp -rq /opt/app/hadoop-2.10.1 slave2:/opt/app

    [root@master1 ~]# scp -rq /opt/app/hadoop_path slave1:/opt/app
    [root@master1 ~]# scp -rq /opt/app/hadoop_path slave2:/opt/app

转发后在所有节点执行【 source /etc/profile 】命令重新加载环境变量

相关推荐
IvanCodes1 小时前
六、Sqoop 导出
大数据·hadoop·sqoop
G探险者2 小时前
《深入理解 Nacos 集群与 Raft 协议》系列五:为什么集群未过半,系统就不可用?从 Raft 的投票机制说起
分布式·后端
G探险者2 小时前
《深入理解 Nacos 集群与 Raft 协议》系列一:为什么 Nacos 集群必须过半节点存活?从 Raft 协议说起
分布式·后端
G探险者2 小时前
《深入理解 Nacos 集群与 Raft 协议》系列四:日志复制机制:Raft 如何确保提交可靠且幂等
分布式·后端
G探险者2 小时前
《深入理解 Nacos 集群与 Raft 协议》系列三:日志对比机制:Raft 如何防止数据丢失与错误选主
分布式·后端
G探险者2 小时前
《深入理解 Nacos 集群与 Raft 协议》系列二:Raft 为什么要“选主”?选主的触发条件与机制详解
分布式·后端
代码匠心2 小时前
从零开始学Flink:揭开实时计算的神秘面纱
java·大数据·后端·flink
weixin_472339463 小时前
Doris查询Hive数据:实现高效跨数据源分析的实践指南
数据仓库·hive·hadoop
归去_来兮3 小时前
图神经网络(GNN)模型的基本原理
大数据·人工智能·深度学习·图神经网络·gnn