以删除/api/v1/clusters/HDP/services/SAMPLESRV为例。 # 一、常规方法 ## 1.1 通过Web操作 - 先stop SAMPLESRV的所有服务。 - 再delete SAMPLESRV服务。 ## 1.2 通过REST API操作 先停止服务: ```bash curl -u admin:admin -H "X-Requested-By: ambari" -X PUT -d '{"RequestInfo": {"context":"Stop Service"},"Body":{"ServiceInfo":{"state":"INSTALLED"}}}' http://192.168.0.200:8080/api/v1/clusters/HDP/services/SAMPLESRV ``` 再删除服务: ```bash curl -u admin:admin -H "X-Requested-By: ambari" -X DELETE http://192.168.0.200:8080/api/v1/clusters/HDP/services/SAMPLESRV ``` 删除目录: ```bash rm -rf /var/lib/ambari-server/resources/stacks/HDP/3.1/services/SAMPLESRV ``` # 二、通过数据库操作 有时因为种种原因,以上常规操作无法彻底删除服务,导致 ambari-server 启动时报告服务异常(WARN)。例如,SAMPLESRV已经从目录删除,但是仍然报以下错误,说明Ambari后台数据库还有SAMPLESRV的记录: ```bash [root@yz200 ~]# cat /var/log/ambari-server/ambari-server-check-database.log …… 2019-11-11 09:18:24,951 WARN - Service(s): SAMPLESRV, from cluster HDP has no config(s) in serviceconfig table! …… ``` 此时,可以通过直接操作Ambari后台数据库强力删除。 ```sql [postgres@yz200 ~]$ psql -d ambari -U ambari ambari=> delete from servicedesiredstate where service_name like '%SAMPLESRV%'; DELETE 1 ambari=> delete from hostcomponentstate where component_name like '%SAMPLESRV%'; DELETE 3 ambari=> delete from hostcomponentdesiredstate where component_name like '%SAMPLESRV%'; DELETE 3 ambari=> delete from servicecomponentdesiredstate where component_name like '%SAMPLESRV%'; DELETE 3 ambari=> delete from clusterservices where service_name like '%SAMPLESRV%'; ``` 删除目录: ```bash rm -rf /var/lib/ambari-server/resources/stacks/HDP/3.1/services/SAMPLESRV ``` 重启ambari-server服务: ```bash ambari-server restart ``` # 三、参考 - [修改ambari postgres-embedded数据库源数据,删除服务。](https://blog.csdn.net/fzh90/article/details/56014606)