hdfs 客户端挂载,集群间复制

客户端挂载表

core-site.xml配置


    fs.defaultFS
    viewfs://nsX
   整个Federation集群对外提供服务的NS逻辑名称,
        注意,这里的协议不再是hdfs,而是新引入的viewfs
        这个逻辑名称会在下面的挂载表中用到

*core-site.xml配置

fs.viewfs.mounttable.default.link./cluster1
hdfs://crxy1:9000/


fs.viewfs.mounttable.default.link./cluster3
hdfs://crxy3:9000


ViewFileSystemfsView = (ViewFileSystem) ViewFileSystem.get(conf);
MountPoint[]m = fsView.getMountPoints();
for(MountPoint m1 : m)
    System.out.println( m1.getSrc() );
// 直接使用/share/test.txt创建文件
// 如果按照之前的配置,客户端会自动根据挂载表找到是ns1
// 然后再通过failover proxy类知道nn1是Active NN并与其通信
Pathp = new Path("/share/test.txt");
FSDataOutputStreamfos = fsView.create(p);



自己实现放入回收站功能

*配置:在每个节点(不仅仅是主节点)上添加配置core-site.xml,增加如下内容

   fs.trash.interval
   1440

public static boolean rm(FileSystem fs, Path path, boolean recursive, boolean skipTrash) throws IOException {
        if (!skipTrash) {
            Trash trashTmp = new Trash(fs, conf);
            if (trashTmp.moveToTrash(path)) {
                log.info("Moved to trash: " + path);
                return true;
            }
        }
        boolean ret = fs.delete(path, recursive);
        if (ret)
            log.info("rm: " + path);
        return ret;
    }


集群间复制

distcp一般用于在两个HDFS集群中传输数据。如果集群在Hadoop的同一版本上运行,就适合使用hdfs方案

 hadoop distcp hdfs://namenode1/foo hdfs://namenode2/bar 

在两个运行着不同版本HDFS的集群上利用distcp,使用hdfs协议是会失败的,因为RPC系统是不兼容的

hadoop distcp hftp://namenode1:50070/foo hdfs://namenode2/bar 
注意,需要在URI源中指定名称节点的Web端口。这是由dfs.http.address的属性决定的,默认值为50070



你可能感兴趣的:(hadoop)