hadoop作业提交时可以指定相应的队列,例如:-Dmapred.job.queue.name=queue2
通过对mapred-queue-acls.xml和mapred-site.xml配置可以对不同的队列实现不同用户的提交权限.
先编辑mapred-site.xml,修改配置如下(增加四个队列):

 
  
  1. <property> 
  2.   <name>mapred.queue.names</name> 
  3.   <value>default,queue1,queue2,queue3,queue4</value> 
  4.   <description> Comma separated list of queues configured for this jobtracker. 
  5.     Jobs are added to queues and schedulers can configure different  
  6.     scheduling properties for the various queues. To configure a property  
  7.     for a queue, the name of the queue must match the name specified in this  
  8.     value. Queue properties that are common to all schedulers are configured  
  9.     here with the naming convention, mapred.queue.$QUEUE-NAME.$PROPERTY-NAME, 
  10.     for e.g. mapred.queue.default.submit-job-acl. 
  11.     The number of queues configured in this parameter could depend on the 
  12.     type of scheduler being used, as specified in  
  13.     mapred.jobtracker.taskScheduler. For example, the JobQueueTaskScheduler 
  14.     supports only a single queue, which is the default configured here. 
  15.     Before adding more queues, ensure that the scheduler you've configured 
  16.     supports multiple queues. 
  17.   </description> 
  18. </property> 

修改生效后通过jobtrack界面可以看到配置的队列信息:

要对队列进行控制, 还需要编辑mapred-queue-acls.xml文件

 
  
  1. <property> 
  2.   <name>mapred.queue.queue1.acl-submit-job</name> 
  3.   <value>' '</value> 
  4.   <description> Comma separated list of user and group names that are allowed 
  5.    to submit jobs to the 'default' queue. The user list and the group list 
  6.    are separated by a blank. For e.g. user1,user2 group1,group2. 
  7.    If set to the special value '*', it means all users are allowed to 
  8.    submit jobs. If set to ' '(i.e. space), no user will be allowed to submit 
  9.    jobs. 
  10.  
  11.    It is only used if authorization is enabled in Map/Reduce by setting the 
  12.    configuration property mapred.acls.enabled to true. 
  13.    Irrespective of this ACL configuration, the user who started the cluster and 
  14.    cluster administrators configured via 
  15.    mapreduce.cluster.administrators can submit jobs. 
  16.   </description> 
  17. </property> 

  要配置多个队列, 只需要重复添加上面配置信息,修改队列名称和value值,为方便测试,queue1禁止所有用户向其提交作业. 
   要使该配置生效, 还需要修改mapred-site.xml,将mapred.acls.enabled值设置为true

 
  
  1. <property> 
  2.   <name>mapred.acls.enabled</name> 
  3.   <value>true</value> 
  4.   <description> Specifies whether ACLs should be checked 
  5.     for authorization of users for doing various queue and job level operations. 
  6.     ACLs are disabled by default. If enabled, access control checks are made by 
  7.     JobTracker and TaskTracker when requests are made by users for queue 
  8.     operations like submit job to a queue and kill a job in the queue and job 
  9.     operations like viewing the job-details (See mapreduce.job.acl-view-job) 
  10.     or for modifying the job (See mapreduce.job.acl-modify-job) using 
  11.     Map/Reduce APIs, RPCs or via the console and web user interfaces. 
  12.   </description> 
  13. </property> 

 重启hadoop, 使配置生效, 接下来拿hive进行测试:
先使用queue2队列:

 
  
  1. set mapred.job.queue.name=queue2
  2. hive>  
  3.     > select count(*) from t_aa_pc_log; 
  4. Total MapReduce jobs = 1 
  5. Launching Job 1 out of 1 
  6. Number of reduce tasks determined at compile time: 1 
  7. In order to change the average load for a reducer (in bytes): 
  8.   set hive.exec.reducers.bytes.per.reducer=<number> 
  9. In order to limit the maximum number of reducers: 
  10.   set hive.exec.reducers.max=<number> 
  11. In order to set a constant number of reducers: 
  12.   set mapred.reduce.tasks=<number> 
  13. Starting Job = job_201205211843_0002, Tracking URL = http://192.168.189.128:50030/jobdetails.jsp?jobid=job_201205211843_0002 
  14. Kill Command = /opt/app/hadoop-0.20.2-cdh3u3/bin/hadoop job  -Dmapred.job.tracker=192.168.189.128:9020 -kill job_201205211843_0002 
  15. 2012-05-21 18:45:01,593 Stage-1 map = 0%,  reduce = 0
  16. 2012-05-21 18:45:04,613 Stage-1 map = 100%,  reduce = 0
  17. 2012-05-21 18:45:12,695 Stage-1 map = 100%,  reduce = 100
  18. Ended Job = job_201205211843_0002 
  19. OK 
  20. 136003 
  21. Time taken: 14.674 seconds 
  22. hive>  

 作业成功完成

再来向queue1队列提交作业:

 
  
  1.     > set mapred.job.queue.name=queue1
  2. hive> select count(*) from t_aa_pc_log; 
  3. Total MapReduce jobs = 1 
  4. Launching Job 1 out of 1 
  5. Number of reduce tasks determined at compile time: 1 
  6. In order to change the average load for a reducer (in bytes): 
  7.   set hive.exec.reducers.bytes.per.reducer=<number> 
  8. In order to limit the maximum number of reducers: 
  9.   set hive.exec.reducers.max=<number> 
  10. In order to set a constant number of reducers: 
  11.   set mapred.reduce.tasks=<number> 
  12. org.apache.hadoop.ipc.RemoteException: org.apache.hadoop.security.AccessControlException: User p_sdo_data_01 cannot perform operation SUBMIT_JOB on queue queue1. 
  13.  Please run "hadoop queue -showacls" command to find the queues you have access to . 
  14.     at org.apache.hadoop.mapred.ACLsManager.checkAccess(ACLsManager.java:179) 
  15.     at org.apache.hadoop.mapred.ACLsManager.checkAccess(ACLsManager.java:136) 
  16.     at org.apache.hadoop.mapred.ACLsManager.checkAccess(ACLsManager.java:113) 
  17.     at org.apache.hadoop.mapred.JobTracker.submitJob(JobTracker.java:3781) 
  18.     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
  19.     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
  20.     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
  21.     at java.lang.reflect.Method.invoke(Method.java:597) 
  22.     at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:557) 
  23.     at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1434) 
  24.     at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:1430) 
  25.     at java.security.AccessController.doPrivileged(Native Method) 
  26.     at javax.security.auth.Subject.doAs(Subject.java:396) 
  27.     at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1157) 
  28.     at org.apache.hadoop.ipc.Server$Handler.run(Server.java:1428) 

作业提交失败!

最后, 可以使用 hadoop queue -showacls 命令查看队列信息:

 
  
  1. [hadoop@localhost conf]$ hadoop queue -showacls 
  2. Queue acls for user :  hadoop 
  3.  
  4. Queue  Operations 
  5. ===================== 
  6. queue1  administer-jobs 
  7. queue2  submit-job,administer-jobs 
  8. queue3  submit-job,administer-jobs 
  9. queue4  submit-job,administer-jobs