Hadoop安装和伪分布环境配置,部分分布式配置文件,以及idea连接分布式hadoop。

2023-05-16

  https://hadoop.apache.org/# 这个是Hadoop官网。我们要从这里进入去查看Hadoop官方文档.

文档这里要点击Getting started才能查看,导航Documentation跳转不过去。

在开始下载hadoop之前要先下载jdk8,因为hadoop2.7开始都支持jdk8版本。

 JDK8:https://www.oracle.com/java/technologies/downloads/#java8

如果系统是32位的,选择后缀中带有 i586的文件,系统是64位的,选择后缀中带有 x64的文件

要先注册账号登录才能下载。

在Download 里面解压下载的jdk :tar -zxvf jdk-8u361-linux-x64.tar.gz

将解压好的jdk移动到/usr/lib/jvm文件夹 sudo mv jdk1.8.0_361 /usr/lib/jvm


vim ~/.bashrc  
在文件前面放这四条代码

export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_361 
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

source ~/.bashrc  保存配置
java -version  查看java配置
Ubuntu默认已安装了SSH客户端,因此,这里还需要安装SSH服务端
sudo apt-get install ssh
sudo apt-get install pdsh
设置免密登录:  

cd ~/.ssh/ 
ssh-keygen -t rsa 
cat ./id_rsa.pub >> ./authorized_keys  

https://dlcdn.apache.org/hadoop/common/ hadoop不同版本官网下载

sudo tar -zxf ~/Downloads/hadoop-3.3.5.tar.gz -C /usr/local

sudo mv ./hadoop-3.3.5/ ./hadoop

sudo chown -R 用户名:所在组 ./hadoop  应该是这个,一般都是两个一样的当前用户名

./bin/hadoop version   #查看当前安装的Hadoop版本。

接下来步骤属于伪分布安装:

     vim hadoop-env.sh

     export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_361

     接下来操作参考hadoop伪分布文档:https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/SingleCluster.html#Pseudo-Distributed_Operation


etc/core-site.xml:

  
<?xml version="1.0" encoding="UTF-8"?>
<?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>hadoop.tmp.dir</name>
        <value>file:/usr/local/hadoop/tmp</value>
        <description>Abase for other temporary directories.</description>
    </property>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://localhost:9000</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>localhost:8032</value>
    </property>

    <property>
        <name>mapreduce.framework.name</name>
        <value>local</value>
    </property>
</configuration>

hadoop.tmp.dir用于保存临时文件,若没有配置hadoop.tmp.dir这个参数,则默认使用的临时目录为/tmp/hadoo-hadoop,而这个目录在Hadoop重启时有可能被系统清理掉,导致一些意想不到的问题,因此,必须配置这个参数。fs.defaultFS这个参数,用于指定HDFS的访问地址,其中,9000是端口号。

etc/hdfs-site.xml:

  
<?xml version="1.0" encoding="UTF-8"?>
<?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>dfs.replication</name>
        <value>1</value>
    </property>
    <property>
        <name>dfs.namenode.name.dir</name>
        <value>file:/usr/local/hadoop/tmp/dfs/name</value>
    </property>
    <property>
        <name>dfs.datanode.data.dir</name>
        <value>file:/usr/local/hadoop/tmp/dfs/data</value>
    </property>
</configuration>

  

  在hdfs-site.xml文件中,dfs.replication这个参数用于指定副本的数量,因为,在分布式文件系统HDFS中,数据会被冗余存储多份,以保证可靠性和可用性。但是,由于这里采用伪分布式模式,只有一个节点,因此,只可能有1个副本,因此,设置dfs.replication的值为1。dfs.namenode.name.dir用于设定名称节点的元数据的保存目录,dfs.datanode.data.dir用于设定数据节点的数据保存目录,这两个参数必须设定,否则后面会出错。 需要指出的是,Hadoop的运行方式(比如运行在单机模式下还是运行在伪分布式模式下),是由配置文件决定的,启动Hadoop时会读取配置文件,然后根据配置文件来决定f运行在什么模式下。因此,如果需要从伪分布式模式切换回单机模式,只需要删除core-site.xml中的配置项即可。

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>yarn.log-aggregation-enable</name>
    <value>true</value>
  </property>

  <property>
    <name>yarn.log-aggregation.retain-seconds</name>
    <value>604800</value>
  </property>

  <property>
    <name>mapreduce.jobhistory.address</name>
    <value>localhost:10020</value>
  </property>

  <property>
    <name>mapreduce.jobhistory.webapp.address</name>
    <value>localhost:19888</value>
  </property>

  <property>
    <name>mapreduce.jobhistory.done-dir</name>
    <value>/tmp/hadoop-yarn/staging/history/done</value>
  </property>
  <property>
    <name>mapreduce.framework.name</name>
    <value>yarn</value>
  </property>
</configuration>

yarn-site.xml:

  
<?xml version="1.0"?>
<!--
  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.
-->
<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>localhost:8032</value>
  </property>
  <property>
    <name>yarn.resourcemanager.scheduler.address</name>
    <value>localhost:8030</value>
  </property>
  <property>
    <name>yarn.resourcemanager.hostname</name>
    <value>localhost</value>
  </property>
</configuration>

cd /usr/local/hadoop
./bin/hdfs namenode -format #格式化文件系统
cd /usr/local/hadoop
./sbin/start-dfs.sh

sudo touch /etc/pdsh/rcmd_default
sudo vim /etc/pdsh/rcmd_default
在文件中写入ssh
这里的目的是防止出现localhost: rcmd: socket: Permission denied错误。
接着jps查看启动节点即可知道是否安装成功伪分布。
配置PATH变量:
vim ~/.bashrc
export PATH=$PATH:/usr/local/hadoop/sbin:/usr/local/hadoop/bin 
source ~/.bashrc  之后在任何目录下启动Hadoop,都只要直接输入start-dfs.sh
命令即可,同理,停止Hadoop,也只需要在任何目录下输入stop-dfs.sh命令即可。  

Hadoop分布式文件配置

配置参考官方文档:https://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-common/ClusterSetup.html

/etc/hadoop/core-site.xml:  #这个主要负责设置namenode端口

fs.defaultFS   #设置NameNode对外提供HDFS服务端口

hadoop查看配置的 fs.default.name名字:
hdfs getconf -confKey fs.default.name 

hadoop.security.authorization  #指明是否开启用户认证,默认为false

/etc/hadoop/hdfs-site.xml: #主要负责datanode和namenode存储地址

dfs.namenode.name.dir   #dfs.namenode.name.dir是保存FsImage镜像的目录,作用是存放的名称节点namenode里的metadata。NameNode存储数据的文件所在的路径

dfs.datanode.data.dir   #dfs.datanode.data.dir是存放HDFS文件系统数据文件的目录,作用是存放hadoop的数据节点datanode里的多个数据块。DataNode存储数据的文件路径。

dfs.namenode.secondary.http-addres  #设置SecondNameNode节点地址,SecondaryNameNode的HTTP服务地址。

dfs.replication  #文件副本数量, 默认是3

/etc/hadoop/mapred-site.xml:

mapreduce.framework.name  #指定map reduce使用yarn资源管理器

/etc/hadoop/yarn-site.xml:

yarn.nodemanager.aux-services  #附属服务名称,如果使用mapreduce,需将之配置为mapreduce-shuffle

yarn.resourcemanager.address #ResourceManager 对客户端暴露的地址。客户端通过该地址向RM提交应用程序,杀死应用程序等,默认为8032

yarn.resourcemanager.scheduler.address #ResourceManager 对ApplicationMaster暴露的访问地址。ApplicationMaster通过该地址向RM申请资源、释放资源等。默认端口8030

yarn.resourcemanager.resource-tracker.address #ResourceManager 对NodeManager暴露的地址.。NodeManager通过该地址向RM汇报心跳,领取任务等。默认端口8031

  • yarn.nodemanager.aux-services 指定 Nodemanager 运行时加载的服务,这里是 mapreduce_shuffle
  • yarn.nodemanager.env-whitelist 指定在运行任务时允许使用的环境变量。
  • yarn.resourcemanager.address 指定 ResourceManager 运行的地址和端口。
  • yarn.resourcemanager.scheduler.address 指定 Scheduler 运行的地址和端口。
  • yarn.resourcemanager.resource-tracker.address 指定 ResourceTracker 运行的地址和端口。
  • yarn.resourcemanager.ha.enabled 指定开启 ResourceManager 的 HA 模式。
  • yarn.resourcemanager.ha.rm-ids 指定以逗号分隔的 ResourceManager ID 列表,用于标识不同的 ResourceManager 实例。
  • yarn.resourcemanager.hostname.X 指定以 ResourceManager ID 为前缀的属性,用于指定不同 ResourceManager 所在的机器名或 IP 地址。
  • ha.zookeeper.quorum 指定用于 ZKFC 和 ResourceManager HA 的 ZooKeeper 集合的主机名或 IP 地址列表。
  • yarn.resourcemanager.zk-state-store.address 指定用于 ResourceManager HA 的状态存储的 ZooKeeper 集合的连接地址。
  • yarn.resourcemanager.zk-address 指定用于连接到 ZooKeeper 的客户端的连接地址。

