Hadoop HDFS NFS GateWay部署深入详解

目的:通过挂载的方式,可以类似访问本地磁盘的方式一样的访问Hadoop文件,简单、方便、快捷。

0.系统版本&hadoop版本
1)系统版本

[root@WEB-W031 sbin]# cat /etc/issue
CentOS release 5.8 (Final)

2)Hadoop版本

[root@WEB-W031 /]# hadoop version
Hadoop 2.7.2
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r b165c4fe8a74265c792ce23f546c64604acf0e41
Compiled by jenkins on 2016-01-26T00:08Z
Compiled with protoc 2.5.0
From source with checksum d0fda26633fa762bff87ec759ebe689c
This command was run using /home/hadoop/hadoop/share/hadoop/common/hadoop-common-2.7.2.jar
You have new mail in /var/spool/mail/root

1、配置Core-site.xml文件

<property>
  <name>hadoop.proxyuser.hadoop.groups</name>
  <value>*</value>
  <description>
         The 'nfsserver' user is allowed to proxy all members of the 'users-group1' and
         'users-group2' groups. Note that in most cases you will need to include the
         group "root" because the user "root" (which usually belonges to "root" group) will
         generally be the user that initially executes the mount on the NFS client system.
         Set this to '*' to allow nfsserver user to proxy any group.
  </description>
</property>

<property>
  <name>hadoop.proxyuser.hadoop.hosts</name>
  <value>*</value>
  <description>
         This is the host where the nfs gateway is running. Set this to '*' to allow
         requests from any hosts to be proxied.
  </description>

</property>

含义解读:
1)hadoop.proxyuser.hadoop.groups:第二个和执行Hadoop的用户名一致,本测试用的名称为Hadoop。
2)hadoop.proxyuser.hadoop.hosts:第二个和执行Hadoop的用户名一致,本测试用的名称为Hadoop。

2、配置hdfs-site.xml文件

     <property>
  <name>dfs.namenode.accesstime.precision</name>
  <value>3600000</value>
  <description>The access time for HDFS file is precise upto this value.
    The default value is 1 hour. Setting a value of 0 disables
    access times for HDFS.
  </description>
</property>

  <property>
    <name>nfs.dump.dir</name>
    <value>/tmp/.hdfs-nfs</value>
  </property>

<property>
  <name>nfs.exports.allowed.hosts</name>
  <value>* rw</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>

3、配置*/etc/hadoop/log4j.properties

 log4j.logger.org.apache.hadoop.hdfs.nfs=DEBUG
 log4j.logger.org.apache.hadoop.oncrpc=DEBUG

4、root用户下停止portmap(Centos 5.X系统),停止nfs


[root@WEB-W031 etc]# service portmap stop
Stopping portmap: [ OK ]
[root@WEB-W031 hadoop]# service nfs stop

注意:5.X的portmap 等价于 6.X上的rpcbind
并通过:service nfs status 验证是否已经结束。
并通过:service portmap status 验证是否已经结束。

5、开启Hadoop的Portmap服务(需要root权限)

[root]> /sbin/hadoop-daemon.sh –script /bin/hdfs start portmap

6、开启Hadoop的Nfs3服务(需要执行Hadoop的用户权限,本系统为Hadoop)

[hadoop]$ /sbin/hadoop-daemon.sh –script /bin/hdfs start nfs3

7、开启Hadoop并验证(需要执行Hadoop的用户权限,本系统为Hadoop)

[root@WEB-W031 sbin]# ./start-dfs.sh
[root@WEB-W031 sbin]# jps
14728 ResourceManager
27478 Jps
5228 Portmap
14104 NameNode
14373 SecondaryNameNode
16762 org.eclipse.equinox.launcher_1.3.0.v20130327-1440.jar
13512 Nfs3

8、验证NFS相关服务是否启动成功
1)验证各服务是否成功运行

