consul

echo '["abcdef123458"]' /var/consul/serf/local.keyring
service consul restart
 
# config
/etc/consul/config.json
/etc/consul/consul.d/*
 
# log
/var/log/syslog

CLI

consul catalog datacenters
consul catalog nodes
consul catalog services
 
consul monitor
consul validate /etc/consul/config.json 
consul operator raft list-peers

UI listen on external
https://stackoverflow.com/questions/35132687/how-to-access-externally-to-consul-ui

# Redirect UI to localhost
ssh -L 8500:localhost:8500 root@node1.example.com -N
 
# cat /etc/consul/config.json 
{
...
    "addresses": {
        "dns": "127.0.0.1",
        "grpc": "127.0.0.1",
        "http": "0.0.0.0",
        "https": "127.0.0.1"
    },
...

Remove service from specific node

ssh node1
consul services deregister -id=prometheus

Remove node
https://www.consul.io/commands/force-leave

consul force-leave com52-dev

checks
https://www.consul.io/api/agent/check.html

Get service state
https://consul.example.com/v1/agent/service/neutron

Icinga / Nagios checks

for SERVICE in $(consul catalog services); do
    echo ${SERVICE}
    /usr/lib/nagios/plugins/check_consul_service.py ${SERVICE}
    echo
done

Ansible module
https://docs.ansible.com/ansible/latest/modules/consul_module.html

Consul data directory

/var/consul/*

ESP
# remove service

curl -X PUT --data "{ \"Node\": \"ceph1-dev\", \"ServiceID\": \"rgw1-ep\" }" http://127.0.0.1:8500/v1/catalog/deregister
curl -X PUT --data "{ \"Node\": \"ceph2-dev\", \"ServiceID\": \"rgw2-ep\" }" http://127.0.0.1:8500/v1/catalog/deregister

Fix "No cluster leader" error
https://learn.hashicorp.com/tutorials/consul/recovery-outage
https://stackoverflow.com/questions/36772098/recovering-from-consul-no-cluster-leader-state
https://learn.hashicorp.com/tutorials/vault/ha-with-consul

consul members
consul info
consul operator raft list-peers
curl http://${IP}:8500/v1/status/peers
curl http://${IP}:8500/v1/status/leader
ll /var/consul//data/raft/
service consul status
consul catalog services

Links
https://www.consul.io/docs/agent/options.html
https://www.hashicorp.com/blog/load-balancing-strategies-for-consul
https://blog.eleven-labs.com/en/consul-service-discovery-failure-detection/
https://learn.hashicorp.com/tutorials/consul/dns-forwarding#unbound-setup