通过NFS将HDFS映射到本地文件系统

  • hdfs是分布式文件系统,要想访问hdfs上的文件,可以用java api或者hadoop shell等工具,如果想操作hdfs文件系统就像操作本地文件系统一样的便捷,可以将hdfs文件系统挂载到本地的一个目录上,可以通过nfs挂载--apache hadoop2.x以后的版本中自带了一个nfs3的插件服务,下面将详细讲解nfs挂载的方式。

  • 官方介绍

    http://hadoop.apache.org/docs/r2.5.2/hadoop-project-dist/hadoop-hdfs/HdfsNfsGateway.html
    
  • 配置core-site.xml

    
        hadoop.proxyuser.nfsserver.groups
        *
        允许所有用户组用户代理
    
    
        hadoop.proxyuser.nfsserver.hosts
        localhost
        允许挂载的主机域名
    
    
    
  • 修改hdfs-site.xml

    
        nfs.dump.dir
        /tmp/.hdfs-nfs
    
    
        nfs.rtmax
        1048576
        This is the maximum size in bytes of a READ request supported by the NFS gateway. If you change this, make sure you also update the nfs mount's rsize(add rsize= # of bytes to the mount directive).
    
    
        nfs.wtmax
        65536
        This is the maximum size in bytes of a WRITE request supported by the NFS gateway. If you change this, make sure you also update the nfs mount's wsize(add wsize= # of bytes to the mount directive).
    
    
        nfs.exports.allowed.hosts
        * rw
        允许所有主机对文件有rw权限
    
    
  • 重启hadoop集群服务

  • 关闭本机的nfs以及rpcbind服务

  • 启动hadoop portmap和nfs3,需要root权限

    [root@master ~]# /home/hadoop/hadoop-2.7.3/sbin/hadoop-daemon.sh start portmap
    [root@master ~]# /home/hadoop/hadoop-2.7.3/sbin/hadoop-daemon.sh start nfs3
    
  • 查看本机挂载状况

    [root@master ~]# showmount -e localhost
    Export list for localhost:
    / *
    
    
  • 可以在其他未安装HDFS的机器上通过nfs挂载hdfs目录

    # mount -t nfs -o vers=3,proto=tcp 10.10.18.229:/ /mnt
    # ls /mnt/user
    hadoop  hive  spark
    
  • 测试速度
    大概每秒40M,感觉不理想

    [root@localhost brute_force]# time cp /mnt/shegong.txt .
    
    real    6m23.823s
    user    0m0.014s
    sys 0m23.255s
    [root@localhost brute_force]# du -msh /mnt/shegong.txt 
    15G /mnt/shegong.txt
    [root@localhost brute_force]# du -msh /mnt/shegong.txt ./shegong.txt 
    15G /mnt/shegong.txt
    15G ./shegong.txt
    
    

你可能感兴趣的:(通过NFS将HDFS映射到本地文件系统)