DFSClient通过HA方式操作HDFS

2020-05-19  本文已影响0人  mrknowledge

只需在创建FileSystem的时候的Conf类中添加如下参数即可:

//设置hdfs配置信息

Configuration conf = new Configuration();

//设置配置相关的信息,分别对应hdfs-site.xml core-site.xml

conf.set("fs.defaultFS", "hdfs://dragoncluster");

conf.set("dfs.nameservices", "dragoncluster");

conf.set("dfs.ha.namenodes.dragoncluster", "nn1,nn2");

conf.set("dfs.namenode.rpc-address.dragoncluster.nn1", "n01.dragon.com:8020");

conf.set("dfs.namenode.rpc-address.dragoncluster.nn2", "n02.dragon.com:8020");

conf.set("dfs.client.failover.proxy.provider.dragoncluster", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");

//设置实现类,因为会出现类覆盖的问题

conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());

conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());

上一篇 下一篇

猜你喜欢

热点阅读