Bootstrapping a Datacenter

    Before a Consul cluster can begin to service requests, a server node must be elected leader. Bootstrapping is the process of joining these initial server nodes into a cluster. Read the architecture documentation to learn more about the internals of Consul.

    It is recommended to have three or five total servers per datacenter. A single server deployment is highly discouraged as data loss is inevitable in a failure scenario. Please refer to the for more detail.

    Note: In versions of Consul prior to 0.4, bootstrapping was a manual process. For details on using the flag directly, see the manual bootstrapping documentation. Manual bootstrapping with -bootstrap is not recommended in newer versions of Consul (0.5 and newer) as it is more error-prone. Instead you should use automatic bootstrapping with .

    The recommended way to bootstrap the servers is to use the -bootstrap-expect configuration option. This option informs Consul of the expected number of server nodes and automatically bootstraps when that many servers are available. To prevent inconsistencies and split-brain (clusters where multiple servers consider themselves leader) situations, you should either specify the same value for or specify no value at all on all the servers. Only servers that specify a value will attempt to bootstrap the cluster.

    The warning indicates that the nodes are expecting 2 peers but none are known yet. Below you will learn how to connect the servers so that one can be elected leader.

    Creating the Cluster

    You can trigger leader election by joining the servers together, to create a cluster. You can either configure the nodes to join automatically or manually.

    There are multiple options for joining the servers. Choose the method which best suits your environment and specific use case.

    • Specify a list of servers with option.
    • Use automatic joining by tag for supported cloud environments with the -retry-join option.

    All three methods can be set in the agent configuration file or the command line flag.

    Since a join operation is symmetric, it does not matter which node initiates it. Once the join is successful, one of the nodes will output something like:

    As a sanity check, the command is a useful tool. It can be used to verify the raft.num_peers and to view the latest log index under raft.last_log_index. When running consul info on the followers, you should see 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, you can join the clients with the same join method you used for the servers. Clients are much easier as they can join against any existing node. All nodes participate in a gossip 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.