返回顶部
c

consul-cliConsul命令行

>

作者: admin | 来源: ClawHub
源自
ClawHub
版本
V 1.0.0
安全检测
已通过
101
下载量
免费
免费
0
收藏
概述
安装方式
版本历史

consul-cli

Consul CLI

HashiCorp Consul 命令行工具参考指南。

快速开始

bash

查看所有命令


consul

查看命令帮助

consul -h consul -h

启用自动补全

consul -autocomplete-install

全局选项

bash
consul [--version] [--help] []

常用全局环境变量:

  • - CONSULHTTPADDR - Agent 地址 (默认 http://127.0.0.1:8500)
  • CONSULHTTPTOKEN - ACL Token
  • CONSULHTTPTOKENFILE - Token 文件路径
  • CONSULHTTPSSL - 启用 HTTPS
  • CONSULHTTPSSLVERIFY - SSL 证书验证 (默认 true)
  • CONSULCACERT - CA 证书路径
  • CONSULNAMESPACE - 命名空间 (企业版)

Agent 命令

启动 Agent

bash

开发模式 (快速测试)

consul agent -dev

开发模式 + 允许外部访问

consul agent -dev -client=0.0.0.0

服务器模式

consul agent -server \ -bootstrap-expect=3 \ -data-dir=/opt/consul/data \ -bind=192.168.1.1 \ -client=0.0.0.0 \ -ui

加入集群

consul agent -config-dir=/etc/consul.d \ -retry-join=provider=aws tagkey=consul tagvalue=server

Agent 常用参数:

参数说明
-dev开发模式
-server
服务器模式 |
| -bootstrap-expect=N | 期望服务器数量 |
| -data-dir= | 数据目录 |
| -bind= | 绑定地址 |
| -client= | 客户端接口地址 |
| -ui | 启用 Web UI |
| -join= | 加入集群 (已弃用,用 -retry-join) |
| -retry-join= | 重试加入集群 |
| -datacenter= | 数据中心名称 |
| -node= | 节点名称 |
| -config-dir= | 配置目录 |
| -config-file= | 配置文件 |
| -encrypt= | 加密密钥 |

管理操作

bash

重载配置

consul reload

优雅停止

consul leave

强制节点离开

consul force-leave

查看成员

consul members consul members -detailed consul members -wan consul members -status=alive

查看信息

consul info

KV 命令

bash
consul kv [options] [args]

子命令

bash

写入

consul kv put consul kv put redis/config/connections 5 consul kv put -flags=123 mykey myvalue # 附加 flags

读取

consul kv get consul kv get redis/config/connections consul kv get -detailed # 详细信息

递归读取

consul kv get -recurse consul kv get -recurse redis/

删除

consul kv delete consul kv delete -recurse

导出/导入

consul kv export > backup.json consul kv import @backup.json

锁操作

consul kv put -acquire= consul kv put -release=

Catalog 命令

bash
consul catalog [options]

子命令

bash

列出数据中心

consul catalog datacenters

列出节点

consul catalog nodes consul catalog nodes -service=redis consul catalog nodes -detailed

列出服务

consul catalog services consul catalog services -node=

Services 命令

bash
consul services [options]

子命令

bash

注册服务 (命令行)

consul services register -name=web consul services register -name=redis -tag=primary -port=6379

注册服务 (配置文件)

cat > web.json << EOF { Service: { Name: web, Tags: [v1, production], Port: 8080, Check: { HTTP: http://localhost:8080/health, Interval: 10s } } } EOF consul services register web.json

注销服务

consul services deregister -id=web consul services deregister web.json

ACL 命令

bash
consul acl [options]

Bootstrap

bash

初始化 ACL 系统

consul acl bootstrap

返回: AccessorID, SecretID (root token)

Policy 管理

bash

创建策略

consul acl policy create \ -name service-read \ -description Read access to services \ -rules @policy.hcl

列出策略

consul acl policy list

读取策略

consul acl policy read -name service-read

更新策略

consul acl policy update -name service-read -rules @new-policy.hcl

删除策略

consul acl policy delete -name service-read

策略规则示例:
hcl

policy.hcl


service_prefix {
policy = read
}
key_prefix config/ {
policy = write
}
node {
policy = read
}

Token 管理

bash

创建 Token

consul acl token create \ -description My token \ -policy-name service-read

列出 Token

consul acl token list

读取 Token

consul acl token read -accessor-id=

更新 Token

consul acl token update -accessor-id= -description Updated

删除 Token

consul acl token delete -accessor-id=

设置 Agent Token

consul acl set-agent-token default

Role 管理

bash consul acl role create -name=my-role -policy-name=service-read consul acl role list consul acl role read -name=my-role consul acl role delete -name=my-role

Operator 命令

bash
consul operator [options]

Raft 管理

bash

列出 Raft 节点

consul operator raft list-peers

移除 Raft 节点

consul operator raft remove-peer

集群状态

consul operator autopilot get-config

区域管理

bash

列出区域

consul operator area list

创建区域

consul operator area create -name=us-west

Snapshot 命令

bash

创建快照


consul snapshot save backup.snap

从 Agent 保存

consul snapshot save -http-addr=http://192.168.1.1:8500 backup.snap

恢复快照

consul snapshot restore backup.snap

检查快照

consul snapshot inspect backup.snap

Connect / Service Mesh 命令

bash
consul connect [options]

Intention 管理

bash

列出意图

consul intention list

创建意图

consul intention create web db consul intention create -deny web malicious

删除意图

consul intention delete web db

检查意图

consul intention check web db

代理配置

bash

生成代理配置

consul connect proxy-config -service=web

调试与监控命令

Monitor

bash

实时日志

consul monitor

指定日志级别

consul monitor -log-level=debug

Debug

bash

收集调试信息

consul debug -duration=30s -output=/tmp/consul-debug

Info

bash

运行时信息

consul info

RTT

bash

网络延迟估算

consul rtt consul rtt dc1.node1 dc2.node2

标签

skill ai

通过对话安装

该技能支持在以下平台通过对话安装:

OpenClaw WorkBuddy QClaw Kimi Claude

方式一:安装 SkillHub 和技能

帮我安装 SkillHub 和 consul-cli-1775986087 技能

方式二:设置 SkillHub 为优先技能安装源

设置 SkillHub 为我的优先技能安装源,然后帮我安装 consul-cli-1775986087 技能

通过命令行安装

skillhub install consul-cli-1775986087

下载

⬇ 下载 consul-cli v1.0.0(免费)

文件大小: 10.3 KB | 发布时间: 2026-4-13 09:51

v1.0.0 最新 2026-4-13 09:51
Initial release - CLI command reference for Consul cluster management, KV operations, ACL, and service mesh

Archiver·手机版·闲社网·闲社论坛·羊毛社区· 多链控股集团有限公司 · 苏ICP备2025199260号-1

Powered by Discuz! X5.0   © 2024-2025 闲社网·线报更新论坛·羊毛分享社区·http://xianshe.com

p2p_official_large
返回顶部