Initialize a Cluster

This page explains the cockroach init command, which you use to perform a one-time initialization of a new multi-node cluster. For a full walk-through of the cluster startup and initialization process, see one of the Manual Deployment tutorials.

Note:

When starting a single-node cluster, you do not need to use the cockroach init command. You can simply run the cockroach start command without the —join flag to start and initialize the single-node cluster.

Synopsis

Perform a one-time initialization of a cluster:

  1. $ cockroach init <flags>

View help:

  1. $ cockroach init --help

Flags

The cockroach init command supports the following client connection and logging flags.

Client connection

FlagDescription
—hostThe server host and port number to connect to. This can be the address of any node in the cluster. Env Variable: COCKROACH_HOSTDefault: localhost:26257
—port-pThe server port to connect to. Note: The port number can also be specified via —host. Env Variable: COCKROACH_PORTDefault: 26257
—user-uThe SQL user that will own the client session.Env Variable: COCKROACH_USERDefault: root
—insecureUse an insecure connection.Env Variable: COCKROACH_INSECUREDefault: false
—certs-dirThe path to the certificate directory containing the CA and client certificates and client key.Env Variable: COCKROACH_CERTS_DIRDefault: ${HOME}/.cockroach-certs/
—urlA connection URL to use instead of the other arguments.Env Variable: COCKROACH_URLDefault: no URL

See Client Connection Parameters for details.

Logging

By default, the init command logs errors to stderr.

If you need to troubleshoot this command's behavior, you can change its logging behavior.

Examples

These examples assume that nodes have already been started with cockroach start but are waiting to be initialized as a new cluster. For a more detailed walk-through, see one of the Manual Deployment tutorials.

Initialize a Cluster on a Node's Machine

  • SSH to the machine where the node has been started.

  • Make sure the client.root.crt and client.root.key files for the root user are on the machine.

  • 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:

  1. $ cockroach init --certs-dir=certs --host=<address of this node>

At this point, all the nodes complete startup and print helpful details to the standard output, such as the CockroachDB version, the URL for the Admin UI, and the SQL URL for clients.

  • SSH to the machine where the node has been started.

  • Run the cockroach init command with the —host flag set to the address of the current node:

  1. $ cockroach init --insecure --host=<address of this node>

At this point, all the nodes complete startup and print helpful details to the standard output, such as the CockroachDB version, the URL for the Admin UI, and the SQL URL for clients.

Initialize a cluster from another machine

  • Install the cockroach binary on a machine separate from the node.

  • Create a certs directory and copy the CA certificate and the client certificate and key for the root user into the directory.

  • 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 any node:

  1. $ cockroach init --certs-dir=certs --host=<address of any node>

At this point, all the nodes complete startup and print helpful details to the standard output, such as the CockroachDB version, the URL for the Admin UI, and the SQL URL for clients.

  • Install the cockroach binary on a machine separate from the node.

  • Run the cockroach init command with the —host flag set to the address of any node:

  1. $ cockroach init --insecure --host=<address of any node>

At this point, all the nodes complete startup and print helpful details to the standard output, such as the CockroachDB version, the URL for the Admin UI, and the SQL URL for clients.

See also

Was this page helpful?
YesNo