Consul CLI 인터페이스
Consul CLI 인터페이스
이 페이지에서는 Consul CLI를 소개하고 CLI를 설정하고 사용하여 Consul 배포와 상호작용하는 방법을 설명해요. Consul CLI는 HTTP API의 래퍼로 터미널 세션에서 Consul과 상호작용할 수 있게 해준답니다.
출처: 문서
본문
이 페이지에서는 Consul CLI를 소개하고 CLI를 설정하고 사용하여 Consul 배포와 상호작용하는 방법을 설명합니다.
자세한 내용은 Consul CLI reference documentation을 참조하세요.
소개 (Introduction)
Consul CLI는 터미널 세션에서 Consul과 상호작용할 수 있게 해주는 HTTP API의 래퍼입니다.
언제든지 사용 가능한 명령 목록을 보려면 인자 없이 consul을 실행하세요.
$ consul
Usage: consul [--version] [--help] <command> [<args>]
Available commands are:
acl Interact with Consul's ACLs
agent Runs a Consul agent
catalog Interact with the catalog
connect Interact with service mesh functionality
debug Records a debugging archive for operators
event Fire a new event
exec Executes a command on Consul nodes
force-leave Forces a member of the cluster to enter the "left" state
info Provides debugging information for operators.
intention Interact with service mesh intentions
join Tell Consul agent to join cluster
keygen Generates a new encryption key
keyring Manages gossip layer encryption keys
kv Interact with the key-value store
leave Gracefully leaves the Consul cluster and shuts down
lock Execute a command holding a lock
login Login to Consul using an auth method
logout Destroy a Consul token created with login
maint Controls node or service maintenance mode
members Lists the members of a Consul cluster
monitor Stream logs from a Consul agent
operator Provides cluster-level tools for Consul operators
peering Create and manage peering connections between Consul clusters
reload Triggers the agent to reload configuration files
rtt Estimates network round trip time between nodes
services Interact with services
snapshot Saves, restores and inspects snapshots of Consul server state
tls Builtin helpers for creating CAs and certificates
troubleshoot Provides tools to troubleshoot Consul's service mesh configuration
validate Validate config files/directories
version Prints the Consul version
watch Watch for changes in Consul
특정 명령에 대한 도움말을 얻으려면 해당 하위 명령에 -h 플래그를 전달하세요. 예를 들어 다음 명령은 join 하위 명령에 대한 정보를 반환합니다.
$ consul join --help
Usage: consul join [options] address ...
Tells a running Consul agent (with "consul agent") to join the cluster
by specifying at least one existing member.
HTTP API Options
-http-addr=<address>
The `address` and port of the Consul HTTP agent. The value can be
an IP address or DNS address, but it must also include the port.
This can also be specified via the CONSUL_HTTP_ADDR environment
variable. The default value is http://127.0.0.1:8500. The scheme
can also be set to HTTPS by setting the environment variable
CONSUL_HTTP_SSL=true.
-token=<value>
ACL token to use in the request. This can also be specified via the
CONSUL_HTTP_TOKEN environment variable. If unspecified, the query
will default to the token of the Consul agent at the HTTP address.
Command Options
-wan
Joins a server to another server in the WAN pool.
환경 변수 (Environment variables)
Consul의 CLI는 기본 동작을 설정하는 환경 변수를 지원합니다. 명령줄 플래그가 항상 우선하지만, 환경 변수를 사용하면 공통 설정을 반복해서 지정할 필요를 줄여 워크플로우를 간소화할 수 있습니다.
다음 환경 변수는 Consul 클러스터의 HTTP 주소와 Consul 인증에 사용되는 토큰을 설정합니다. 문서와 튜토리얼은 이미 이러한 변수를 구성했다고 가정합니다.
CONSUL_HTTP_ADDR: Consul 클러스터의 HTTP 주소를 지정합니다.$ export CONSUL_HTTP_ADDR=http://127.0.0.1:8500CONSUL_HTTP_TOKEN또는CONSUL_HTTP_TOKEN_FILE: Consul 인증에 사용되는 ACL 토큰을 지정합니다. ACL 시스템이 활성화된 경우 Consul CLI는 작업을 수행할 권한이 있는 ACL 토큰이 필요합니다.-token명령줄 플래그로 CLI에 직접 ACL 토큰을 제공하거나,-token-file명령줄 플래그로 파일에서 제공하거나,CONSUL_HTTP_TOKEN또는CONSUL_HTTP_TOKEN_FILE환경 변수로 제공할 수 있습니다.$ export CONSUL_HTTP_TOKEN=aba7cbe5-879b-999a-07cc-2efd9ac0ffe
추가 연결 요구 사항은 Consul 클러스터가 구성된 방식에 따라 달라집니다. 자세한 내용은 support된 환경 변수 목록을 포함하여 Consul CLI documentation을 참조하세요.
기본 명령 (Basic commands)
다음 명령은 일반적으로 사용되는 Consul CLI 명령을 보여줍니다.
consul members 명령은 클러스터의 gossip 풀에 참여한 Consul 인스턴스에 대한 정보와 상태를 반환합니다. 이 명령으로 클러스터의 현재 상태를 확인할 수 있습니다.
$ consul members
Node Address Status Type Build Protocol DC Partition Segment
boruszak-LFH0JH12XD 127.0.0.1:8301 alive server 1.20.2 2 dc1 default <all>
consul version 명령으로 설치 버전 번호와 빌드 날짜를 확인하세요. 같은 데이터센터에서 호환되지 않는 버전의 에이전트를 실행하면 운영에 영향을 줄 수 있습니다.
$ consul version
Consul v1.20.2
Revision 33e5727a
Build Date 2025-01-03T14:38:40Z
Protocol 2 spoken by default, understands 2 to 3 (agent will automatically use protocol >2 when speaking to compatible agents)
consul reload 명령은 에이전트의 구성 디렉터리에 있는 구성 파일을 다시 로드합니다. 이 명령을 사용하여 에이전트나 노드를 다시 시작하지 않고 Consul 클러스터에 구성 업데이트를 적용하세요.
$ consul reload
Configuration reload triggered
consul catalog services 명령은 Consul 카탈로그에 등록된 서비스 목록을 반환합니다.
$ consul catalog services
consul
consul kv 명령으로 Consul 키-값 스토어와 상호작용할 수 있습니다. 작업, 키, 값을 순서대로 지정하세요.
$consul kv put redis/config/connections 5
Success! Data written to: redis/config/connections
consul leave를 사용하여 Consul 에이전트가 데이터센터를 정상적으로 떠나게 합니다. 클러스터를 떠난 후 에이전트는 종료됩니다.
$ consul leave
Graceful leave complete
다음 단계 (Next steps)
Consul CLI와 그 명령에 대해 더 알아보려면 Consul CLI documentation을 참조하세요.
Consul 기초를 계속 배우려면 Explore the Consul web UI로 진행하세요.