java串連hdfs ha和調用mapreduce jar樣本_java

來源:互聯網
上載者:User

Java API 串連 HDFS HA

複製代碼 代碼如下:

public static void main(String[] args) {
  Configuration conf = new Configuration();
  conf.set("fs.defaultFS", "hdfs://hadoop2cluster");
  conf.set("dfs.nameservices", "hadoop2cluster");
  conf.set("dfs.ha.namenodes.hadoop2cluster", "nn1,nn2");
  conf.set("dfs.namenode.rpc-address.hadoop2cluster.nn1", "10.0.1.165:8020");
  conf.set("dfs.namenode.rpc-address.hadoop2cluster.nn2", "10.0.1.166:8020");
  conf.set("dfs.client.failover.proxy.provider.hadoop2cluster",        "org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider");
  FileSystem fs = null;
  try {
     fs = FileSystem.get(conf);
     FileStatus[] list = fs.listStatus(new Path("/"));
     for (FileStatus file : list) {
       System.out.println(file.getPath().getName());
      }
  } catch (IOException e) {
     e.printStackTrace();
  } finally{
      try {
        fs.close();
      } catch (IOException e) {
        e.printStackTrace();
      }
  }
}

Java API調用MapReduce程式

複製代碼 代碼如下:

String[] args = new String[24];
args[0] = “/usr/hadoop-2.2.0/share/hadoop/mapreduce/hadoop-mapreduce-examples-2.2.0.jar";
args[1] = "wordcount";
args[2] = "-D";
args[3] = "yarn.resourcemanager.address=10.0.1.165:8032";
args[4] = "-D";
args[5] = "yarn.resourcemanager.scheduler.address=10.0.1.165:8030";
args[6] = "-D";
args[7] = "fs.defaultFS=hdfs://hadoop2cluster/";
args[8] = "-D";
args[9] = "dfs.nameservices=hadoop2cluster";
args[10] = "-D";
args[11] = "dfs.ha.namenodes.hadoop2cluster=nn1,nn2";
args[12] = "-D";
args[13] = "dfs.namenode.rpc-address.hadoop2cluster.nn1=10.0.1.165:8020";
args[14] = "-D";
args[15] = "dfs.namenode.rpc-address.hadoop2cluster.nn2=10.0.1.166:8020";
args[16] = "-D";
args[17] = "dfs.client.failover.proxy.provider.hadoop2cluster=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider";
args[18] = "-D";
args[19] = "fs.hdfs.impl=org.apache.hadoop.hdfs.DistributedFileSystem";
args[20] = "-D";
args[21] = "mapreduce.framework.name=yarn";
args[22] = "/input";
args[23] = "/out01";
RunJar.main(args);

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.