通过数据库操作删除Ambari的服务
以删除/api/v1/clusters/HDP/services/SAMPLESRV为例。
一、常规方法
1.1 通过Web操作
- 先stop SAMPLESRV的所有服务。
- 再delete SAMPLESRV服务。
1.2 通过REST API操作
先停止服务:
- snippet.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
再删除服务:
- snippet.bash
curl -u admin:admin -H "X-Requested-By: ambari" -X DELETE http://192.168.0.200:8080/api/v1/clusters/HDP/services/SAMPLESRV
删除目录:
- snippet.bash
rm -rf /var/lib/ambari-server/resources/stacks/HDP/3.1/services/SAMPLESRV
二、通过数据库操作
有时因为种种原因,以上常规操作无法彻底删除服务,导致 ambari-server 启动时报告服务异常(WARN)。例如,SAMPLESRV已经从目录删除,但是仍然报以下错误,说明Ambari后台数据库还有SAMPLESRV的记录:
- snippet.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后台数据库强力删除。
- snippet.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%';
删除目录:
- snippet.bash
rm -rf /var/lib/ambari-server/resources/stacks/HDP/3.1/services/SAMPLESRV
重启ambari-server服务:
- snippet.bash
ambari-server restart
三、参考
打赏作者以资鼓励: