NFS挂载hdfs到本地

NFS挂载hdfs到本地

 

nfs hdfs nfs hdfs

hdfs挂载: hdfs是分布式系统,要想访问hdfs上的文件,可以用java api 或者hadoop shell等工具,如果想操作hdfs文件系统就像操作本地文件系统一样的便捷,可以将hdfs文件系统挂载到本地的一个目录上,那么挂载的方式有两种:

  • fuse 挂载:需要另外安装fuse工具,详细请参考: 
    http://duguyiren3476.iteye.com/blog/2054506
  • nfs挂载:apache hadoop2.x以后的版本中自带了一个nfs3的插件服务,下面将详细讲解nfs挂载的方式。 

 

测试环境

  • apache hadoop 2.5.2
  • jdk 1.7
  • ubuntu 14.04

NFS挂载hdfs

Markdown 是一种轻量级标记语言,它允许人们使用易读易写的纯文本格式编写文档,然后转换成格式丰富的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集群服务

root@localhost:/opt/hdfsnfs# /opt/work/hadoop/sbin/stop-all.sh

root@localhost:/opt/hdfsnfs# /opt/work/hadoop/sbin/stop-all.sh

以上启动,只需启动hdfs服务即可

关闭本机的nfs服务

centos关闭nfs服务

      service nfs stop
      service rpcbind stop

ubuntu关闭nfs服务

root@localhost:/opt/hdfsnfs# /etc/init.d/nfs-kernel-server stop
root@localhost:/opt/hdfsnfs# /etc/init.d/rpcbind stop

如果没有nfs服务则可略过

启动hadoop nfs

root@localhost:/opt/hdfsnfs# /opt/work/hadoop/sbin/hadoop-daemon.sh start portmap
root@localhost:/opt/hdfsnfs# /opt/work/hadoop/sbin/hadoop-daemon.sh start nfs3

停止服务

root@localhost:/opt/hdfsnfs# /opt/work/hadoop/sbin/hadoop-daemon.sh stop portmap
root@localhost:/opt/hdfsnfs# /opt/work/hadoop/sbin/hadoop-daemon.sh stop nfs3

查看本机挂载状况

root@localhost:/opt/hdfsnfs# showmount -e localhost
Export list for localhost:
/ *
root@localhost:/opt/hdfsnfs# 

上述的localhost是指第一步的core-site.xml中的hadoop.proxyuser.nfsserver.hosts的值 
如果出现上述的 / *说明服务启动成功

挂载到本地制定目录

root@localhost:~# mkdir -p /opt/hdfsnfs   #创建挂载的目标点
root@localhost:~# mount -t nfs -o vers=3,proto=tcp,nolock,noacl localhost:/  /opt/hdfsnfs/
root@localhost:~# ll /opt/hdfsnfs/
总用量 581
drwxr-xr-x 15 root      2584148964    480  57 17:49 ./
drwxr-xr-x 24 root      root         4096  57 17:44 ../
drwxr-xr-x  3 root      2584148964     96 1225 17:10 2014/
drwxr-xr-x  3 root      2584148964     96  29 16:55 2015/
drwxr-xr-x 10 root      2584148964    320  422 17:53 hbase/
drwxr-xr-x  3 root      2584148964     96  429 16:11 lib/
-rw-r--r--  1 root      2584148964 583045  57 18:00 lzo-2.06.tar.gz
drwxr-xr-x  4 root      2584148964    128  415 10:12 merge/
drwxr-xr-x  3 root      2584148964     96  415 10:26 opt/
drwxr-xr-x  4 root      2584148964    128  56 18:42 out/
drwxr-xr-x  3 root      2584148964     96  48 16:49 target/
drwxr-xr-x 27 root      2584148964    864  57 11:20 test/
drwx------ 18 root      2584148964    576  57 15:21 tmp/
drwxr-xr-x  3 root      2584148964     96  29 10:46 user/
drwxr-xr-x  3 146731693 2584148964     96  327 19:42 usr/
root@localhost:~# 

即可在本地查看hdfs上的所有文件

总结

fuse配置起来麻烦,hdfs的nfs配置方式相对简单,依赖的插件少,配置简单,当然里面的acl控制,hdfs的安全需要根据自己的业务进行配置

猜你喜欢

转载自duguyiren3476.iteye.com/blog/2209242