ambari rest api (修改集群配置文件)

Posted 大葱拌豆腐

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ambari rest api (修改集群配置文件)相关的知识,希望对你有一定的参考价值。

1.找到你需要修改的配置的最新版本

curl -u admin:admin -H "X-Requested-By: ambari" -X GET  http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs
 
Sample OUTPUT
{
  "href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME?fields=Clusters/desired_configs",
  "Clusters" : {
    "cluster_name" : "CLUSTER_NAME",
    "version" : "HDP-2.0.6",
    "desired_configs" : {
      ...
      "mapred-site" : {
        "user" : "admin",
        "tag" : "version1384716039631"
      }
      ...
    }
  }
}

2.用正确的“tag”读取配置类型

curl -u admin:admin -H "X-Requested-By: ambari" -X GET "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631"
 
Sample OUTPUT
{
  "href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631",
  "items" : [
    {
      "href" : "http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/configurations?type=mapred-site&tag=version1384716039631",
      "tag" : "version1384716039631",
      "type" : "mapred-site",
      "Config" : {
        "cluster_name" : "CLUSTER_NAME"
      },
      "properties" : {
      ... THESE ARE THE PROPERTY KEY-VALUE PAIRS ...
      }
    }]
}

注意:此处的tag=version1384716039631要换做第一步获取的最新的tag

3.把希望修改的部分保存为一个新的配置版本

curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d [{"Clusters":{
  "desired_config":[{
    "type":"zoo.cfg",
    "tag":"version1480557385509",
    "properties":{
      "autopurge.purgeInterval":"24",
      "autopurge.snapRetainCount":"30",
      "dataDir":"/hadoop/zookeeper",
      "tickTime":"2000",
      "initLimit":"11",
      "syncLimit":"5",
      "clientPort":"2181"},
    "service_config_version_note":"New config version"}]}}]‘
"http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME"

注意:要确保用一个独一无二的tag,建议使用version+时间戳

4.重启所有组件或者服务让修改的配置立即生效

curl --user admin:admin -i -X PUT -d {"RequestInfo": {"context": "Stop HDFS"}, "ServiceInfo": {"state": "INSTALLED"}} http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS
curl --user admin:admin -i -X PUT -d {"RequestInfo": {"context": "Start HDFS"}, "ServiceInfo": {"state": "STARTED"}} http://AMBARI_SERVER_HOST:8080/api/v1/clusters/CLUSTER_NAME/services/HDFS

 

以上是关于ambari rest api (修改集群配置文件)的主要内容,如果未能解决你的问题,请参考以下文章

怎么修改ambari中的hadoop配置文件

Ambari-Server Rest API处理2(Ambari-Server通过Rest API进行服务安装部署操作流程+操作源码分析)

ambari rest api

同步 Ambari 集群配置

我们可以在现有集群中将 ambari 配置为非 root 用户吗

如何将主机添加到 ambari-server 集群中?