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
原文地址:https://www.cnblogs.com/itboys/p/7003872.html