2014-02-08 00:41:03 +00:00
|
|
|
---
|
2020-09-01 15:14:13 +00:00
|
|
|
layout: commands
|
2020-04-07 18:55:19 +00:00
|
|
|
page_title: Commands
|
|
|
|
description: >-
|
|
|
|
Consul is controlled via a very easy to use command-line interface (CLI).
|
|
|
|
Consul is only a single command-line application: `consul`. This application
|
|
|
|
then takes a subcommand such as agent or members. The complete list of
|
|
|
|
subcommands is in the navigation to the left.
|
2014-02-08 00:41:03 +00:00
|
|
|
---
|
|
|
|
|
2014-02-19 01:32:13 +00:00
|
|
|
# Consul Commands (CLI)
|
2014-02-08 00:41:03 +00:00
|
|
|
|
2014-02-19 01:32:13 +00:00
|
|
|
Consul is controlled via a very easy to use command-line interface (CLI).
|
|
|
|
Consul is only a single command-line application: `consul`. This application
|
2014-02-08 00:41:03 +00:00
|
|
|
then takes a subcommand such as "agent" or "members". The complete list of
|
|
|
|
subcommands is in the navigation to the left.
|
|
|
|
|
2018-01-04 21:44:07 +00:00
|
|
|
The `consul` CLI is a well-behaved command line application. In erroneous
|
2014-02-08 00:41:03 +00:00
|
|
|
cases, a non-zero exit status will be returned. It also responds to `-h` and `--help`
|
|
|
|
as you'd most likely expect. And some commands that expect input accept
|
2014-02-19 01:32:13 +00:00
|
|
|
"-" as a parameter to tell Consul to read the input from stdin.
|
2014-02-08 00:41:03 +00:00
|
|
|
|
2014-02-19 01:32:13 +00:00
|
|
|
To view a list of the available commands at any time, just run `consul` with
|
2014-02-08 00:41:03 +00:00
|
|
|
no arguments:
|
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2014-02-19 01:32:13 +00:00
|
|
|
$ consul
|
2018-05-22 16:07:13 +00:00
|
|
|
Usage: consul [--version] [--help] <command> [<args>]
|
2014-02-08 00:41:03 +00:00
|
|
|
|
|
|
|
Available commands are:
|
2019-05-01 21:11:23 +00:00
|
|
|
acl Interact with Consul's ACLs
|
2014-02-19 01:32:13 +00:00
|
|
|
agent Runs a Consul agent
|
2018-03-09 17:46:37 +00:00
|
|
|
catalog Interact with the catalog
|
2023-05-05 17:41:40 +00:00
|
|
|
connect Interact with service mesh functionality
|
2019-05-01 21:11:23 +00:00
|
|
|
debug Records a debugging archive for operators
|
2014-09-01 22:03:37 +00:00
|
|
|
event Fire a new event
|
|
|
|
exec Executes a command on Consul nodes
|
2014-02-08 00:41:03 +00:00
|
|
|
force-leave Forces a member of the cluster to enter the "left" state
|
2018-03-09 17:46:37 +00:00
|
|
|
info Provides debugging information for operators.
|
2023-05-05 17:41:40 +00:00
|
|
|
intention Interact with service mesh intentions
|
2014-02-19 01:32:13 +00:00
|
|
|
join Tell Consul agent to join cluster
|
2014-02-08 00:41:03 +00:00
|
|
|
keygen Generates a new encryption key
|
2015-01-20 02:43:38 +00:00
|
|
|
keyring Manages gossip layer encryption keys
|
2018-03-09 17:46:37 +00:00
|
|
|
kv Interact with the key-value store
|
2014-02-19 01:32:13 +00:00
|
|
|
leave Gracefully leaves the Consul cluster and shuts down
|
2015-01-20 02:43:38 +00:00
|
|
|
lock Execute a command holding a lock
|
2019-05-01 21:11:23 +00:00
|
|
|
login Login to Consul using an auth method
|
|
|
|
logout Destroy a Consul token created with login
|
2016-09-26 15:12:14 +00:00
|
|
|
maint Controls node or service maintenance mode
|
2014-02-19 01:32:13 +00:00
|
|
|
members Lists the members of a Consul cluster
|
|
|
|
monitor Stream logs from a Consul agent
|
2016-08-30 02:09:57 +00:00
|
|
|
operator Provides cluster-level tools for Consul operators
|
2022-08-31 16:58:41 +00:00
|
|
|
peering Create and manage peering connections between Consul clusters
|
2014-06-11 18:03:59 +00:00
|
|
|
reload Triggers the agent to reload configuration files
|
2015-10-16 07:56:15 +00:00
|
|
|
rtt Estimates network round trip time between nodes
|
2018-10-01 17:27:15 +00:00
|
|
|
services Interact with services
|
2018-03-09 17:46:37 +00:00
|
|
|
snapshot Saves, restores and inspects snapshots of Consul server state
|
2019-05-01 21:11:23 +00:00
|
|
|
tls Builtin helpers for creating CAs and certificates
|
2023-02-17 21:25:49 +00:00
|
|
|
troubleshoot Provides tools to troubleshoot Consul's service mesh configuration
|
2018-03-09 17:46:37 +00:00
|
|
|
validate Validate config files/directories
|
2014-02-19 01:32:13 +00:00
|
|
|
version Prints the Consul version
|
2014-08-22 00:25:42 +00:00
|
|
|
watch Watch for changes in Consul
|
2014-02-08 00:41:03 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
To get help for any specific command, pass the `-h` flag to the relevant
|
2014-06-11 18:08:19 +00:00
|
|
|
subcommand. For example, to see help about the `join` subcommand:
|
2014-02-08 00:41:03 +00:00
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2022-01-12 23:05:01 +00:00
|
|
|
$ consul join --help
|
2014-06-11 18:08:19 +00:00
|
|
|
Usage: consul join [options] address ...
|
2014-02-08 00:41:03 +00:00
|
|
|
|
2014-06-11 18:08:19 +00:00
|
|
|
Tells a running Consul agent (with "consul agent") to join the cluster
|
|
|
|
by specifying at least one existing member.
|
2014-02-08 00:41:03 +00:00
|
|
|
|
2017-02-28 21:41:09 +00:00
|
|
|
HTTP API Options
|
2014-02-08 00:41:03 +00:00
|
|
|
|
2017-02-28 21:41:09 +00:00
|
|
|
-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.
|
2014-02-08 00:41:03 +00:00
|
|
|
```
|
2017-01-09 17:02:06 +00:00
|
|
|
|
2022-01-10 22:07:38 +00:00
|
|
|
## Authentication
|
|
|
|
|
2023-01-25 16:52:43 +00:00
|
|
|
When the [ACL system is enabled](/consul/docs/agent/config/config-files#acl) the Consul CLI will
|
|
|
|
require an [ACL token](/consul/docs/security/acl#tokens) to perform API requests.
|
2022-01-10 22:07:38 +00:00
|
|
|
|
|
|
|
The ACL token can be provided directly on the command line using the `-token` command line flag,
|
|
|
|
from a file using the `-token-file` command line flag, or from the
|
|
|
|
[`CONSUL_HTTP_TOKEN`](#consul_http_token_file) environment variable.
|
|
|
|
|
2017-10-06 20:05:45 +00:00
|
|
|
## Autocompletion
|
|
|
|
|
|
|
|
The `consul` command features opt-in subcommand autocompletion that you can
|
|
|
|
enable for your shell with `consul -autocomplete-install`. After doing so,
|
|
|
|
you can invoke a new shell and use the feature.
|
|
|
|
|
|
|
|
For example, assume a tab is typed at the end of each prompt line:
|
|
|
|
|
2020-05-19 18:32:38 +00:00
|
|
|
```shell-session
|
2017-10-06 20:05:45 +00:00
|
|
|
$ consul e
|
|
|
|
event exec
|
|
|
|
|
|
|
|
$ consul r
|
2017-10-06 20:23:43 +00:00
|
|
|
reload rtt
|
2017-10-06 20:05:45 +00:00
|
|
|
|
2017-10-06 20:23:43 +00:00
|
|
|
$ consul operator raft
|
|
|
|
list-peers remove-peer
|
2017-10-06 20:05:45 +00:00
|
|
|
```
|
|
|
|
|
2022-02-16 18:19:00 +00:00
|
|
|
## Arguments with URL-Invalid Characters
|
|
|
|
|
|
|
|
The CLI automatically URL-encodes arguments, which are then
|
2023-01-25 16:52:43 +00:00
|
|
|
[URL-decoded by the underlying HTTP API endpoints](/consul/api-docs/api-structure#url-encoded-resource-names).
|
2022-02-16 18:19:00 +00:00
|
|
|
To avoid double-encoding arguments, do not URL-encode arguments passed to the CLI.
|
|
|
|
|
2017-01-09 17:02:06 +00:00
|
|
|
## Environment Variables
|
|
|
|
|
|
|
|
In addition to CLI flags, Consul reads environment variables for behavior
|
|
|
|
defaults. CLI flags always take precedence over environment variables, but it
|
|
|
|
is often helpful to use environment variables to configure the Consul agent,
|
|
|
|
particularly with configuration management and init systems.
|
|
|
|
|
|
|
|
These environment variables and their purpose are described below:
|
|
|
|
|
2019-10-31 19:14:08 +00:00
|
|
|
### `CONSUL_HTTP_ADDR`
|
2017-01-09 17:02:06 +00:00
|
|
|
|
2020-04-06 20:27:35 +00:00
|
|
|
This is the HTTP API address to the _local_ Consul agent
|
2018-10-11 09:44:42 +00:00
|
|
|
(not the remote server) specified as a URI with optional scheme:
|
2017-01-09 17:02:06 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_HTTP_ADDR=127.0.0.1:8500
|
|
|
|
```
|
|
|
|
|
|
|
|
or as a Unix socket path:
|
|
|
|
|
|
|
|
```
|
2019-05-10 13:28:58 +00:00
|
|
|
CONSUL_HTTP_ADDR=unix:///var/run/consul_http.sock
|
2017-01-09 17:02:06 +00:00
|
|
|
```
|
|
|
|
|
2018-10-11 09:44:42 +00:00
|
|
|
If the `https://` scheme is used, `CONSUL_HTTP_SSL` is implied to be true.
|
|
|
|
|
2017-01-09 17:02:06 +00:00
|
|
|
### `CONSUL_HTTP_TOKEN`
|
|
|
|
|
|
|
|
This is the API access token required when access control lists (ACLs)
|
|
|
|
are enabled, for example:
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_HTTP_TOKEN=aba7cbe5-879b-999a-07cc-2efd9ac0ffe
|
|
|
|
```
|
|
|
|
|
2019-05-01 21:11:23 +00:00
|
|
|
### `CONSUL_HTTP_TOKEN_FILE`
|
|
|
|
|
|
|
|
This is a path to a file containing the API access token required when access
|
|
|
|
control lists (ACLs) are enabled, for example:
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_HTTP_TOKEN_FILE=/path/to/consul.token
|
|
|
|
```
|
|
|
|
|
2017-01-09 17:02:06 +00:00
|
|
|
### `CONSUL_HTTP_AUTH`
|
|
|
|
|
|
|
|
This specifies HTTP Basic access credentials as a username:password pair:
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_HTTP_AUTH=operations:JPIMCmhDHzTukgO6
|
|
|
|
```
|
|
|
|
|
|
|
|
### `CONSUL_HTTP_SSL`
|
|
|
|
|
|
|
|
This is a boolean value (default is false) that enables the HTTPS URI
|
|
|
|
scheme and SSL connections to the HTTP API:
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_HTTP_SSL=true
|
|
|
|
```
|
|
|
|
|
|
|
|
### `CONSUL_HTTP_SSL_VERIFY`
|
|
|
|
|
2018-10-11 09:44:42 +00:00
|
|
|
This is a boolean value (default true) to specify SSL certificate verification;
|
|
|
|
setting this value to `false` is not recommended for production use. Example for
|
|
|
|
development purposes:
|
2017-01-09 17:02:06 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_HTTP_SSL_VERIFY=false
|
|
|
|
```
|
2017-04-14 20:37:29 +00:00
|
|
|
|
|
|
|
### `CONSUL_CACERT`
|
|
|
|
|
|
|
|
Path to a CA file to use for TLS when communicating with Consul.
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_CACERT=ca.crt
|
|
|
|
```
|
|
|
|
|
|
|
|
### `CONSUL_CAPATH`
|
|
|
|
|
|
|
|
Path to a directory of CA certificates to use for TLS when communicating with Consul.
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_CAPATH=ca_certs/
|
|
|
|
```
|
|
|
|
|
|
|
|
### `CONSUL_CLIENT_CERT`
|
|
|
|
|
|
|
|
Path to a client cert file to use for TLS when `verify_incoming` is enabled.
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_CLIENT_CERT=client.crt
|
|
|
|
```
|
|
|
|
|
|
|
|
### `CONSUL_CLIENT_KEY`
|
|
|
|
|
|
|
|
Path to a client key file to use for TLS when `verify_incoming` is enabled.
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_CLIENT_KEY=client.key
|
|
|
|
```
|
|
|
|
|
|
|
|
### `CONSUL_TLS_SERVER_NAME`
|
|
|
|
|
|
|
|
The server name to use as the SNI host when connecting via TLS.
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_TLS_SERVER_NAME=consulserver.domain
|
2018-01-04 21:44:07 +00:00
|
|
|
```
|
2018-10-11 09:44:42 +00:00
|
|
|
|
|
|
|
### `CONSUL_GRPC_ADDR`
|
|
|
|
|
|
|
|
Like [`CONSUL_HTTP_ADDR`](#consul_http_addr) but configures the address the
|
|
|
|
local agent is listening for gRPC requests. Currently gRPC is only used for
|
2023-01-25 16:52:43 +00:00
|
|
|
integrating [Envoy proxy](/consul/docs/connect/proxies/envoy) and must be [enabled
|
|
|
|
explicitly](/consul/docs/agent/config/config-files#grpc_port) in agent configuration.
|
2018-10-11 09:44:42 +00:00
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_GRPC_ADDR=127.0.0.1:8502
|
|
|
|
```
|
|
|
|
|
|
|
|
or as a Unix socket path:
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_GRPC_ADDR=unix://var/run/consul_grpc.sock
|
|
|
|
```
|
|
|
|
|
|
|
|
If the agent is [configured with TLS
|
2023-01-25 16:52:43 +00:00
|
|
|
certificates](/consul/docs/security/encryption#rpc-encryption-with-tls), then the
|
2018-10-11 09:44:42 +00:00
|
|
|
gRPC listener will require TLS and present the same certificate as the https
|
|
|
|
listener. As with `CONSUL_HTTP_ADDR`, if TLS is enabled either the `https://`
|
2019-05-01 21:11:23 +00:00
|
|
|
scheme should be used, or `CONSUL_HTTP_SSL` set.
|
2020-07-08 14:41:42 +00:00
|
|
|
|
|
|
|
### `CONSUL_NAMESPACE`
|
|
|
|
|
|
|
|
**Enterprise only**
|
2020-07-08 23:09:00 +00:00
|
|
|
If you're using Consul Enterprise namespaces you can set this for the CLI to
|
|
|
|
explicitly use a single namespace. This is common across all Hashicorp
|
2020-07-08 14:41:42 +00:00
|
|
|
products that support Enterprise namespaces.
|
|
|
|
|
|
|
|
```
|
|
|
|
CONSUL_NAMESPACE=default
|
|
|
|
```
|