使用REST API删除Ambari服务

问题描述:

将原有HDFS集群升级为HA集群是,发生了个小插曲,在一个节点,因操作失误,额外安装了NameNode和ZKFC,HA安装过程中最后一步强制退出,导致Secondary NameNode未被删除。

集群规划:

角色
目的
node1
ActiveNameNode,Secondary-NameNode,DataNode,ZKFC,JournalNode
删除Secondary-NameNode
node2
StandByNameNode,DataNode,ZKFC,JournalNode
node3
额外安装的NameNode,DataNode,额外安装的ZKFC,JournalNode
删除NameNode,ZKFC

在Web页面上,无法删除NameNode、ZKFC、SNameNode,只有Move操作,无法删除

所以只能通过其他的方式删除服务

Ambari Web页面显示信息如下:



so,今天就来说一下如何使用Ambari的REST API删除服务

Ambari 借鉴了很多成熟分布式软件的 API 设计

Rest API 就是一个很好地体现,通过 Ambari 的 Rest API,可以在脚本中通过 curl 维护整个集群

并且,我们可以用Rest API 实现一些无法在 Ambari Web页面上面做的操作

下面,就用实例来演示一下Ambari的REST API使用

1.查看在node1上的Secondary-Namenode信息

 curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://node1:8080/api/v1/clusters/insightcredit/hosts/node1/host_components/SECONDARY_NAMENODE
{
  "href" : "http://node1:8080/api/v1/clusters/insightcredit/hosts/ai-main/host_components/SECONDARY_NAMENODE",
  "HostRoles" : {
    "cluster_name" : "insightcredit",
    "component_name" : "SECONDARY_NAMENODE",
    "desired_stack_id" : "HDP-2.6",
    "desired_state" : "INSTALLED",
    "display_name" : "SNameNode",
    "hdp_version" : "HDP-2.6.2.0",
    "host_name" : "ai-main",
    "maintenance_state" : "ON",
    "public_host_name" : "ai-main",
    "service_name" : "HDFS",
    "stack_id" : "HDP-2.6",
    "stale_configs" : true,
    "state" : "INSTALLED",
    "upgrade_state" : "NONE",
   },
  "host" : {
    "href" : "http://node1:8080/api/v1/clusters/insightcredit/hosts/node1"
  },
  "processes" : [ ],
  "component" : [
    {
      "href" : "http://node1:8080/api/v1/clusters/insightcredit/services/HDFS/components/SECONDARY_NAMENODE",
      "ServiceComponentInfo" : {
        "cluster_name" : "insightcredit",
        "component_name" : "SECONDARY_NAMENODE",
        "service_name" : "HDFS"
      }
    }
  ]

注意:在执行的curl语句中有几点需要注意

curl -u admin:admin -H “X-Requested-By: ambari” -X GET http://node1:8080/api/v1/clusters/insightcredit/hosts/node1/host_components/SECONDARY_NAMENODE

admin:admin            Ambari的用户名和密码

http://node1:8080    Ambari的IP和端口

/api/v1/clusters/insightcredit    cluster name,即安装集群时定义的集群名称

hosts/node1            查询的节点

host_components        获取指定节点安装的服务

SECONDARY_NAMENODE        查询的服务名(如果不指定服务名,可获取该节点所有服务列表)


删除Secondary-Namenode

curl -u admin:admin -H "X-Requested-By: ambari" -X DELETE http://node1:8080/api/v1/clusters/insightcredit/hosts/node1/host_components/SECONDARY_NAMENODE

再次使用刚才的查询,404,已经不存在了,说明Secondary-Namenode删除成功

curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://node1:8080/api/v1/clusters/insightcredit/hosts/node1/host_components/SECONDARY_NAMENODE
{
  "status" : 404,
  "message" : "The requested resource doesn't exist: ServiceComponentHost not found, clusterName=insightcredit, serviceName=HDFS, serviceComponentName=SECONDARY_NAMENODE, hostName=node1"
}

2.删除node3的ZKFC:

先查询node3上ZKFC相关信息

curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/ZKFC
{
  "href" : "http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/ZKFC",
  "HostRoles" : {
    "cluster_name" : "insightcredit",
    "component_name" : "ZKFC",
    "desired_admin_state" : "INSERVICE",
    "desired_stack_id" : "HDP-2.6",
    "desired_state" : "STARTED",
    "display_name" : "ZKFailoverController",
    "hdp_version" : "HDP-2.6.2.0",
    "host_name" : "node3",
    "maintenance_state" : "OFF",
    "public_host_name" : "node3",
    "service_name" : "HDFS",
    "stack_id" : "HDP-2.6",
    "stale_configs" : false,
    "state" : "INSTALLED",
    "upgrade_state" : "NONE",
    "actual_configs" : { }
  },
  "host" : {
    "href" : "http://node1:8080/api/v1/clusters/insightcredit/hosts/node3"
  },
  "component" : [
    {
      "href" : "http://node1:8080/api/v1/clusters/insightcredit/services/HDFS/components/ZKFC",
      "ServiceComponentInfo" : {
        "cluster_name" : "insightcredit",
        "component_name" : "ZKFC",
        "service_name" : "HDFS"
      }
    }
  ],
  "processes" : [ ] }

执行删除语句:

 curl -u admin:admin -H "X-Requested-By: ambari" -X DELETE http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/ZKFC

再次查询,404找不到,ZKFC已经删除

curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/ZKFC
{
  "status" : 404,
  "message" : "The requested resource doesn't exist: ServiceComponentHost not found, clusterName=insightcredit, serviceName=HDFS, serviceComponentName=ZKFC, hostName=node3"
}

3.同上,删除NameNode

先进行查询

curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/NAMENODE
{
  "href" : "http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/NAMENODE",
  "HostRoles" : {
    "cluster_name" : "insightcredit",
    "component_name" : "NAMENODE",
    "desired_stack_id" : "HDP-2.6",
    "desired_state" : "STARTED",
    "display_name" : "NameNode",
    "hdp_version" : "HDP-2.6.2.0",
    "host_name" : "node3",
    "maintenance_state" : "OFF",
    "public_host_name" : "node3",
    "service_name" : "HDFS",
    "stack_id" : "HDP-2.6",
    "stale_configs" : false,
    "state" : "INSTALLED",
    "upgrade_state" : "NONE",
    "actual_configs" : { }
  },
  "host" : {
    "href" : "http://node1:8080/api/v1/clusters/insightcredit/hosts/node3"
  },
  "processes" : [ ],
  "component" : [
    {
      "href" : "http://node1:8080/api/v1/clusters/insightcredit/services/HDFS/components/NAMENODE",
      "ServiceComponentInfo" : {
        "cluster_name" : "insightcredit",
        "component_name" : "NAMENODE",
        "service_name" : "HDFS"
      }
    }
  ]

删除NameNode

curl -u admin:admin -H "X-Requested-By: ambari" -X DELETE  http://node1:8080/api/v1/clusters/insightcredit/hosts/node3/host_components/NAMENODE

再次查询,404找不到,NameNode已经删除

[root@ai-main 2.6.0.3-8]# curl -u admin:admin -H "X-Requested-By: ambari" -X GET http://ai-main:8080/api/v1/clusters/insightcredit/hosts/ai-node4/host_components/NAMENODE
{
  "status" : 404,
  "message" : "The requested resource doesn't exist: ServiceComponentHost not found, clusterName=insightcredit, serviceName=HDFS, serviceComponentName=NAMENODE, hostName=ai-node4"
}

回到Web页面上进行查看

node1的Secondary NameNode

node3的NameNode、ZKFC已经删除

集群恢复正常,问题解决。

赫墨拉

我是一个喜爱大数据的小菜鸡,这里是我分享我的成长和经历的博客

1 Response

  1. Josephmer说道:

    kdjx psi tracking

发表评论

邮箱地址不会被公开。