consul catalog

catalog命令用于通过命令行与Consul的目录进行交互。它暴露顶级命令来读取和过滤来自注册表的数据

用法: consul catalog

列出所有数据中心

# consul catalog datacenters
testkydhuabei2

列出所有节点

# consul catalog nodes
Node ID Address DC
location 2ebf41aa 172.17.252.105 testkydhuabei2
test 316bec16 172.17.252.104 testkydhuabei2

列出所有服务

# consul catalog services
consul
kyd-auth
kyd-backend
kyd-gate
kyd-monitor
kyd-user
nomad
nomad-client

列出特定服务的所有节点

# consul catalog nodes -service=kyd-gate
Node ID Address DC
location 2ebf41aa 172.17.252.105 testkydhuabei2
location 2ebf41aa 172.17.252.105 testkydhuabei2
location 2ebf41aa 172.17.252.105 testkydhuabei2
location 2ebf41aa 172.17.252.105 testkydhuabei2
location 2ebf41aa 172.17.252.105 testkydhuabei2
location 2ebf41aa 172.17.252.105 testkydhuabei2

列出节点的所有服务

# consul catalog services -node=location
consul
kyd-auth
kyd-backend
kyd-gate
nomad
nomad-client

consul services

services用于与向本地代理注册的Consul服务进行交互。它们提供了有用的命令,例如register,deregister用于在脚本,开发模式等中轻松注册服务。要查看目录中的所有服务

用法: consul services deregister [options] [FILE…]

此命令可以使用-id下面记录的标志取消注册单个服务,也可以使用HCL或JSON格式的服务定义文件取消注册一个或多个服务

# consul services deregister -id kyd-user-88bf0b417b4164bcc640cf8a6553f066

查看版本

# consul version
Consul v1.4.0

consul reload

reload命令会触发代理程序的重新加载配置文件

快照

consul snapshot

snapshot命令用于保存,恢复和检查Consul服务器的状态以进行灾难恢复

用法: consul snapshot

创建快照并将其另存为名为“backup.snap”的文件

# consul snapshot save backup.snap
Saved and verified snapshot to index 53956

从名为“backup.snap”的文件还原快照

# consul snapshot restore backup.snap
Restored snapshot