Ambari+HDP通过脚本设置yarn执行计划

1.背景

我们都知道CDH带有设置yarn执行计划的功能:

通过这个功能,能方便我们充分使用集群的计算资源(一般白天和夜间采用不同的策略)。

但是ambari+HDP集群没有这个功能,但是我们还是想要他具有切换yarn资源池队列大小的计划功能,应该如何去做。

2.做法:

2.1.首先在ambari上进行设置(设置好后先不要点刷新并保存):

修改完后,“Actions”变成黄色,提示需要进行保存和刷新才能生效。

2.2.打开F12,进入web控制台,点击“Fetch/XHR”,观察点击保存并刷新后,ambari发送的接口:

2.3.点击Actions下的“Save and Refresh Queues”按钮,我们需要查询一个配置信息,我们找到“configuration”接口,按下图所示的方式进行点击,找到一大串的json串

 这个json串里面包含了我们设置yarn执行计划所需的队列资源大小设置的相关配置,我们把这个大串的json拷贝出来,后面要用。

2.4.套用shell脚本

2.4.1.先观察一下上一步获取的大串json的内容,因为有一处需要更改才能使用:

上图中,红框里面的tag的值,每次使用,都需要改变才行,所以我们后面需要通过代码将这个值改变之后,进行使用。

2.4.2.套用shell脚本

#!/bin/bash

# 生成 json 中不断变化的 tag 的值
current=`date "+%Y-%m-%d %H:%M:%S"`
timeStamp=`date -d "$current" +%s`
currentTimeStamp=$((timeStamp*1000+`date "+%N"`/1000000))
# 填写 ambari 的集群的相关信息
ambariuser="admin"
ambaripassword="admin"
ambarihost="xxxxxxx"

# 更改队列配置请求
# 将 tag 带入到 json 中,发送请求,注意需要设置好集群的 ambari 用户名和密码
curl -u $ambariuser:$ambaripassword -H "X-Requested-By: ambari" -X PUT -d '[{
    "Clusters":{
        "desired_config":[
            {
                "type":"capacity-scheduler",
                "tag":"'"${currentTimeStamp}"'",
                "service_config_version_note":"",
                "properties":{
                    "yarn.scheduler.capacity.maximum-am-resource-percent":0.2,
                    "yarn.scheduler.capacity.maximum-applications":10000,
                    "yarn.scheduler.capacity.node-locality-delay":40,
                    "yarn.scheduler.capacity.resource-calculator":"org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator",
                    "yarn.scheduler.capacity.queue-mappings-override.enable":false,
                    "yarn.scheduler.capacity.root.acl_administer_queue":"*",
                    "yarn.scheduler.capacity.root.acl_submit_applications":"*",
                    "yarn.scheduler.capacity.root.capacity":100,
                    "yarn.scheduler.capacity.root.queues":"ai,default",
                    "yarn.scheduler.capacity.root.priority":0,
                    "yarn.scheduler.capacity.root.accessible-node-labels":"*",
                    "yarn.scheduler.capacity.root.ai.acl_administer_queue":"*",
                    "yarn.scheduler.capacity.root.ai.acl_submit_applications":"*",
                    "yarn.scheduler.capacity.root.ai.minimum-user-limit-percent":100,
                    "yarn.scheduler.capacity.root.ai.maximum-capacity":70,
                    "yarn.scheduler.capacity.root.ai.user-limit-factor":1,
                    "yarn.scheduler.capacity.root.ai.state":"RUNNING",
                    "yarn.scheduler.capacity.root.ai.capacity":50,
                    "yarn.scheduler.capacity.root.ai.queues":"offline,online",
                    "yarn.scheduler.capacity.root.ai.priority":0,
                    "yarn.scheduler.capacity.root.ai.offline.acl_administer_queue":"*",
                    "yarn.scheduler.capacity.root.ai.offline.acl_submit_applications":"*",
                    "yarn.scheduler.capacity.root.ai.offline.minimum-user-limit-percent":100,
                    "yarn.scheduler.capacity.root.ai.offline.maximum-capacity":60,
                    "yarn.scheduler.capacity.root.ai.offline.user-limit-factor":1,
                    "yarn.scheduler.capacity.root.ai.offline.state":"RUNNING",
                    "yarn.scheduler.capacity.root.ai.offline.capacity":60,
                    "yarn.scheduler.capacity.root.ai.offline.ordering-policy":"fifo",
                    "yarn.scheduler.capacity.root.ai.offline.priority":0,
                    "yarn.scheduler.capacity.root.ai.online.acl_administer_queue":"*",
                    "yarn.scheduler.capacity.root.ai.online.acl_submit_applications":"*",
                    "yarn.scheduler.capacity.root.ai.online.minimum-user-limit-percent":100,
                    "yarn.scheduler.capacity.root.ai.online.maximum-capacity":40,
                    "yarn.scheduler.capacity.root.ai.online.user-limit-factor":1,
                    "yarn.scheduler.capacity.root.ai.online.state":"RUNNING",
                    "yarn.scheduler.capacity.root.ai.online.capacity":40,
                    "yarn.scheduler.capacity.root.ai.online.ordering-policy":"fifo",
                    "yarn.scheduler.capacity.root.ai.online.priority":0,
                    "yarn.scheduler.capacity.root.default.acl_submit_applications":"*",
                    "yarn.scheduler.capacity.root.default.maximum-capacity":70,
                    "yarn.scheduler.capacity.root.default.user-limit-factor":1,
                    "yarn.scheduler.capacity.root.default.state":"RUNNING",
                    "yarn.scheduler.capacity.root.default.capacity":50,
                    "yarn.scheduler.capacity.root.default.priority":0
                }
            }
        ]
    }
}]' "http://${ambarihost}:8080/api/v1/clusters/sg_bigdata"
# 睡3秒
sleep 3
# 刷新队列
# 刷新方式1
curl -u $ambariuser:$ambaripassword -H 'Content-Type:application/json' -H 'X-Requested-By:ambari' -iX PUT -d '{"save": "true"}' "http://${ambarihost}:8080/api/v1/views/CAPACITY-SCHEDULER/versions/1.0.0/instances/AUTO_CS_INSTANCE/resources/scheduler/configuration/saveAndRefresh"

# 刷新方式2 方式2需要将 RESOURCEMANAGER 的 hosts 替换到 xxxxx 处
# 不推荐方式2,因为方式2需要填写 RESOURCEMANAGER 的 hosts 信息,并不方便
# curl -u $ambariuser:$ambaripassword -H 'Content-Type:application/json' -H 'X-Requested-By:ambari' -iX POST -d '{"RequestInfo":{"command":"REFRESHQUEUES","context":"Refresh YARN Capacity Scheduler","operation_level":{"level":"HOST_COMPONENT","cluster_name":"sg_bigdata"},"parameters/forceRefreshConfigTags":"capacity-scheduler"},"Requests/resource_filters":[{"service_name":"YARN","component_name":"RESOURCEMANAGER","hosts":"xxxxxx"}]}' "http://${ambarihost}:8080/api/v1/clusters/sg_bigdata/requests"

 3.按照“第2步”的方式,创建出其他资源池配置的脚本,在linux的crontab中,或者自己公司的调度体统中定时执行,可以实现像CDH一样的yarn执行计划的功能。

参考资料:

Solved: How to add new yarn queue using Rest API / Ambari ... - Cloudera Community - 176989

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值