首页 > 编程语言 > 详细

【Hadoop】HA 场景下访问 HDFS JAVA API Client

时间:2017-07-19 19:22:07      阅读:306      评论:0      收藏:0      [点我收藏+]

客户端需要指定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);
    }
}
技术分享
 

【Hadoop】HA 场景下访问 HDFS JAVA API Client

原文:http://www.cnblogs.com/rocky-AGE-24/p/7207340.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!