> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Objective 2 Section Recap

> This article reviews the steps to install, configure, and manage Consul agents in server and client modes.

In this section, we reviewed the essential steps to install, configure, and operate Consul agents in both **server** and **client** modes.

## 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`                 |

<Callout icon="lightbulb" color="#1CB2FE">
  Before restarting agents, validate your configuration:

  ```bash theme={null}
  consul validate /path/to/config.hcl
  ```
</Callout>

***

## 1. Starting and Managing the Consul Process

You can start a Consul agent directly from the command line:

```bash theme={null}
consul agent \
  -dev \
  -bind 192.168.1.10 \
  -config-dir /etc/consul.d
```

Or use an HCL/JSON configuration file (`consul.hcl`):

```hcl theme={null}
datacenter       = "dc1"
node_name        = "consul-server-1"
server           = true
bootstrap_expect = 3
bind_addr        = "0.0.0.0"

ports {
  http = 8500
  rpc  = 8400
  dns  = 8600
}
```

***

## 2. Interpreting Consul Agent Configurations

Both HCL and JSON support the same agent options.\
Example HCL for a **client** agent registering a web service:

```hcl theme={null}
service {
  name = "web"
  port = 80
  tags = ["nginx", "frontend"]
}
```

## 3. Configuring Network Addresses and Ports

Fine-tune Consul network settings to optimize performance and security:

* `bind_addr`: IP/interface for RPC, HTTP, DNS
* `advertise_addr`: Publicly advertised address
* `ports.rpc`, `ports.http`, `ports.dns`

```hcl theme={null}
bind_addr = "10.0.0.5"
advertise_addr = "203.0.113.10"

ports {
  http = 8500
  rpc  = 8400
  dns  = 8600
}
```

***

## 4. Agent Join and Leave Behaviors

### Joining a Cluster

Use the `consul join` command to add a new node:

```bash theme={null}
consul join 10.0.0.1 10.0.0.2
```

### Graceful Leave

For clients and especially servers, remove nodes gracefully to maintain cluster health:

```bash theme={null}
consul leave
```

<Callout icon="triangle-alert" color="#FF6B6B">
  Always drain and remove server nodes gracefully to avoid quorum loss.\
  Use `consul leave` rather than killing the process.
</Callout>

***

## Next Steps

Move on to **Objective 3: Service Discovery & Health Checking** to learn how Consul automatically tracks and verifies service health.

## Links and References

* [Consul Official Documentation](https://www.consul.io/docs)
* [HashiCorp Configuration Language (HCL)](https://github.com/hashicorp/hcl)
* [Consul Agent Configuration Options](https://www.consul.io/docs/agent/options)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/hashicorp-certified-consul-associate-certification/module/a1f79019-1fbb-4b11-8935-0f09bdc9da3c/lesson/29a2efee-b387-4212-b0ff-28e97dab4ec5" />
</CardGroup>
