zoukankan      html  css  js  c++  java
  • HDFS 开发中的文件配置优先级

    一、先看集群上的配置,这里设置了文件块副本数为 3

    上传一个文件试试

    public class ConfigPriority {
        private Configuration conf;
        private FileSystem fs;
    
        @Before
        public void init() throws Exception {
            // 设置 HADOOP_HOME 环境变量
            System.setProperty("hadoop.home.dir", "D:/DevelopTools/hadoop-2.9.2/");
            // 日志初始化
            BasicConfigurator.configure();
    
            conf = new Configuration();
            // 获取 hdfs 客户端对象,指定用户名,避免无权限
            fs = FileSystem.get(new URI("hdfs://192.168.8.136:9000"), conf, "root");
        }
    
        @After
        public void close() throws IOException {
            fs.close();
        }
    
        // 文件上传
        @Test
        public void testCopyFromLocalFile() throws Exception{
            fs.copyFromLocalFile(new Path("D://MyFile/Downloads/Writage-1.12.msi"), new Path("/Priority/AAA.msi"));
        }
    }

    二、在资源目录添加 hdfs-site.xml 配置后再上传

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
    <configuration>
        <property>
            <name>dfs.replication</name>
            <value>1</value>
        </property>
    </configuration>

    代码中的上传名字做下改变

    三、在代码中指定下配置参数

    public class ConfigPriority {
        private Configuration conf;
        private FileSystem fs;
    
        @Before
        public void init() throws Exception {
            // 设置 HADOOP_HOME 环境变量
            System.setProperty("hadoop.home.dir", "D:/DevelopTools/hadoop-2.9.2/");
            // 日志初始化
            BasicConfigurator.configure();
    
            conf = new Configuration();
            conf.set("dfs.replication","2");
            // 获取 hdfs 客户端对象,指定用户名,避免无权限
            fs = FileSystem.get(new URI("hdfs://192.168.8.136:9000"), conf, "root");
        }
    
        @After
        public void close() throws IOException {
            fs.close();
        }
    
        // 文件上传
        @Test
        public void testCopyFromLocalFile() throws Exception{
            fs.copyFromLocalFile(new Path("D://MyFile/Downloads/Writage-1.12.msi"), new Path("/Priority/CCC.msi"));
        }
    }

    总结:代码设置 > 工程资源目录配置 > 集群配置 > 默认配置

  • 相关阅读:
    在不打开excel的情况下用python执行excel
    Python中xlrd、xlwt、win32com模块对xls文件的读写操作
    [已解决]报错:have mixed types. Specify dtype option on import or set low_memory=False
    [已解决]报错:xlrd.compdoc.CompDocError: Workbook: size exceeds expected 17920 bytes; corrupt?
    使用Pandas读取大型Excel文件
    [转]jmeter实战
    webService(SOAP)性能测试脚本
    jmeter正则表达式提取器--关联
    Data Set Config配置元件
    压力测试涉及到的参数
  • 原文地址:https://www.cnblogs.com/jhxxb/p/10704806.html
Copyright © 2011-2022 走看看