您当前的位置: 首页 >  hdfs

梁云亮

暂无认证

  • 2浏览

    0关注

    1211博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

HDFS 参数优先级测试

梁云亮 发布时间:2019-12-04 00:19:40 ,浏览量:2

结论:

参数从高到低:代码中指定的>项目中配置文件中指定的>Hadoop环境中用户指定的>default

示例1:测试Hadoop环境中用户指定的

什么配置文件都不需要,只需要如下代码:

public static void main(String[] args) throws Exception {
    Configuration cfg = new Configuration();
    FileSystem fs = FileSystem.get(new URI("hdfs://hcmaster:9000"),cfg);
    fs.copyFromLocalFile(new Path("E:/test/core-site.xml"), new Path("/a.xml"));
    fs.close();
}

结果: 在这里插入图片描述

示例2:测试项目中配置文件中指定的

在项目的类路径下面创建文件hdfs-site.xml,添加如下所示的内容:



   
      dfs.replication
      1
   

上传文件的代码:
public static void main(String[] args) throws Exception {
    Configuration cfg = new Configuration();
    FileSystem fs = FileSystem.get(new URI("hdfs://hcmaster:9000"),cfg);
    fs.copyFromLocalFile(new Path("E:/test/core-site.xml"), new Path("/a.xml"));
    fs.close();
}
结果:

在这里插入图片描述

示例3:测试代码中指定

保留示例2中类路径下面创建文件hdfs-site.xml,修改测试代码:

public static void main(String[] args) throws Exception {
    Configuration cfg = new Configuration();
    cfg.set("dfs.replication","2");
    FileSystem fs = FileSystem.get(new URI("hdfs://hcmaster:9000"),cfg);
    fs.copyFromLocalFile(new Path("E:/test/core-site.xml"), new Path("/a.xml"));
    fs.close();
}
结果:

在这里插入图片描述

关注
打赏
1665409997
查看更多评论
立即登录/注册

微信扫码登录

0.0410s