命令行 (CLI)
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.
The consul
CLI is a well-behaved command line application. In erroneous 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 "-" as a parameter to tell Consul to read the input from stdin.
To view a list of the available commands at any time, just run consul
with no arguments:
To get help for any specific command, pass the -h
flag to the relevant subcommand. For example, to see help about the join
subcommand:
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:
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:
CONSUL_HTTP_ADDR
CONSUL_HTTP_ADDR
This is the HTTP API address to the local Consul agent (not the remote server) specified as a URI with optional scheme:
or as a Unix socket path:
If the https://
scheme is used, CONSUL_HTTP_SSL
is implied to be true.
CONSUL_HTTP_TOKEN
CONSUL_HTTP_TOKEN
This is the API access token required when access control lists (ACLs) are enabled, for example:
CONSUL_HTTP_AUTH
CONSUL_HTTP_AUTH
This specifies HTTP Basic access credentials as a username:password pair:
»CONSUL_HTTP_SSL
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_VERIFY
CONSUL_HTTP_SSL_VERIFY
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:
CONSUL_CACERT
CONSUL_CACERT
Path to a CA file to use for TLS when communicating with Consul.
CONSUL_CAPATH
CONSUL_CAPATH
Path to a directory of CA certificates to use for TLS when communicating with Consul.
CONSUL_CLIENT_CERT
CONSUL_CLIENT_CERT
Path to a client cert file to use for TLS when verify_incoming
is enabled.
CONSUL_CLIENT_KEY
CONSUL_CLIENT_KEY
Path to a client key file to use for TLS when verify_incoming
is enabled.
CONSUL_TLS_SERVER_NAME
CONSUL_TLS_SERVER_NAME
The server name to use as the SNI host when connecting via TLS.
CONSUL_GRPC_ADDR
CONSUL_GRPC_ADDR
Like CONSUL_HTTP_ADDR
but configures the address the local agent is listening for gRPC requests. Currently gRPC is only used for integrating Envoy proxy and must be enabled explicitly in agent configuration.
or as a Unix socket path:
If the agent is configured with TLS certificates, then the 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://
scheme should be used, or CONSUL_HTTP_SSL
set.
Last updated