用consul做注册中心,前期注册错误的服务看着总是很麻烦,需要手动进行删除或脚本删除
脚本批量删除
#!/bin/bash
CONSUL_ADDRESS="10.198.1.1:8500"
CONSUL_CRITICAL=`curl -H"X-Consul-Token:p2BE1AtpwPbrxZdC6k+eXA==" ${CONSUL_ADDRESS}/v1/health/state/critical | python -m json.tool | grep ServiceID | awk '{print $2}' |sed 's/"//g' | sed 's/,//g'`
for critical in ${CONSUL_CRITICAL}
do
echo "${critical} 已删除"
curl -XPUT -H"X-Consul-Token:p2BE1AtpwPbrxZdC6k+eXA==" http://${CONSUL_ADDRESS}/v1/agent/service/deregister/${critical}
done
手动单个删除
1.登录控制台,找到报错内容
http://10.1.1.15:8500/ui/dc1/services
2.查到服务id
点开错误服务,后面这个nxxxxxxxh-syn-b6c15a9fdd91ffa39bf9463a10ceb7c6 就是服务id
3.用删除接口进行删除
curl --request PUT http://10.1.1.15:8500/v1/agent/service/deregister/nxxxxxxxh-syn-b6c15a9fdd91ffa39bf9463a10ceb7c6
[tmn@kafka1 bin]$ curl --request PUT http://10.173.98.15:8500/v1/agent/service/deregister/nxxxxxxh-syn-b6c15a9fdd91ffa39bf9463a10ceb7c6