这是配置hadoop分布式zookeeper时候用到的,记录下,之后还要改

我是windows下idea连接ubuntu hadoop,这里要在windows下配置hadoop环境路径,参考这位大佬博主配的:(73条消息) 关于IDEA出现报错: java.io.FileNotFoundException: HADOOP_HOME and hadoop.home.dir are unset.、_小小程序员呀~的博客-CSDN博客

hadoop version #查看下载好的hadoop版本

(74条消息) Hadoop3.3.5winutils-Java文档类资源-CSDN文库

这是我用的winutils

(83条消息) hadoop3.3.3-winutils_winutils-Hadoop文档类资源-CSDN文库

配置hadoop环境变量,参考这位博主csdn就好:

(75条消息) winutils解决hadoop跨平台问题_Stackflowed的博客-CSDN博客

netstat -tpnl #查看ubuntu端口情况 查看hadoop 9000端口是否对外开发

以下是连接hadoop3.3.5的配置:

 <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-common</artifactId>
        <version>3.3.5</version>
    </dependency>

    <!-- hadoop hdfs -->
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-hdfs</artifactId>
        <version>3.3.5</version>
    </dependency>

    <!-- hadoop mapreduce -->
    <dependency>
        <groupId>org.apache.hadoop</groupId>
        <artifactId>hadoop-mapreduce-client-core</artifactId>
        <version>3.3.5</version>
    </dependency>
    <dependency>
         <groupId>org.apache.hadoop</groupId>
         <artifactId>hadoop-auth</artifactId>
         <version>3.3.5</version>
    </dependency>

    <!-- log4j -->
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>

配置好环境之后直接连接hadoop就可以了,这里端口必须对外开放,不然hadoop连接不起来。

log4j.properties:

#
# 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.
#
log4j.appender.console=org.apache.log4j.ConsoleAppender
log4j.appender.console.Target=System.err
log4j.appender.console.layout=org.apache.log4j.PatternLayout
log4j.appender.console.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n
log4j.rootLogger=INFO, console


 下面这个代码是查看hdfs根目录有哪些文件夹。

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FSDataInputStream;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;


import java.io.IOException;

public class connect {
    public static void main(String[] args) throws IOException {
        Configuration conf = new Configuration();
        conf.set("fs.defaultFS","hdfs://自己ubutunip地址:9000");
        FileSystem fs = FileSystem.get(conf);
        Path path = new Path("/");
        FileStatus[] fileStatus = fs.listStatus(path);

        for (FileStatus status : fileStatus) {
            System.out.println(status.getPath().toString());
        }
    }
}

