Key Takeaways
| Task | Description | Example/Command |
|---|---|---|
| Agent Startup | Launch Consul from the CLI or via a JSON/HCL config file | consul agent -dev -bind 192.168.1.10 |
| Configuration Formats | Define common settings, server/client roles, and register services | HCL or JSON snippets |
| Network Binding & Ports | Set bind_addr, and customize RPC, HTTP, and DNS port assignments | bind_addr = "0.0.0.0" |
| Cluster Join & Leave | Add nodes with consul join and gracefully remove them using consul leave | consul join 10.0.0.1 |
Before restarting agents, validate your configuration:
1. Starting and Managing the Consul Process
You can start a Consul agent directly from the command line:consul.hcl):
2. Interpreting Consul Agent Configurations
Both HCL and JSON support the same agent options.Example HCL for a client agent registering a web service:
3. Configuring Network Addresses and Ports
Fine-tune Consul network settings to optimize performance and security:bind_addr: IP/interface for RPC, HTTP, DNSadvertise_addr: Publicly advertised addressports.rpc,ports.http,ports.dns
4. Agent Join and Leave Behaviors
Joining a Cluster
Use theconsul join command to add a new node:
Graceful Leave
For clients and especially servers, remove nodes gracefully to maintain cluster health:Always drain and remove server nodes gracefully to avoid quorum loss.
Use
Use
consul leave rather than killing the process.