[root@WEB-W031 hadoop]# rpcinfo -p $nfs_server_ip
program vers proto port
100005 2 tcp 4242 mountd
100000 2 udp 111 portmapper
100000 2 tcp 111 portmapper
100005 1 tcp 4242 mountd
100003 3 tcp 2049 nfs
100005 1 udp 4242 mountd
100005 3 udp 4242 mountd
100005 3 tcp 4242 mountd

2)显示挂载路径

[root@WEB-W031 hadoop]# showmount -e $nfs_server_ip
Export list for WEB-W031:
/ *

9、实施挂载

 [root]>mount -t nfs -o vers=3,proto=tcp,nolock,noacl,sync $10.0.1.31:/  /hdfsnew

10、查看挂载是否成功

[root@WEB-W031 hdfsnew]# ls -al
total 10
drwxr-xr-x  5 root   2584148964  160 Mar 11 09:43 .
drwxr-xr-x 31 root   root       4096 Mar 11 10:40 ..
drwxr-xr-x  3 root   root         96 Mar 11 09:58 testing
drwxrwx---  3 hadoop 2584148964   96 Mar  9 11:14 tmp
drwxr-xr-x  3 hadoop 2584148964   96 Mar  9 13:24 user
[root@WEB-W031 hdfsnew]# cd testing/
[root@WEB-W031 testing]# ls -al
total 2
drwxr-xr-x 3 root   root        96 Mar 11 09:58 .
drwxr-xr-x 5 root   2584148964 160 Mar 11 09:43 ..
-rw-rw-r-- 1 hadoop hadoop      18 Mar 11 10:08 dffafdadafasdfaf
[root@WEB-W031 testing]# echo  "testinglaoyang" > testlaoyang
[root@WEB-W031 testing]# ls -al
total 2
drwxr-xr-x 4 root   root       128 Mar 11 18:05 .
drwxr-xr-x 5 root   2584148964 160 Mar 11 09:43 ..
-rw-rw-r-- 1 hadoop hadoop      18 Mar 11 10:08 dffafdadafasdfaf
-rw-r--r-- 1 root   root        15 Mar 11 18:05 testlaoyang

11、访问效果
这里写图片描述

12、结束服务
1)NFS3服务结束(必须和启动hadoop用户一致)

[hadoop]$ */sbin/hadoop-daemon.sh --script */bin/hdfs stop nfs3

2)PortMap服务结束(必须为root用户)

[root]> */sbin/hadoop-daemon.sh --script */bin/hdfs start portmap

3)Hadoop结束(必须和启动hadoop用户一致)

“`
[hadoop@WEB-W031 sbin]# ./stop-dfs.sh

13、常见问题
java 进程 占用了111 端口
[root@WEB-W031 etc]# lsof -i:111
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 31206 root 474u IPv4 93384812 0t0 TCP *:sunrpc (LISTEN)
java 31206 root 476u IPv4 93384815 0t0 UDP *:sunrpc

解决方案:kill -9 31206

错误明细
[root@xx sbin]# mount -t nfs -o vers=3,proto=tcp,nolock,noacl,sync localhost:/ /hdfs_y
mount.nfs: Input/output error
注意:一定要注意配置文件的细节含义。
解决方案:
http://stackoverflow.com/questions/35910751/hdfs-nfs-gateway-mount-nfs-input-output-error/35935229#35935229

参考:
https://hadoop.apache.org/docs/r2.7.2/hadoop-project-dist/hadoop-hdfs/HdfsNfsGateway.html#Allow_mounts_from_unprivileged_clients
http://tianxingzhe.blog.51cto.com/3390077/1650182

作者:铭毅天下
转载请标明出处,原文地址:http://blog.csdn.net/laoyang360/article/details/50865025
如果感觉本文对您有帮助,请点击‘顶’支持一下,您的支持是我坚持写作最大的动力,谢谢!

©️2020 CSDN 皮肤主题: Age of Ai 设计师:meimeiellie 返回首页