温馨提示
Consul
是一个用于服务发现、配置和分布式协调的工具。在 Windows
环境下,可以通过下载 Consul
二进制文件并运行来部署单机 Consul
服务。
下载 Consul
访问 Consul 官网 下载适用于 Windows
的二进制文件。
选择版本
选择适用于 Windows
的版本(通常是 64
位 .zip
文件,如:consul_1.20.5_windows_amd64.zip
软件包)。
下载并解压到指定目录,例如 E:\consul_1.20.5_windows_amd64
。
配置环境变量
- 右键点击“此电脑”或“计算机”,选择“属性”。
- 点击“高级系统设置”,然后选择“环境变量”。
- 在“系统变量”中找到
Path
,点击“编辑”。
- 添加
Consul
的路径(例如E:\consul_1.20.5_windows_amd64
)到Path
变量中。
启动 Consul
- 打开命令提示符
(CMD)
或PowerShell
。
- 输入以下命令启动
Consul
:
js
consul agent -dev
输出结果:
js
Windows PowerShell
版权所有(C) Microsoft Corporation。保留所有权利。
安装最新的 PowerShell,了解新功能和改进!https://aka.ms/PSWindows
PS E:\consul_1.20.5_windows_amd64> consul agent -dev
==> Starting Consul agent...
Version: '1.20.1'
Build Date: '2024-10-29 19:04:05 +0000 UTC'
Node ID: 'f7124776-fc5d-ca62-7c2b-fc29e5656773'
Node name: 'LAPTOP-1DA0H5V6'
Datacenter: 'dc1' (Segment: '<all>')
Server: true (Bootstrap: false)
Client Addr: [127.0.0.1] (HTTP: 8500, HTTPS: -1, gRPC: 8502, gRPC-TLS: 8503, DNS: 8600)
Cluster Addr: 127.0.0.1 (LAN: 8301, WAN: 8302)
Gossip Encryption: false
Auto-Encrypt-TLS: false
ACL Enabled: false
Reporting Enabled: false
ACL Default Policy: allow
HTTPS TLS: Verify Incoming: false, Verify Outgoing: false, Min Version: TLSv1_2
gRPC TLS: Verify Incoming: false, Min Version: TLSv1_2
Internal RPC TLS: Verify Incoming: false, Verify Outgoing: false (Verify Hostname: false), Min Version: TLSv1_2
==> Log data will now stream in as it occurs:
2025-03-20T09:07:54.344+0800 [DEBUG] agent.grpc.balancer: switching server: target=consul://dc1.f7124776-fc5d-ca62-7c2b-fc29e5656773/server.dc1 from=<none> to=<none>
2025-03-20T09:07:54.424+0800 [INFO] agent.server.raft: initial configuration: index=1 servers="[{Suffrage:Voter ID:f7124776-fc5d-ca62-7c2b-fc29e5656773 Address:127.0.0.1:8300}]"
2025-03-20T09:07:54.425+0800 [INFO] agent.server.raft: entering follower state: follower="Node at 127.0.0.1:8300 [Follower]" leader-address= leader-id=
2025-03-20T09:07:54.427+0800 [INFO] agent.server.serf.wan: serf: EventMemberJoin: LAPTOP-1DA0H5V6.dc1 127.0.0.1
2025-03-20T09:07:54.428+0800 [INFO] agent.server.serf.lan: serf: EventMemberJoin: LAPTOP-1DA0H5V6 127.0.0.1
2025-03-20T09:07:54.428+0800 [INFO] agent.router: Initializing LAN area manager
2025-03-20T09:07:54.428+0800 [DEBUG] agent.grpc.balancer: switching server: target=consul://dc1.f7124776-fc5d-ca62-7c2b-fc29e5656773/server.dc1 from=<none> to=dc1-127.0.0.1:8300
2025-03-20T09:07:54.428+0800 [INFO] agent.server: Adding LAN server: server="LAPTOP-1DA0H5V6 (Addr: tcp/127.0.0.1:8300) (DC: dc1)"
2025-03-20T09:07:54.428+0800 [INFO] agent.server: Handled event for server in area: event=member-join server=LAPTOP-1DA0H5V6.dc1 area=wan
2025-03-20T09:07:54.428+0800 [INFO] agent.server.autopilot: reconciliation now disabled
2025-03-20T09:07:54.431+0800 [DEBUG] agent.server.autopilot: autopilot is now running
2025-03-20T09:07:54.431+0800 [DEBUG] agent.server.autopilot: state update routine is now running
2025-03-20T09:07:54.431+0800 [INFO] agent.server.cert-manager: initialized server certificate management
2025-03-20T09:07:54.431+0800 [INFO] agent: Started DNS server: address=127.0.0.1:8600 network=tcp
2025-03-20T09:07:54.431+0800 [INFO] agent: Started DNS server: address=127.0.0.1:8600 network=udp
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v1/executive
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/multicluster/v2/exportedservices
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/multicluster/v2/computedexportedservices
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/hcp/v2/link
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v1/concept
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v2/artist
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v2/album
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/multicluster/v2/partitionexportedservices
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/hcp/v2/telemetrystate
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/internal/v1/tombstone
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v1/recordlabel
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v1/album
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v2/festival
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/demo/v1/artist
2025-03-20T09:07:54.437+0800 [INFO] agent.http: Registered resource endpoint: endpoint=/api/multicluster/v2/namespaceexportedservices
2025-03-20T09:07:54.437+0800 [INFO] agent: Starting server: address=127.0.0.1:8500 network=tcp protocol=http
2025-03-20T09:07:54.437+0800 [INFO] agent: Started gRPC listeners: port_name=grpc address=127.0.0.1:8502 network=tcp
2025-03-20T09:07:54.437+0800 [INFO] agent: started state syncer
2025-03-20T09:07:54.437+0800 [INFO] agent: Consul agent running!
2025-03-20T09:07:54.437+0800 [INFO] agent: Started gRPC listeners: port_name=grpc_tls address=127.0.0.1:8503 network=tcp
2025-03-20T09:07:54.472+0800 [WARN] agent.server.raft: heartbeat timeout reached, starting election: last-leader-addr= last-leader-id=
2025-03-20T09:07:54.472+0800 [INFO] agent.server.raft: entering candidate state: node="Node at 127.0.0.1:8300 [Candidate]" term=2
2025-03-20T09:07:54.472+0800 [DEBUG] agent.server.raft: voting for self: term=2 id=f7124776-fc5d-ca62-7c2b-fc29e5656773
2025-03-20T09:07:54.474+0800 [DEBUG] agent.server.raft: calculated votes needed: needed=1 term=2
2025-03-20T09:07:54.474+0800 [DEBUG] agent.server.raft: vote granted: from=f7124776-fc5d-ca62-7c2b-fc29e5656773 term=2 tally=1
2025-03-20T09:07:54.474+0800 [INFO] agent.server.raft: election won: term=2 tally=1
2025-03-20T09:07:54.474+0800 [INFO] agent.server.raft: entering leader state: leader="Node at 127.0.0.1:8300 [Leader]"
2025-03-20T09:07:54.474+0800 [DEBUG] agent.server.controller-runtime: controller running: controller=artists managed_type=demo.v2.Artist
2025-03-20T09:07:54.474+0800 [DEBUG] agent.server.controller-runtime: controller running: controller=consul.io/exported-services-v1-compat managed_type=multicluster.v2.ComputedExportedServices
2025-03-20T09:07:54.474+0800 [DEBUG] agent.server.controller-runtime: controller running: controller=consul.io/reaper-controller managed_type=internal.v1.Tombstone
2025-03-20T09:07:54.474+0800 [INFO] agent.server: cluster leadership acquired
2025-03-20T09:07:54.474+0800 [INFO] agent.server: New leader elected: payload=LAPTOP-1DA0H5V6
2025-03-20T09:07:54.476+0800 [DEBUG] agent.server.controller-runtime: priming caches: controller=artists managed_type=demo.v2.Artist
2025-03-20T09:07:54.476+0800 [DEBUG] agent.server.controller-runtime: priming caches: controller=consul.io/reaper-controller managed_type=internal.v1.Tombstone
2025-03-20T09:07:54.477+0800 [DEBUG] agent.server.controller-runtime: priming caches: controller=consul.io/exported-services-v1-compat managed_type=multicluster.v2.ComputedExportedServices
2025-03-20T09:07:54.477+0800 [INFO] agent.server.autopilot: reconciliation now enabled
2025-03-20T09:07:54.478+0800 [INFO] agent.leader: started routine: routine="federation state anti-entropy"
2025-03-20T09:07:54.478+0800 [INFO] agent.leader: started routine: routine="federation state pruning"
2025-03-20T09:07:54.478+0800 [INFO] agent.leader: started routine: routine="streaming peering resources"
2025-03-20T09:07:54.478+0800 [INFO] agent.leader: started routine: routine="metrics for streaming peering resources"
2025-03-20T09:07:54.478+0800 [INFO] agent.leader: started routine: routine="peering deferred deletion"
2025-03-20T09:07:54.478+0800 [DEBUG] agent.server.controller-runtime: priming caches complete: controller=consul.io/reaper-controller managed_type=internal.v1.Tombstone
2025-03-20T09:07:54.478+0800 [DEBUG] agent.server.controller-runtime: priming caches complete: controller=artists managed_type=demo.v2.Artist
2025-03-20T09:07:54.478+0800 [DEBUG] agent.server.controller-runtime: priming caches complete: controller=consul.io/exported-services-v1-compat managed_type=multicluster.v2.ComputedExportedServices
2025-03-20T09:07:54.478+0800 [DEBUG] connect.ca.consul: consul CA provider configured: id=fb:50:9b:45:1a:65:15:c1:68:57:73:5f:da:cd:b8:0d:0f:e2:26:eb:68:66:43:11:85:9d:67:a9:7a:56:9c:b9 is_primary=true
2025-03-20T09:07:54.481+0800 [INFO] connect.ca: updated root certificates from primary datacenter
2025-03-20T09:07:54.481+0800 [INFO] connect.ca: initialized primary datacenter CA with provider: provider=consul
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: started routine: routine="intermediate cert renew watch"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: started routine: routine="CA root pruning"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: started routine: routine="CA root expiration metric"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: started routine: routine="CA signing expiration metric"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: started routine: routine="virtual IP version check"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: started routine: routine="config entry controllers"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: stopping routine: routine="virtual IP version check"
2025-03-20T09:07:54.481+0800 [INFO] agent.leader: stopped routine: routine="virtual IP version check"
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.api_gateway_controller: rewatching controller subscription: controller=apiGatewayController topic=APIGateway
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.api_gateway_controller: rewatching controller subscription: controller=apiGatewayController topic=HTTPRoute
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.api_gateway_controller: rewatching controller subscription: controller=apiGatewayController topic=InlineCertificate
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.api_gateway_controller: rewatching controller subscription: controller=apiGatewayController topic=TCPRoute
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.api_gateway_controller: rewatching controller subscription: controller=apiGatewayController topic=BoundAPIGateway
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.api_gateway_controller: rewatching controller subscription: controller=apiGatewayController topic=JWTProvider
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server: successfully established leadership: duration=6.438ms
2025-03-20T09:07:54.481+0800 [INFO] agent.server: member joined, marking health alive: member=LAPTOP-1DA0H5V6 partition=default
2025-03-20T09:07:54.481+0800 [DEBUG] agent.server.xds_capacity_controller: updating drain rate limit: rate_limit=1
2025-03-20T09:07:54.504+0800 [DEBUG] agent: Skipping remote check since it is managed automatically: check=serfHealth
2025-03-20T09:07:54.505+0800 [INFO] agent: Synced node info
2025-03-20T09:07:54.505+0800 [DEBUG] agent: Node info in sync
2025-03-20T09:07:54.927+0800 [INFO] agent.server: federation state anti-entropy synced
2025-03-20T09:07:55.253+0800 [DEBUG] agent: Skipping remote check since it is managed automatically: check=serfHealth
2025-03-20T09:07:55.253+0800 [DEBUG] agent: Node info in sync
2025-03-20T09:07:55.326+0800 [DEBUG] agent.server.cert-manager: got cache update event: correlationID=leaf error=<nil>
2025-03-20T09:07:55.326+0800 [DEBUG] agent.server.cert-manager: leaf certificate watch fired - updating auto TLS certificate: uri=spiffe://a4695d0b-d322-1c6d-5de7-dab7899c88a9.consul/agent/server/dc/dc1
2025-03-20T09:07:55.443+0800 [DEBUG] agent.server.cert-manager: CA config watch fired - updating auto TLS server name: name=server.dc1.peering.a4695d0b-d322-1c6d-5de7-dab7899c88a9.consul
温馨提示
-dev
参数表示以开发模式运行,适用于单机环境。
验证 Consul 安装
- 打开浏览器,访问
http://127.0.0.1:8500
。
- 如果看到
Consul
的Web
界面,用于查看节点、服务和配置,说明安装成功。
停止 Consul 服务
在启动 Consul
的命令提示符中按 Ctrl + C
停止服务。
配置 Consul(可选)
- 创建配置文件
config.json
,内容如下:
js
{
"datacenter": "dc1",
"data_dir": "C:/Consul/data",
"log_level": "INFO",
"node_name": "consul-dev",
"server": true,
"bootstrap_expect": 1,
"bind_addr": "127.0.0.1",
"client_addr": "127.0.0.1",
"ui": true
}
- 使用配置文件启动
Consul
js
consul agent -config-file=E:\consul_1.20.5_windows_amd64\config.json
总结
通过以上步骤,你已在 Windows
上成功部署了单机 Consul
服务,并可通过 Web UI
进行管理。