zoukankan      html  css  js  c++  java
  • JAVA HDFS API Client 连接HA

    如果Hadoop开启HA,那么用Java Client连接Hive的时候,需要指定一些额外的参数

    package cn.itacst.hadoop.hdfs;
    
    import java.io.FileInputStream;
    import java.io.InputStream;
    import java.io.OutputStream;
    import java.net.URI;
    
    import org.apache.hadoop.conf.Configuration;
    import org.apache.hadoop.fs.FileSystem;
    import org.apache.hadoop.fs.Path;
    import org.apache.hadoop.io.IOUtils;
    
    public class HDFS_HA {
    
        
        public static void main(String[] args) throws Exception {
            Configuration conf = new Configuration();
            conf.set("fs.defaultFS", "hdfs://ns1");
            conf.set("dfs.nameservices", "ns1");
            conf.set("dfs.ha.namenodes.ns1", "nn1,nn2");
            conf.set("dfs.namenode.rpc-address.ns1.nn1", "itcast01:9000");
            conf.set("dfs.namenode.rpc-address.ns1.nn2", "itcast02:9000");
            conf.set("dfs.client.failover.proxy.provider.ns1", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
            FileSystem fs = FileSystem.get(new URI("hdfs://ns1"), conf, "hadoop");
            FileStatus[] list = fs.listStatus(new Path("/"));
            for (FileStatus fileStatus : list) {
                System.out.println(fileStatus.toString());
            }
         fs.close();
    } }
  • 相关阅读:
    php函数总结
    文本框输入限制
    e.keyCode和e.which使用
    transform总结
    wampSever的mysql操作
    linux命令总结
    nginx总结
    微雪的stm32学习资料
    串口+RS485驱动
    cubemx+stm32串口学习汇总资料
  • 原文地址:https://www.cnblogs.com/shysky77/p/6971850.html
Copyright © 2011-2022 走看看