I wrote before that JAVA uses a client to connect to Hadoop, which is a single node; all clusters are used in production. I haven’t found a detailed configuration method for the cluster after searching online for a long time. The client in the Hadoop nameNode HA cluster needs to be connected. Each node of the client cluster.
Method 1: Load using XML configuration file
This method is based on the core-site.xml file configured in the Hadoop cluster service. Of course, the configuration file can also be written by hand. (Tucao, when I was doing it, O&M only provided a bunch of IPs for me to guess)
configuration = new Configuration();
//通过加载配置文件配置
configuration.addResource(core-site.xml);
FileSystem fs = FileSystem.get(configuration);
The configuration file template is as follows
<configuration>
<property>
<name>fs.default.name</name>
<!--<name>fs.defaultFS</name>-->
<value>hdfs://hadoopCluster</value>
</property>
<property>
<name>dfs.nameservices</name>
<value>hadoopCluster