当前位置:   article > 正文

Ambari Rest API 管理集群_ambari api

ambari api

有时候因为网络端口活着其他限制原因,我们没办法直接访问ambari web ui的页面进行操作,这时候我们可以在能访问ambari server的linux服务器上执行curl命令来管理ambari集群
参考链接: https://github.com/apache/ambari/blob/trunk/ambari-server/docs/api/v1/index.md#resources.

  1. 获取集群名称
curl -u username:password -H "X-Requested-By: ambari" -X GET http://ip.ip.ip.ip:8080/api/v1/clusters
{
  "href" : "http://localhost:8080/api/v1/clusters",
  "items" : [
    {
      "href" : "http://localhost:8080/api/v1/clusters/c1",
      "Clusters" : {
        "cluster_name" : "c1"
      }
    }
  ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  1. 获取集群的所有服务
curl -u username:password -H "X-Requested-By: ambari" -X GET http://ip.ip.ip.ip:8080/api/v1/clusters/c1/services
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/services",
  "items" : [
  	......
    {
      "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/services/HBASE",
      "ServiceInfo" : {
        "cluster_name" : "c1",
        "service_name" : "HBASE"
      }
    },
    {
      "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/services/HDFS",
      "ServiceInfo" : {
        "cluster_name" : "c1",
        "service_name" : "HDFS"
      }
    },
    ......
  ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  1. 获取某个集群的所有主机
curl -u username:password -H "X-Requested-By: ambari" -X GET http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts
{
    "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts",
    "items" : [
      {
        "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01",
        "Hosts" : {
          "cluster_name" : "c1",
          "host_name" : "node-01"
        }
      },
      ......
    ]
  }
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  1. 获取某个主机上的所有组件
curl -u username:password -H "X-Requested-By: ambari" -X GET http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01/host_components
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01/host_components",
  "items" : [
    {
      "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01/host_components/HIVE_METASTORE",
      "HostRoles" : {
        "cluster_name" : "c1",
        "component_name" : "HIVE_METASTORE",
        "host_name" : "node-01"
      },
      "host" : {
        "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01"
      }
    },
    ......
  ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  1. 启停某个服务的所有组件
curl -u username:password -H "X-Requested-By: ambari" -X PUT http://ip.ip.ip.ip:8080/api/v1/clusters/c1/services/HDFS -d '{"RequestInfo":{"context":"Start HDFS Service"},"Body":{"ServiceInfo":{"state":"STARTED"}}}'
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/287",
  "Requests" : {
    "id" : 287,
    "status" : "Accepted"
  }
}
curl -u username:password -H "X-Requested-By: ambari" -X PUT http://ip.ip.ip.ip:8080/api/v1/clusters/c1/services/HDFS -d '{"RequestInfo":{"context":"Stop HDFS Service"},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}'
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/286",
  "Requests" : {
    "id" : 286,
    "status" : "Accepted"
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  1. 启停某个主机上的所有组件
curl -u username:password -H "X-Requested-By: ambari" -X PUT http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01/host_components -d '{"RequestInfo":{"context":"Start All Host Components"},"Body":{"HostRoles":{"state":"STARTED"}}}'
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/292",
  "Requests" : {
    "id" : 292,
    "status" : "Accepted"
  }
}
curl -u username:password -H "X-Requested-By: ambari" -X PUT http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node-01/host_components -d '{"RequestInfo":{"context":"Stop All Host Components"},"Body":{"HostRoles":{"state":"INSTALLED"}}}'
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/293",
  "Requests" : {
    "id" : 293,
    "status" : "Accepted"
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  1. 启停某个主机上的某个组件
curl -u username:password -H "X-Requested-By: ambari" -X PUT http://ip.ip.ip.ip:8080/api/v1/clusters/c1/osts/node1-02/host_components/DATANODE -d '{"RequestInfo":{"context":"Stop DATANODE"},"Body":{"HostRoles":{"state":"STARTED"}}}'
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/289",
  "Requests" : {
    "id" : 289,
    "status" : "Accepted"
  }
}
curl -u username:password -H "X-Requested-By: ambari" -X PUT http://ip.ip.ip.ip:8080/api/v1/clusters/c1/hosts/node1-02/host_components/DATANODE -d '{"RequestInfo":{"context":"Start DATANODE"},"Body":{"HostRoles":{"state":"INSTALLED"}}}'
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/288",
  "Requests" : {
    "id" : 288,
    "status" : "Accepted"
  }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  1. 检查操作进度
curl -u username:password -H "X-Requested-By: ambari" -X GET http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/287
{
  "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/287",
  "Requests" : {
    ......
    "request_context" : "Start HDFS Service",
    "request_status" : "COMPLETED",
    ......
  },
  "stages" : [
    {
      "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/287/stages/0",
      "Stage" : {
        "cluster_name" : "c1",
        "request_id" : 287,
        "stage_id" : 0
      }
    },
    ......
  ],
  "tasks" : [
    {
      "href" : "http://ip.ip.ip.ip:8080/api/v1/clusters/c1/requests/287/tasks/1574",
      "Tasks" : {
        "cluster_name" : "c1",
        "id" : 1574,
        "request_id" : 287,
        "stage_id" : 0
      }
    },
    ......
  ]
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家小花儿/article/detail/683613
推荐阅读
相关标签
  

闽ICP备14008679号