zoukankan      html  css  js  c++  java
  • 【Hadoop】HA 场景下访问 HDFS JAVA API Client

    客户端需要指定ns名称,节点配置,ConfiguredFailoverProxyProvider等信息。

    代码示例:

    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.setBoolean(name, value);
            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");
            InputStream in =new FileInputStream("c://eclipse.rar");
            OutputStream out = fs.create(new Path("/eclipse"));
            IOUtils.copyBytes(in, out, 4096, true);
        }
    }
  • 相关阅读:
    c--日期和时间函数
    笔试题:360找镇长的题。
    【JavaScript】BOM和DOM
    也谈在 .NET 平台上使用 Scala 语言(续)
    生成n个元素的全排列 C实现
    jsp安全性问题
    stm32DMA通道 ADC通道
    POJ 1860
    Codeforces Round #FF (Div. 2) A. DZY Loves Hash
    Configure the modules to be find by modprobe
  • 原文地址:https://www.cnblogs.com/junneyang/p/5869413.html
Copyright © 2011-2022 走看看