-
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
<property> <name>hadoop.proxyuser.nfsserver.groups</name> <value>*</value> <description>允许所有用户组用户代理</description> </property> <property> <name>hadoop.proxyuser.nfsserver.hosts</name> <value>localhost</value> <description>允许挂载的主机域名</description> </property> </property>
-
修改hdfs-site.xml
<property> <name>nfs.dump.dir</name> <value>/tmp/.hdfs-nfs</value> </property> <property> <name>nfs.rtmax</name> <value>1048576</value> <description>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).</description> </property> <property> <name>nfs.wtmax</name> <value>65536</value> <description>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).</description> </property> <property> <name>nfs.exports.allowed.hosts</name> <value>* rw</value> <description>允许所有主机对文件有rw权限</description> </property>
-
重启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
网友评论