伪分布式式要是连接的化要在hdfs-site.xml设置

    <property>
        <name>dfs.namenode.rpc-bind-host</name>
	    <value>0.0.0.0</value>
    </property>

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Hadoop安装和伪分布环境配置,部分分布式配置文件,以及idea连接分布式hadoop。 的相关文章

  • 信号量(sem)控制访问有限共享资源的线程数

    信号量 sem t就是个资源计数器 xff0c 用于控制访问有限共享资源的线程数 span class token macro property span class token directive keyword include span
  • 不需要各种代码的MATLAB语法高亮的设置,简单实用

    文章目录 前言一 代码高亮是什么 xff1f 二 设置步骤1 点击主页再点击预设2 点击MATLAB再点击颜色别着急因为是窗口太小哦所以要放大取消使用系统颜色 xff0c 然后自己选择文本颜色和背景颜色 总结 前言 这次主要想说说MATLA
  • 优先级队列(堆)

    优先级队列 1 什么是优先级队列2 什么时候用它什么时候不用它3 它的具体用法记得import两个库 xff1a 3 1定义3 2输入输出 1 什么是优先级队列 优先级队列就是用库内已有的类 xff0c 这个类名字是队列 xff0c 其实不
  • 2.1 关系模型的基本概念

    文章目录 2 1 1 基本术语定义2 1 用二维表格表示实体集 xff0c 用关键码表示实体间联系的数据模型称为关系模型 xff08 relational Model xff09 在关系模型中 xff0c 关键码 key 简称键 由一个或多
  • 2.2 关系代数的五个基本操作

    文章目录 前言2 2 关系代数2 2 1 关系代数的五个基本操作 1 投影 xff08 Projection xff09 2 选择 xff08 Selection xff09 选择与投影组合 3 xff09 并 xff08 Union xf
  • web的一些介绍

    文章目录 前言一 什么是Web xff1f 二 基本Web服务结构软件编程体系C S xff08 Client Server xff09 软件体系结构B S xff08 Brower Server xff09 软件体系结构C S结构与B S
  • .net技术第一章

    文章目录 NETC C Sharp 的特点C 的应用范围 NET Framework1 2 创建简单的C 程序结构和书写规则类型的声明和使用类型的声明和使用命名空间使用方法命名空间举例 注释Main方法命令行参数Main返回值 控制台输入和
  • .net----委托和事件

    委托和事件 委托声明实例化调用将类型安全的函数指针 方法 作为其他方法的参数进行传递 xff0c 从而实现函数回调方法委托 xff1a 匿名方法委托 多播委托委托 xff1a 委托的异步调用委托 xff1a 委托的兼容性 事件事件实际上是委
  • .net-----语言集成查询LINQ

    语言集成查询LINQ 前言相关语言要素初始值设定项匿名类型相关语言要素Lambda表达式扩展方法 LINQ的概念和基本操作集成语言查询LINQLINQ查询操作 标准查询运算符数据排序数据筛选数据投影数据分组联接运算数据分区限定运算聚合运算集
  • .net-----Windows 窗体应用程序包括控件,对话框,多重窗体,绘制图形,菜单和工具栏

    目录 前言Windows窗体应用程序概述 xff1b 窗体和大部分控件常用的事件创建Windows窗体应用程序使用Visual Studio集成开发环境实现Hello World程序 使用常用Windows窗体控件 xff1b Label
  • python字符串内建函数

    在八进制数前面显示零 0 xff0c 在十六进制前面显示 0x 或者 0X 取决于用的是 x 还是 X 0 显示的数字前面填充 0 而不是默认的空格 输出一个单一的 var 映射变量 字典参数 m n m 是显示的最小总宽度 n 是小数点后
  • 物理层-计算机网络速成

    物理层 1 物理层的基本概念1 1四大特性机械特性电气特性功能特性过程特性 1 2两种信号1 3 调制编码调制编码区别 1 4 传输介质双绞线光纤同轴电缆 xff1a 淘汰 xff0c 有线电话无线 xff1a IEEE802 11 1 5
  • 考研第一天,汤家凤基础班,连续与极限复习笔记

    函数连续极限 性质保号性证明极值点 xff1a 夹逼准则二项式展开根号下 xff0c 大于一 xff0c 小于一的讨论直接放缩求和分子分母齐次 xff0c 且分母大一次 xff0c 用积分 单调有界存在极限几个重要的切线放缩证明有界 xff
  • Ubuntu双系统安装教程

    安装Ubuntu双系统 1 下载Ubuntu镜像源文件2 下载制作U盘启动工具3 磁盘分区4 安装Ubuntu 1 下载Ubuntu镜像源文件 18 04 6链接 xff1a http mirrors aliyun com ubuntu r
  • Arduino造轮子—红外遥控器

    今天练习的程序是实现红外遥控器的控制 xff0c 首先 xff0c 通过太极创客的视频来看看最终的实现结果 xff1a 太极创客 零基础入门学用Arduino 第三部分 智能应用篇 合辑 本次程序例程来自太极创客官网 xff0c 此平台的A
  • 嵌入式软件刷题日记【第一天】

    1 什么是同步IO xff0c 什么是异步IO 同步就是在发出一个功能调用时 xff0c 会一直阻塞等地结果 异步就是在发出一个功能调用时 xff0c 无需阻塞等待结果 xff0c 当结果产生一般通过状态 xff0c 回调等方法来通知调用者
  • 嵌入式软件刷题笔记【第四天】

    1 头文件的两种包含形式的区别 xff1f lt gt 尖括号形式表示引用系统编译器类库路径里面的头文件 34 34 双引号则表示引用当前文件工作目录相对路径里面的头文件 2 STM32 中断是怎么进入到中断服务程序的 xff1f STM3
  • 嵌入式软件刷题【第五天】

    1 在请求分页式存储管理中 xff0c 假设一次内存访问时间为 100ns xff0c 一次快表 xff08 TLB xff09 访问时间为 20ns xff0c 地址转换计算时的快表命中率为 80 xff0c 请计算平均有效内存访问时间为
  • OSlab

    OSlab B站链接 xff1a https www bilibili com video BV1kU4y1m7QW share source 61 copy web Linux环境实践作业 在Windows Terminal的Ubuntu
  • Linux操作命令学习笔记

    Linux操作命令学习笔记 常用操作命令 xff08 以下均严格区分大小写 xff09 查看文件以及文件夹 xff1a ls命令 ls a xff08 显示隐含文件 xff0c 如以 开头的文件 ls l 长格式输出 xff0c 和ll命令

随机推荐