2014-02-23 05:08:36 +00:00
---
layout: "docs"
page_title: "Bootstrapping"
sidebar_current: "docs-guides-bootstrapping"
2014-10-19 23:40:10 +00:00
description: |-
2017-04-13 17:03:26 +00:00
An agent can run in both client and server mode. Server nodes are responsible for running the consensus protocol and storing the cluster state. Before a Consul cluster can begin to service requests, a server node must be elected leader. Thus, the first nodes that are started are generally the server nodes. Bootstrapping is the process of joining these server nodes into a cluster.
2014-02-23 05:08:36 +00:00
---
# Bootstrapping a Datacenter
2015-02-23 04:19:11 +00:00
An agent can run in both client and server mode. Server nodes are responsible for running the
[consensus protocol ](/docs/internals/consensus.html ) and storing the cluster state.
The client nodes are mostly stateless and rely heavily on the server nodes.
Before a Consul cluster can begin to service requests, a server node must be elected leader.
Thus, the first nodes that are started are generally the server nodes. Bootstrapping is the process
2015-03-05 00:12:14 +00:00
of joining these initial server nodes into a cluster.
2014-02-23 05:08:36 +00:00
2015-02-24 19:11:11 +00:00
The recommended way to bootstrap is to use the [`-bootstrap-expect` ](/docs/agent/options.html#_bootstrap_expect )
configuration option. This option informs Consul of the expected number of
2015-02-23 04:19:11 +00:00
server nodes and automatically bootstraps when that many servers are available. To prevent
inconsistencies and split-brain situations (that is, clusters where multiple servers consider
2015-02-24 19:11:11 +00:00
themselves leader), all servers should either specify the same value for
[`-bootstrap-expect` ](/docs/agent/options.html#_bootstrap_expect )
2015-02-23 04:19:11 +00:00
or specify no value at all. Only servers that specify a value will attempt to bootstrap the cluster.
2014-02-23 05:08:36 +00:00
2015-02-23 04:19:11 +00:00
We recommend 3 or 5 total servers per datacenter. A single server deployment is _**highly**_ discouraged
as data loss is inevitable in a failure scenario. Please refer to the
2016-12-06 05:10:40 +00:00
[deployment table ](/docs/internals/consensus.html#deployment-table ) for more detail.
2014-02-23 05:08:36 +00:00
2015-02-23 04:19:11 +00:00
Suppose we are starting a 3 server cluster. We can start `Node A` , `Node B` , and `Node C` with each
providing the `-bootstrap-expect 3` flag. Once the nodes are started, you should see a message like:
2014-02-23 05:08:36 +00:00
2014-10-19 23:40:10 +00:00
```text
[WARN] raft: EnableSingleNode disabled, and no known peers. Aborting election.
```
2014-02-23 05:08:36 +00:00
2015-05-12 19:54:32 +00:00
This indicates that the nodes are expecting 2 peers but none are known yet. To prevent a split-brain
2015-02-23 04:19:11 +00:00
scenario, the servers will not elect themselves leader.
2017-04-13 17:03:26 +00:00
## Creating the cluster
2015-02-23 04:19:11 +00:00
2017-04-13 17:03:26 +00:00
To trigger leader election, we must join these machines together and create a cluster. There are multiple options for joining the machines:
2015-03-05 00:12:14 +00:00
2017-04-13 17:03:26 +00:00
- Manually specified list of machines with
[-join ](/docs/agent/options.html#_join ) and
[start_join ](https://www.consul.io/docs/agent/options.html#start_join )
options
- Manually specified list of machines with [-retry-join ](https://www.consul.io/docs/agent/options.html#_retry_join ) option
- Automatic AWS EC2 instance joining with the [-retry-join-ec2-* ](https://www.consul.io/docs/agent/options.html#_retry_join_ec2_tag_key ) options
- Automatic GCE instance joining with the [-retry-join-gce-* ](https://www.consul.io/docs/agent/options.html#_retry_join_gce_tag_value ) options
2015-03-05 00:12:14 +00:00
2017-04-13 17:03:26 +00:00
Choose the method which best suits your environment and specific use case.
2015-03-05 00:12:14 +00:00
2017-04-13 17:03:26 +00:00
~> **Notice:** The hosted version of Consul Enterprise was deprecated on
March 7th, 2017 and the Atlas `auto-join` feature is no longer available. For details, see https://atlas.hashicorp.com/help/consul/alternatives.
2014-02-23 05:08:36 +00:00
2017-04-13 17:03:26 +00:00
## Verifying the Cluster
2014-02-23 05:08:36 +00:00
2016-11-25 16:00:02 +00:00
As a sanity check, the [`consul info` ](/docs/commands/info.html ) command
is a useful tool. It can be used to verify `raft.num_peers` is now 2,
2016-11-25 18:25:09 +00:00
and you can view the latest log index under `raft.last_log_index` . When
2016-11-25 16:00:02 +00:00
running [`consul info` ](/docs/commands/info.html ) on the followers, you
should see `raft.last_log_index` converge to the same value once the
leader begins replication. That value represents the last log entry that
has been stored on disk.
Now that the servers are all started and replicating to each other, all
the remaining clients can be joined. Clients are much easier as they can
2016-11-25 18:25:09 +00:00
join against any existing node. All nodes participate in a gossip
2016-11-25 16:00:02 +00:00
protocol to perform basic discovery, so once joined to any member of the
cluster, new clients will automatically find the servers and register
themselves.
-> **Note:** It is not strictly necessary to start the server nodes before the clients; however, most operations will fail until the servers are available.
2014-07-01 22:02:26 +00:00
## Manual Bootstrapping
2015-02-23 04:19:11 +00:00
In versions of Consul prior to 0.4, bootstrapping was a more manual process. For details on
2015-02-24 19:11:11 +00:00
using the [`-bootstrap` ](/docs/agent/options.html#_bootstrap ) flag directly, see the
[manual bootstrapping guide ](/docs/guides/manual-bootstrap.html ).
2014-07-01 22:02:26 +00:00
2015-02-23 04:19:11 +00:00
Manual bootstrapping is not recommended as it is more error-prone than automatic bootstrapping
2015-02-24 19:11:11 +00:00
with [`-bootstrap-expect` ](/docs/agent/options.html#_bootstrap_expect ).