Ambari-Rest-API

本文记录了一些Ambari常用的Rest API。

查看服务状态

1
2
3
4
查看所有服务信息:(注意服务名大写)
curl -u admin:$PASSWORD -H "X-Requested-By: ambari" -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services
查看某个服务的信息:
curl -u admin:$PASSWORD -H "X-Requested-By: ambari" -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE_NAME

停止服务

1
curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X PUT -d '{"RequestInfo": {"context" :"Stop Service"}, "Body": {"ServiceInfo": {"state": "INSTALLED"}}}' http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE_NAME

删除服务

1
2
3
4
删除某服务
curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X DELETE http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE_NAME
删除某节点上服务组件:
curl -u admin:$PASSWORD -i -H 'X-Requested-By: ambari' -X DELETE http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$HOST_NAME/host_components/$COMPONENT_NAME

添加服务

1
2
添加某个服务的组件:
curl -u admin:$PASSWORD -H "X-Requested-By:ambari" -X POST "http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/hosts/$HOST_NAME/host_components/$COMPONENT_NAME"

获取服务在节点信息

1
curl -u admin:$PASSWORD -H "X-Requested-By: ambari" -X GET http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services/$SERVICE_NAME/components/$COMPONENT_NAME 2>/dev/null |grep "host_name"

启动所有服务

1
curl -u admin:$PASSWORD -i -H "X-Requested-By:ambari" -X PUT -d '{"ServiceInfo": {"state" : "STARTED"}}' http://$AMBARI_HOST:8080/api/v1/clusters/$CLUSTER_NAME/services
Kyle Joe wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!