IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 大数据 -> hadoop学习之WebHDFS (REST API) -> 正文阅读

[大数据]hadoop学习之WebHDFS (REST API)

官网永远是学习最好的地方

https://hadoop.apache.org/docs/r3.2.2/hadoop-yarn/hadoop-yarn-site/FairScheduler.html

?为什么要用rest api呢? 使用这个之前我们是如何操作hdfs上的文件的?

通过fs地址 和filesysterm,

现在webHdfs这个明显好用。。。

直接开搞。两种方式 一种是shell脚本 一种是java代码。

webhdfs已经开启?

?rest 端口为14000

集群为cdh 安装了kerberos的认证。

shell版本

[devuser@worker01 /data/cc_test/web]$ kinit hdfs 
Password for hdfs@CDH.COM: 
[devuser@worker01 /data/cc_test/web]$ klist
Ticket cache: FILE:/tmp/krb5cc_1000
Default principal: hdfs@CDH.COM

Valid starting       Expires              Service principal
2021-07-26T15:51:03  2021-07-27T15:51:03  krbtgt/CDH.COM@CDH.COM
	renew until 2021-08-02T15:51:03
[devuser@worker01 /data/cc_test/web]$ curl --negotiate -u : http://node03.data.com:14000/webhdfs/v1/?op=liststatus
{"FileStatuses":{"FileStatus":[{"pathSuffix":"data","type":"DIRECTORY","length":0,"owner":"hive","group":"hive","permission":"755","accessTime":0,"modificationTime":1627024265890,"blockSize":0,"replication":0},{"pathSuffix":"dolphinscheduler","type":"DIRECTORY","length":0,"owner":"dolphinscheduler","group":"dolphinscheduler","permission":"755","accessTime":0,"modificationTime":1606204815466,"blockSize":0,"replication":0},{"pathSuffix":"dolphinscheduler_xxx","type":"DIRECTORY","length":0,"owner":"dolphinscheduler","group":"dolphinscheduler","permission":"755","accessTime":0,"modificationTime":1604988539901,"blockSize":0,"replication":0},{"pathSuffix":"hbase","type":"DIRECTORY","length":0,"owner":"hbase","group":"hbase","permission":"755","accessTime":0,"modificationTime":1626160944859,"blockSize":0,"replication":0},{"pathSuffix":"streamx","type":"DIRECTORY","length":0,"owner":"devuser","group":"devuser","permission":"777","accessTime":0,"modificationTime":1624874177497,"blockSize":0,"replication":0},{"pathSuffix":"system","type":"DIRECTORY","length":0,"owner":"hdfs","group":"supergroup","permission":"755","accessTime":0,"modificationTime":1618555718143,"blockSize":0,"replication":0},{"pathSuffix":"tmp","type":"DIRECTORY","length":0,"owner":"hdfs","group":"supergroup","permission":"1777","accessTime":0,"modificationTime":1622450280651,"blockSize":0,"replication":0},{"pathSuffix":"user","type":"DIRECTORY","length":0,"owner":"hdfs","group":"supergroup","permission":"755","accessTime":0,"modificationTime":1611304943508,"blockSize":0,"replication":0}]}}
[devuser@worker01 /data/cc_test/web]$ 

java代码版本

import cn.hutool.core.lang.Console;
import cn.hutool.http.HttpUtil;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.security.UserGroupInformation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Properties;

public class downloadUtil {
    private static Logger logger=LoggerFactory.getLogger(downloadUtil.class);

    private  static  String listStatus_url="http://node03.data.com:14000/webhdfs/v1/?op=liststatus";
    public static void main(String[] args) {
        kerberos_auth(null);
        String result1= HttpUtil.get(listStatus_url);
        Console.log(result1);
    }

    private static void kerberos_auth(Properties prop){
        if (System.getProperty("os.name").toLowerCase().contains("windows")) {
            try {
                String krb5FilePath = "C:\\Users\\coder\\Desktop\\kerberos\\krb5.ini";
                String krb5KeyTabPath = "C:\\Users\\coder\\Desktop\\kerberos\\hive.keytab";
                String krbPrincipal = "hive@CDH.COM";
                // System.setProperty("java.security.krb5.conf", krb5Conf);
                System.setProperty("java.security.krb5.conf", krb5FilePath);
                System.setProperty("sun.security.krb5.debug", "true");
                Configuration configuration = new Configuration();
                configuration.set("hadoop.security.authentication", "Kerberos");
                configuration.set("keytab.file", krb5KeyTabPath);
                configuration.set("kerberos.principal", krbPrincipal);
                UserGroupInformation.setConfiguration(configuration);
                UserGroupInformation.loginUserFromKeytab(krbPrincipal, krb5KeyTabPath);
            } catch (IOException e) {
                logger.error("kerberos login异常 : {}", e.getMessage());
            }
        }else {
            try {
                String hive_keytable = prop.getProperty("hive_keytable");
                String hive_principal= prop.getProperty("hive_principal");
                logger.info("验证kerberos,hive_principal={},hive_keytable={}",hive_principal,hive_keytable);
                UserGroupInformation.loginUserFromKeytab(hive_principal, hive_keytable);
            } catch (IOException e) {
                logger.error("kerberos login异常 : {}", e.getMessage());
            }
        }
    }

}

打印日志

{
  "FileStatuses": {
    "FileStatus": [
      {
        "pathSuffix": "data",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "hive",
        "group": "hive",
        "permission": "755",
        "accessTime": 0,
        "modificationTime": 1627024265890,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "dolphinscheduler",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "dolphinscheduler",
        "group": "dolphinscheduler",
        "permission": "755",
        "accessTime": 0,
        "modificationTime": 1606204815466,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "dolphinscheduler_xxx",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "dolphinscheduler",
        "group": "dolphinscheduler",
        "permission": "755",
        "accessTime": 0,
        "modificationTime": 1604988539901,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "hbase",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "hbase",
        "group": "hbase",
        "permission": "755",
        "accessTime": 0,
        "modificationTime": 1626160944859,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "streamx",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "devuser",
        "group": "devuser",
        "permission": "777",
        "accessTime": 0,
        "modificationTime": 1624874177497,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "system",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "hdfs",
        "group": "supergroup",
        "permission": "755",
        "accessTime": 0,
        "modificationTime": 1618555718143,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "tmp",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "hdfs",
        "group": "supergroup",
        "permission": "1777",
        "accessTime": 0,
        "modificationTime": 1622450280651,
        "blockSize": 0,
        "replication": 0
      },
      {
        "pathSuffix": "user",
        "type": "DIRECTORY",
        "length": 0,
        "owner": "hdfs",
        "group": "supergroup",
        "permission": "755",
        "accessTime": 0,
        "modificationTime": 1611304943508,
        "blockSize": 0,
        "replication": 0
      }
    ]
  }
}

  大数据 最新文章
实现Kafka至少消费一次
亚马逊云科技:还在苦于ETL?Zero ETL的时代
初探MapReduce
【SpringBoot框架篇】32.基于注解+redis实现
Elasticsearch:如何减少 Elasticsearch 集
Go redis操作
Redis面试题
专题五 Redis高并发场景
基于GBase8s和Calcite的多数据源查询
Redis——底层数据结构原理
上一篇文章      下一篇文章      查看所有文章
加:2021-07-27 16:17:12  更:2021-07-27 16:19:23 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/22 23:39:00-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码