java修改hdfs文件权限,HDFS基础和java api操作

1. 概括

适合一次写入多次查询情况,不支持并发写情况

通过hadoop shell 上传的文件存放在DataNode的block中,通过linux

shell只能看见block,看不见文件(HDFS将客户端的大文件存放在很多节点的数据块中,Block本质上是一个逻辑概念,它是hdfs读写数据的基本单位)

HDFS中,如果一个文件小于一个数据块的大小,并不占用整个数据块存储空间

2. fs

可以使用hdfs shell操作hdfs,常用 fs命令如下:

eg: hadoop fs -cat file1

69c5a8ac3fa60e0848d784a6dd461da6.png- put localsrc dst //从本地文件移动到hdfs

-get src localsrc //复制文件到本地

-text src //显示文件内容

其他类似于linux shell

69c5a8ac3fa60e0848d784a6dd461da6.png

3. 端口

端口:

50070:查看NameNode状态50075:查看DataNode状态50090:查看SecondaryNameNode50030:查看JobTracker状态50060:查看TaskTracker状态

4. hdfs安全模式

在启动hadoop集群的时候,集群的运行首先进入到安全模式下(safeMode),以检查数据完整性

69c5a8ac3fa60e0848d784a6dd461da6.png(hdfs-default.xml,302行)dfs.safemode.threshold.pct

0.999f

这里定义了一个最小的副本率0.999,如果应该有5个副本存在,却只存在3个副本,3/5=0.6<0.999,则系统会自动地复制副本到其他DataNode,使得副本率不小于0.999,相反,如果此时系统中有8个副本,则会自动删除多余的3个副本

69c5a8ac3fa60e0848d784a6dd461da6.png

安全模式相关操作:

hadoop fs –safemode get:查看安全模式状态

hadoop fs –safemode enter:进入安全模式状态

hadoop fs –safemode leave:离开安全模式状态

5. java api

注意:1)需注释掉org.apache.hadoop.fs.FileUtil类的checkReturnValue方法(688—692),否则可能出现权限问题)

2)需要修改远程登录客户端的用户名,以避免权限问题

我的电脑-管理-本地用户和组;

注册表“HKEY_LOCAL_MACHINE\SOFEWARE\Microsoft\Windows

NT\CurrentVersion 修改  RegisteredOwner

写文件:

69c5a8ac3fa60e0848d784a6dd461da6.pngString uri="hdfs://hadoop:9000/";

Configuration configuration=newConfiguration();

FileSystem fileSystem=FileSystem.get(URI.create(uri),configuration);final String pathString="/input";final FSDataOutputStream fsDataOutputStream=fileSystem.create(newPath(pathString));

IOUtils.copyBytes(new ByteArrayInputStream("wish\n".getBytes()),fsDataOutputStream,configuration,false);

IOUtils.copyBytes(new ByteArrayInputStream("wish you happy \n".getBytes()),fsDataOutputStream,configuration,true);

69c5a8ac3fa60e0848d784a6dd461da6.png

读文件:

String uri="hdfs://hadoop:9000/";

Configuration configuration=newConfiguration();

FileSystem fileSystem=FileSystem.get(URI.create(uri),configuration);final String pathString="/output";final FSDataInputStream fsDataInputStream=fileSystem.open(newPath(pathString));

IOUtils.copyBytes(fsDataInputStream, System.out, configuration,true);

创建目录:

69c5a8ac3fa60e0848d784a6dd461da6.pngString uri="hdfs://hadoop:9000/";

Configuration configuration=newConfiguration();

FileSystem fileSystem=FileSystem.get(URI.create(uri),configuration);final String pathString="/d1";boolean exists=fileSystem.exists(newPath(pathString));if(!exists){boolean result=fileSystem.mkdirs(newPath(pathString));

System.out.println(result);

}

69c5a8ac3fa60e0848d784a6dd461da6.png

删除文件

String uri="hdfs://hadoop:9000/";

Configuration configuration=newConfiguration();

FileSystem fileSystem=FileSystem.get(URI.create(uri),configuration);final String pathString="/output";

fileSystem.delete(new Path("/output"),true);

原文:http://www.cnblogs.com/wishyouhappy/p/3730606.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值