hadoop版本:2.7.3
使用场景:
线上服务写hdfs,写过程中namenode的master节点发生HA切换,为保证写服务不因为连接中断而终止,需要在客户端以nameservices 的方式初始化 FileSystem
方式一 :代码里添加配置项
# conf.set("key", "value"); key保持不变,value值去core-site.xml 、hdfs-site.xml文件里找
Configuration conf = new Configuration();
conf.set("fs.defaultFS", "hdfs://nameservices");
conf.set("dfs.nameservices", "nameservices");
conf.set("dfs.ha.namenodes.nameservices", "nn1,nn2");
conf.set("dfs.namenode.rpc-address.nameservices.nn1", "bigdata-hadoop-0-x:8020");
conf.set("dfs.namenode.rpc-address.nameservices.nn2", "bigdata-hadoop-0-xx:8020");
conf.set("dfs.client.failover.proxy.provider.nameservices", "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");