zoukankan      html  css  js  c++  java
  • HADOOP操作权限问题

    hdfs的权限判断十分简单,就是拿发出指令的user name和文件的user name 做比较
      private void check(INode inode, FsAction access
          ) throws AccessControlException {
        if (inode == null) {
          return;
        }
        FsPermission mode = inode.getFsPermission();
     
        if (user.equals(inode.getUserName())) { //user class
          if (mode.getUserAction().implies(access)) { return; }
        }
        else if (groups.contains(inode.getGroupName())) { //group class
          if (mode.getGroupAction().implies(access)) { return; }
        }
        else { //other class
          if (mode.getOtherAction().implies(access)) { return; }
        }
        throw new AccessControlException("Permission denied: user=" + user
            + ", access=" + access + ", inode=" + inode);
      }
    }
     
    在多用户提交任务时遇到Permission denied, 的原因和任务提交的过程有关。
    1. 首先提交任务的客户端会把任务相关文件打包放在hadoop.tmp.dir中,这是本地目录,需要通过本地系统权限验证。由于是临时目录直接设置成为777就行.
    2.  客户端会将任务文件打包写入hdfs的mapreduce.jobtracker.staging.root.dir + "/" + user + "/.staging" 目录,需要经过hdfs权限验证。通常可以选择两种方法解决。
    1) 保持mapreduce.jobtracker.staging.root.dir为默认,将此目录chmod 777
    2) 在hdfs的/user目录下建立用户目录,并且chown为该用户,相当于在hdfs下创建一个用户。
    然后设置mapreduce.jobtracker.staging.root.dir为/user,  这是官方推荐的,可以看到这个属性的描述是这样写的:
    The root of the staging area for users' job files In practice, this should be the directory where users' home directories are located (usually /user)。
    3)有人说可以在启动任务时加入hadoop.job.ugi属性指定用户和群组。 我验证这样不行。看源码里也是直接获取
    ugi = UserGroupInformation.getCurrentUser();不过看hdfs权限策略这操行应该可以设置。
     
    还有一些如设置dfs.permissions参数关闭权限校验,改源码直接不校验之类的。。。
     
    最后要注意,任务的out put需要当前用户拥有权限,不然还是不成功。设置成为用户目录就好了
     
    另外,关于/tmp目录也要注意:
     ERROR org.apache.pig.impl.io.FileLocalizer - org.apache.hadoop.security.AccessControlException: org.apache.hadoop.security.AccessControlException: Permission denied: user=shashaa, access=WRITE, inode="tmp":pwang7:supergroup:rwxr-xr-x
     碰到这种情况,当然是使用chmod把tmp目录的权限改为777了。
     
    关于mapreduce.jobtracker.staging.root.dir
    ParameterValueDescription
    mapred.system.dir /var/mapr/cluster/mapred/jobTracker/system The shared directory where MapReduce stores control files.
    mapred.job.tracker.persist.jobstatus.dir /var/mapr/cluster/mapred/jobTracker/jobsInfo The directory where the job status information is persisted in a file system to be available after it drops of the memory queue and between jobtracker restarts.
    mapreduce.jobtracker.staging.root.dir /var/mapr/cluster/mapred/jobTracker/staging The root of the staging area for users' job files In practice, this should be the directory where users' home directories are located (usually /user)
    启动hadoop hdfs系统的用户即为超级用户,可以进行任意的操作。
     
    如想让leaf用户也可执行hadoop的作业,执行如下操作:
     
    用超级用户hadoop,创建文件    hadoop fs -mkdir /user/leaf
     
    使用hadoop fs -chown 以及-chgrp 命令改变该文件的用户和用户组权限为leaf
     
    在配置文件hdfs-site-xml 中添加项  dfs.permissions.enabled的值为 true
     
    要保证leaf这个用户几个节点能ssh无密码相互登录,java环境变量没问题
     
    这样leaf用户就可以提交任务数据到HDFS的/user/leaf目录中,并且可执行hadoop任务,
    意如果不修改staging,任务仍旧无法提交,虽然这时候可以对hdfs的/user/leaf目录进行操作
  • 相关阅读:
    【SICP练习】80 练习2.52
    【SICP练习】79 练习2.51
    【SICP练习】78 练习2.50
    【SICP练习】77 练习2.48-2.49
    【SICP练习】76 练习2.47
    【SICP练习】75 练习2.46
    【SICP练习】74 练习2.45
    【SICP练习】73 练习2.44
    【SICP练习】72 练习2.43
    【SICP练习】71 练习2.42
  • 原文地址:https://www.cnblogs.com/OnTheWay-0518/p/9679708.html
Copyright © 2011-2022 走看看