Skip to main content
This page explains the cockroach init , which you use to perform a one-time initialization of a new multi-node cluster. For a full tutorial of the cluster startup and initialization process, see one of the tutorials.
When starting a single-node cluster with , you do not need to use the cockroach init command.

Synopsis

Perform a one-time initialization of a cluster:
View help:

Flags

The cockroach init command supports the following client connection and logging flags.
cockroach init must target one of the nodes that was listed with when starting the cluster. Otherwise, the command will not initialize the cluster correctly.

Client connection

See for details.

Logging

By default, this command logs messages to stderr. This includes events with WARNING and higher. If you need to troubleshoot this command’s behavior, you can .

Examples

Usage of cockroach init assumes that nodes have already been started with and are waiting to be initialized as a new cluster. For a more detailed tutorial, see one of the tutorials.

Initialize a Cluster on a Node’s Machine

  1. SSH to the machine where the node has been started. This must be a node that was listed with when starting the cluster.
  2. Make sure the client.root.crt and client.root.key files for the root user are on the machine.
  3. Run the cockroach init command with the --certs-dir flag set to the directory containing the ca.crt file and the files for the root user, and with the --host flag set to the address of the current node:
    At this point, all the nodes complete startup and print helpful details to the , such as the CockroachDB version, the URL for the DB Console, and the SQL URL for clients.
  4. SSH to the machine where the node has been started. This must be a node that was listed with when starting the cluster.
  5. Run the cockroach init command with the --host flag set to the address of the current node:
    At this point, all the nodes complete startup and print helpful details to the , such as the CockroachDB version, the URL for the DB Console, and the SQL URL for clients.

Initialize a cluster from another machine

  1. on a machine separate from the node.
  2. Create a certs directory and copy the CA certificate and the client certificate and key for the root user into the directory.
  3. Run the cockroach init command with the --certs-dir flag set to the directory containing the ca.crt file and the files for the root user, and with the --host flag set to the address of the node. This must be a node that was listed with when starting the cluster:
    At this point, all the nodes complete startup and print helpful details to the , such as the CockroachDB version, the URL for the DB Console, and the SQL URL for clients.
  4. on a machine separate from the node.
  5. Run the cockroach init command with the --host flag set to the address of the node. This must be a node that was listed with when starting the cluster:
    At this point, all the nodes complete startup and print helpful details to the , such as the CockroachDB version, the URL for the DB Console, and the SQL URL for clients.

See also