首页 >> 大全

学习大数据的第47天(HDFS以及Zookeeper)——HDFS的重要架构知识

2023-07-31 大全 22 作者:考证青年

学习大数据的第47天(HDFS以及)——HDFS的重要架构知识点以及的安装和基本命令 HDFS的知识点 HDFS文件块的大小

HDFS的写流程

自己的话总结一下:

首先客户端通过fs(类型为m)向发送请求,回应请求,继续请求上传第一个block块,回应客户端存储到哪个中,这里数据在备份的时候要求跨机架,数据保存到多个中,请求建立连接,之间应答通道请求,传输第一个block块,返回传输结果。

代码详解

Configuration conf = new Configuration();
//        public void set(String name, String value) {conf.set("fs.defaultFS","hdfs://master:9000");FileSystem fs = FileSystem.get(conf);/*** Params:* delSrc – whether to delete the src* overwrite – whether to overwrite an existing file* src – path  文件的路径* dst – path   HDFS 的文件路径 完整的路径*/fs.copyFromLocalFile(false,true,new Path("G:\\MyIdeaProjects\\HadoopCode\\data\\sanguo.txt"),new Path("/hdfsDemo/sanguo.txt"));fs.close();

数据备份:

数据备份的意义:

​ 1、机架容灾,网络问题,整个机架毁损

​ 2、相同机架中的保存两份

为什么不放三个机架中 呢?

​ 可能会造成很大的网络IO问题

机架感知:

HDFS的读流程

代码详解:

Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://master:9000");
conf.set("dfs.replication", "3");
FileSystem fs = FileSystem.get(conf);
/*** Params:* f – is the path* recursive – if the subdirectories need to be traversed recursively  如果需要递归,则设置为true**/
RemoteIterator<LocatedFileStatus> files = fs.listFiles(new Path("/hdfsDemo/sanguo2.txt"), true);
while (files.hasNext()) {LocatedFileStatus fileStatus = files.next();//获取block 大小System.out.println(fileStatus.getBlockSize());//获取路径System.out.println(fileStatus.getBlockLocations());//获取所有者System.out.println(fileStatus.getOwner());BlockLocation[] blockLocations = fileStatus.getBlockLocations();for (BlockLocation b : blockLocations) {//获取HostSystem.out.println("hosts:" + b.getHosts());System.out.println("names:" + b.getNames());System.out.println("length:" + b.getLength());}
}
fs.close();

:

是整个文件系统的管理节点。它维护着整个文件系统的文件目录树,文件/目录的元信息和每个文件对应的数据块列表。接收用户的操作请求。

文件包括:

:元数据镜像文件。存储某一时段内存元数据信息。

edits:操作日志文件,启动后一些新增元信息日志。

:保存最近一次的时间 (老版本)

以上这些文件是保存在linux的文件系统中。

hdfs-site.xml的dfs..name.dir属性

hdfs的两种命令模式:

fs

hdfs dfs

hdfs中的oiv和oev的用法

oiv apply the to an

hdfs oiv -p xml -i -o .xml

hdfs oiv -p 文件格式 -i 文件名 -o 转换后的文件路径

hdfs oev -p xml -i 00271 -o edits.xml

hdfs oev -p 文件格式 -i 文件名 -o 转换后的文件路径

的工作流程:

概述:

使用的数据结构为树形结构,根节点为"/"。集群中的节点,根据其身份特性分为、、。负责客户端类型的请求;负责客户端类型的请求,并参与选举;是特殊的,可以接收客户端请求,但是不会参与选举,可以用来扩容系统支撑能力,提高读取速度。

是一个基于观察者模式设计的分布式服务管理框架,负责存储和管理相关数据,接收观察者的注册。

的安装过程:

1、上传安装包到并解压

tar -xvf -3.4.6.tar.gz

2、配置环境变量

vim /etc/

=/usr/local/soft/-3.4.6

PATH= P A T H : PATH: PATH:/bin

/etc/

3、修改配置文件

cd conf

cp .cfg zoo.cfg

修改

=/usr/local/soft/-3.4.6/data

增加

.0=:2888:3888

.1=node1:2888:3888

.2=node2:2888:3888

4、同步到其它节点

scp -r -3.4.6 node1:pwd

scp -r -3.4.6 node2:pwd

配置node1和node2的环境变量

scp /etc/ node1:/etc/

scp /etc/ node2:/etc/

在所有节点执行

/etc/

5、创建/usr/local/soft/-3.4.6/data目录,所有节点都要创建

mkdir /usr/local/soft/-3.4.6/data

在data目录下创建myid文件

vim myid

,node1,node2分别加上0,1,2

6、启动zk,

.sh start 三台都需要执行

.sh 查看状态

当有一个的时候启动成功

7、连接zk

bash zkCli.sh

zk 是一个目录结构 ,每个节点可以存数据,同时可以有子节点

8、zk shell

创建目录

/test test

/test/a 1

获取数据

get /test

ls /test

只能删除没有子节点的节点

rmr /test 删除节点

9、重置zk

1、杀掉所有zk进程

kiil -9 pid

2、删除data目录下的文件, 所有节点都要删除

rm -rf /usr/local/soft/-3.4.6/data/-2

2、启动zk

.sh start

笔记:

>>>>>>>>>>>>>>>>>>zookeeper配置信息解释<<<<<<<<<<<<<<<<<<<<<<<<# The number of milliseconds of each tick# 心跳时间 ms  2秒一次心跳
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take# 通信限时 当服务启动时 限定初始的心跳数
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement# 超时心跳 数  syncLimit * tickTime = 10s
syncLimit=5# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.dataDir=/usr/local/soft/zookeeper-3.4.6/data
# the port at which the clients will connect
clientPort=2181>>>>>>>>>>>>>>>>>>zookeeper常用命令<<<<<<<<<<<<<<<<<<<<<<<<# 登录zookeeperbash zkcli.sh  <- 默认连接 localhost:2181# 命令:help表示帮助命令ls:表示查看指定路径节点下的节点信息create /test abc表示创建节点并赋值get /test表示获取指定节点位置的值set /test cb 表示重新设置节点的值delete /test/test1表示删除test1节点

关于我们

最火推荐

小编推荐

联系我们


版权声明:本站内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 88@qq.com 举报,一经查实,本站将立刻删除。备案号:桂ICP备2021009421号
Powered By Z-BlogPHP.
复制成功
微信号:
我知道了