2014-07-01 22:02:42 +00:00
---
2020-04-07 18:55:19 +00:00
layout: docs
2022-09-09 18:30:04 +00:00
page_title: Manually Bootstrap a Datacenter
2020-04-07 18:55:19 +00:00
description: >-
2022-09-16 15:28:32 +00:00
Manually bootstrap a datacenter to deploy your Consul servers and join them together for the first time. For Consul v0.4+, we recommend automatic bootstrapping instead.
2014-07-01 22:02:42 +00:00
---
# Manually Bootstrapping a Datacenter
2014-10-19 23:40:10 +00:00
When deploying Consul to a datacenter for the first time, there is an initial
bootstrapping that must be done. As of Consul 0.4, an
2023-01-25 16:52:43 +00:00
[automatic bootstrapping](/consul/docs/install/bootstrapping) is available and is
2014-10-19 23:40:10 +00:00
the recommended approach. However, older versions only support a manual
bootstrap that is documented here.
Generally, the first nodes that are started are the server nodes. Remember that
an agent can run in both client and server mode. Server nodes are responsible
2023-01-25 16:52:43 +00:00
for running the [consensus protocol](/consul/docs/architecture/consensus), and
2014-10-19 23:40:10 +00:00
storing the cluster state. The client nodes are mostly stateless and rely on the
server nodes, so they can be started easily.
Manual bootstrapping requires that the first server that is deployed in a new
2023-01-25 16:52:43 +00:00
datacenter provide the [`-bootstrap` configuration option](/consul/docs/agent/config/cli-flags#_bootstrap).
2015-03-27 17:20:32 +00:00
This option allows the server
2014-10-19 23:40:10 +00:00
to assert leadership of the cluster without agreement from any other server.
This is necessary because at this point, there are no other servers running in
the datacenter! Lets call this first server `Node A`. When starting `Node A`
something like the following will be logged:
2021-07-31 01:37:33 +00:00
```log
2014-10-19 23:40:10 +00:00
2014/02/22 19:23:32 [INFO] consul: cluster leadership acquired
```
Once `Node A` is running, we can start the next set of servers. There is a
2023-01-25 16:52:43 +00:00
[deployment table](/consul/docs/architecture/consensus#deployment_table) that covers various
2015-02-19 22:45:47 +00:00
options, but it is recommended to have 3 or 5 total servers per datacenter. A
2014-10-19 23:40:10 +00:00
single server deployment is _**highly**_ discouraged as data loss is inevitable
in a failure scenario. We start the next servers **without** specifying
`-bootstrap`. This is critical, since only one server should ever be running in
2018-07-26 23:30:24 +00:00
bootstrap mode. Once `Node B` and `Node C` are started, you should see a
2014-07-01 22:02:42 +00:00
message to the effect of:
2021-07-31 01:37:33 +00:00
```log
2014-10-19 23:40:10 +00:00
[WARN] raft: EnableSingleNode disabled, and no known peers. Aborting election.
```
2014-07-01 22:02:42 +00:00
2014-10-19 23:40:10 +00:00
This indicates that the node is not in bootstrap mode, and it will not elect
itself as leader. We can now join these machines together. Since a join
operation is symmetric it does not matter which node initiates it. From
`Node B` and `Node C` you can do the following:
2014-07-01 22:02:42 +00:00
2020-05-19 18:32:38 +00:00
```shell-session
2014-10-19 23:40:10 +00:00
$ consul join <Node A Address>
Successfully joined cluster by contacting 1 nodes.
```
2014-07-01 22:02:42 +00:00
Alternatively, from `Node A` you can do the following:
2020-05-19 18:32:38 +00:00
```shell-session
2014-10-19 23:40:10 +00:00
$ consul join <Node B Address> <Node C Address>
Successfully joined cluster by contacting 2 nodes.
```
2014-07-01 22:02:42 +00:00
Once the join is successful, `Node A` should output something like:
2021-07-31 01:37:33 +00:00
```log
2014-10-19 23:40:10 +00:00
[INFO] raft: Added peer 127.0.0.2:8300, starting replication
....
[INFO] raft: Added peer 127.0.0.3:8300, starting replication
```
2014-07-01 22:02:42 +00:00
As a sanity check, the `consul info` command is a useful tool. It can be used to
2014-10-19 23:40:10 +00:00
verify `raft.num_peers` is now 2, and you can view the latest log index under
`raft.last_log_index`. When running `consul info` on the followers, you should
see `raft.last_log_index` converge to the same value as the leader begins
replication. That value represents the last log entry that has been stored on
disk.
This indicates that `Node B` and `Node C` have been added as peers. At this
point, all three nodes see each other as peers, `Node A` is the leader, and
replication should be working.
The final step is to remove the `-bootstrap` flag. This is important since we
don't want the node to be able to make unilateral decisions in the case of a
failure of the other two nodes. To do this, we send a `SIGINT` to `Node A` to
allow it to perform a graceful leave. Then we remove the `-bootstrap` flag and
restart the node. The node will need to rejoin the cluster, since the graceful
exit leaves the cluster. Any transactions that took place while `Node A` was
offline will be replicated and the node will catch up.
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 be started
and perform a `join` against any existing node. All nodes participate in a
gossip protocol to perform basic discovery, so clients will automatically find
the servers and register themselves.
2020-04-06 20:27:35 +00:00
-> If you accidentally start another server with the flag set, do not fret.
2014-10-19 23:40:10 +00:00
Shutdown the node, and remove the `raft/` folder from the data directory. This
will remove the bad state caused by being in `-bootstrap` mode. Then restart the
2014-07-01 22:02:42 +00:00
node and join the cluster normally.