传统运维 - consul操作

2022-08-19

consul api 地址

CONSUL_CATALOG_API=http://127.0.0.1/v1

查看 service id

curl ${CONSUL_CATALOG_API}/agent/services | jq .

注销 service

curl -X PUT -H 'application/json' ${CONSUL_CATALOG_API}/agent/service/deregister/${service_id}

注销 node

curl -X PUT -H 'application/json' -d '{"Datacenter": "java-prd","Node": "'${ip}'"}' ${CONSUL_CATALOG_API}/agent/force-leave/${ip}

注册 node

{
	"Datacenter": "dc1",
	"Node": "ali-hz-office-gitlabrunner-gitlabrunnerlinux-001",
	"Address": "10.111.115.218",
	"NodeMeta": {
		"dpt": "office",
		"group": "office-gitlabrunner",
		"hostname": "ali-hz-office-gitlabrunner-gitlabrunnerlinux-001"
	},
	"Service": {
		"ID": "server",
		"Service": "node_exporter",
		"Tags": [
			"primary",
			"v1"
		],
		"Address": "10.111.115.218",
		"Port": 9100
	},
	"SkipNodeUpdate": false
}

curl -s --request PUT --data @${temp_file} ${CONSUL_CATALOG_API}/register
curl -X PUT -d '{"id": "浙江xxx","name": "check_tcp_custom","address": "114.55.172.226","port": 80 }' http://consul.iyunquna.com/v1/agent/service/register
curl -X PUT -d '{"id": "test","name": "check_icmp_custom","address": "192.168.100.247"}' [http://pr-consul.iyunquna.com/v1/agent/service/register](http://pr-consul.iyunquna.com/v1/agent/service/register)
curl http://consul.iyunquna.com/v1/catalog/service/node_exporter | python -m json.tool | grep ServiceID| grep -v 'i-' | grep -v AY1208310125583e55559|awk '{print $2}'|awk -F '"' '{print $2}' | while read line; do  consul services deregister -id=${line};done
curl ${CONSUL_CATALOG_API}/agent/services | jq . | grep node_export -B1|awk -F '"' '{print $4}'|sort|uniq |grep -v node_export| while read line;do curl -X PUT -H 'application/json' ${CONSUL_CATALOG_API}/agent/service/deregister/${line};done

标题:传统运维 - consul操作
地址:https://blog.njqhome.com:8443/articles/2019/10/28/1572253717120.html