一、情景描述
需求1:
default隊列占總內存的40%,最大資源容量占總資源60%,hive隊列占總內存的60%,最大資源容量占總資源80%。
二、多隊列優點
(1)因為擔心員工不小心,寫遞歸死循環代碼,把所有資源全部耗盡
。
(2)實現任務的降級
使用,特殊時期保證重要的任務隊列資源充足。
三、多隊列配置
capacity-scheduler.xml
<!-- 指定多隊列,增加hive隊列 -->
<property><name>yarn.scheduler.capacity.root.queues</name><value>default,hive</value><description>The queues at the this level (root is the root queue).</description>
</property><!-- 降低default隊列資源額定容量為40%,默認100% -->
<property><name>yarn.scheduler.capacity.root.default.capacity</name><value>40</value>
</property><!-- 降低default隊列資源最大容量為60%,默認100% -->
<property><name>yarn.scheduler.capacity.root.default.maximum-capacity</name><value>60</value>
</property>
為hive
隊列添加必要屬性:
都是yarn.scheduler.capacity.root.hive
下的配置
<!-- 指定hive隊列的資源額定容量 -->
<property><name>yarn.scheduler.capacity.root.hive.capacity</name><value>60</value>
</property><!-- 用戶最多可以使用隊列多少資源,1表示 -->
<property><name>yarn.scheduler.capacity.root.hive.user-limit-factor</name><value>1</value>
</property><!-- 指定hive隊列的資源最大容量 -->
<property><name>yarn.scheduler.capacity.root.hive.maximum-capacity</name><value>80</value>
</property><!-- 啟動hive隊列 -->
<property><name>yarn.scheduler.capacity.root.hive.state</name><value>RUNNING</value>
</property><!-- 哪些用戶有權向隊列提交作業 -->
<property><name>yarn.scheduler.capacity.root.hive.acl_submit_applications</name><value>*</value>
</property><!-- 哪些用戶有權操作隊列,管理員權限(查看/殺死) -->
<property><name>yarn.scheduler.capacity.root.hive.acl_administer_queue</name><value>*</value>
</property><!-- 哪些用戶有權配置提交任務優先級 -->
<property><name>yarn.scheduler.capacity.root.hive.acl_application_max_priority</name><value>*</value>
</property><!-- 任務的超時時間設置:yarn application -appId appId -updateLifetime Timeout
參考資料:https://blog.cloudera.com/enforcing-application-lifetime-slas-yarn/ --><!-- 如果application指定了超時時間,則提交到該隊列的application能夠指定的最大超時時間不能超過該值。
-->
<property><name>yarn.scheduler.capacity.root.hive.maximum-application-lifetime</name><value>-1</value>
</property><!-- 如果application沒指定超時時間,則用default-application-lifetime作為默認值 -->
<property><name>yarn.scheduler.capacity.root.hive.default-application-lifetime</name><value>-1</value>
</property>
命令方式指定任務的運行時間
yarn application -appId appId -updateLifetime Timeout
四、更新配置到服務器
上傳capacity-scheduler.xml到102,然后,用xsync
同步腳本同步到103,104.
102上:yarn rmadmin -refreshQueues
五、執行任務
1、命令方式
指定任務隊列
hadoop jar share/hadoop/mapreduce/hadoop-mapreduce-examples-3.1.3.jar wordcount -D mapreduce.job.queuename=hive /input /output1
2、Java
代碼中指定任務隊列
public class WcDrvier {public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {Configuration conf = new Configuration();conf.set("mapreduce.job.queuename","hive");//1. 獲取一個Job實例Job job = Job.getInstance(conf);。。。 。。。//6. 提交Jobboolean b = job.waitForCompletion(true);System.exit(b ? 0 : 1);}
}