You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
These changes attempt to keep the Start a Cluster tutorial
quick and easy while introducing new users to what makes
CockroachDB unique, not just ease of deployment, but also
automated replication and survival.
I've also stripped out some details that I think are not
important to the majority of users getting up and running
for the first time, e.g., how to customize `start` flags
and the fact that you can use third-party monitoring.
Finally, I've update the Stop the Cluster step to account
for the fact that `cockroach quit` can't be used to stop
nodes once quorum is lost.
Fixes#1191Fixes#1252
Copy file name to clipboardExpand all lines: start-a-local-cluster.md
+99-53Lines changed: 99 additions & 53 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ toc_not_nested: true
6
6
asciicast: true
7
7
---
8
8
9
-
Once you've [installed the CockroachDB binary](install-cockroachdb.html), it's simple to start a multi-node cluster locally with each node listening on a different port.
9
+
Once you’ve [installed CockroachDB](install-cockroachdb.html), it’s simple to start a multi-node cluster locally with each node listening on a different port.
10
10
11
11
{{site.data.alerts.callout_info}}Running multiple nodes on a single host is useful for testing out CockroachDB, but it's not recommended for production deployments. To run a physically distributed cluster in production, see <ahref="manual-deployment.html">Manual Deployment</a>, <ahref="cloud-deployment.html">Cloud Deployment</a>, or <ahref="orchestration.html">Orchestration</a>.{{site.data.alerts.end}}
12
12
@@ -20,7 +20,7 @@ Also, feel free to watch this process in action before going through the steps y
20
20
21
21
<asciinema-playerclass="asciinema-demo"src="asciicasts/start-a-local-cluster.json"cols="107"speed="2"theme="monokai"poster="npt:0:30"title="Start a Local Cluster"></asciinema-player>
22
22
23
-
## Step 1. Start your first node
23
+
## Step 1. Start the first node
24
24
25
25
~~~shell
26
26
$ cockroach start --background
@@ -40,84 +40,82 @@ nodeID: 1
40
40
41
41
This command starts a node, accepting all [`cockroach start`](start-a-node.html) defaults.
42
42
43
-
- Communication is insecure, with the server listening only on `localhost` on port `26257` for internal and client communication and on port `8080` for HTTP requests from the Admin UI.
44
-
- To bind to different ports, set `--port=<port>` and `--http-port=<port>`.
45
-
- To bind the Admin UI to a private IP address or host, set `--http-host=<private-addr>`.
46
-
- To listen on an external hostname or IP address, set `--insecure` and `--host=<external address>`. For a demonstration, see [Manual Deployment](manual-deployment.html).
47
-
48
-
- Node data is stored in the `cockroach-data` directory. To store data in a different location, set `--store=<filepath>`. To use multiple stores, set this flag separately for each.
49
-
43
+
- Communication is insecure, with the node listening on `localhost` on port `26257` for internal and client traffic and on port `8080` for HTTP requests from the Admin UI.
44
+
- Node data is stored in the `cockroach-data` directory.
50
45
- The `--background` flag runs the node in the background so you can continue the next steps in the same shell.
46
+
- The [standard output](start-a-node.html#standard-output) gives you helpful details such as the CockroachDB version, the URL for the admin UI, and the SQL URL for clients.
51
47
52
-
- The [standard output](start-a-node.html#standard-output) gives you a helpful summary: the CockroachDB version; the URL for the admin UI; the SQL URL for your client code; the storage locations for node and debug log data; whether the node is the first in the cluster, joined an existing cluster for the first time, or rejoined an existing cluster; the cluster ID; and the node ID.
53
-
54
-
{{site.data.alerts.callout_success}}By default, each node's cache is limited to 25% of available memory. This default is reasonable when running one node per host. When running multiple nodes on a single host, however, it may lead to out of memory errors, especially when testing against the cluster in a serious way. To avoid such errors, you can manually limit each node's cache size by setting the <ahref="start-a-node.html#flags"><code>--cache</code></a> flag in the <code>start</code> command.{{site.data.alerts.end}}
48
+
{{site.data.alerts.callout_success}}By default, each node's cache is limited to 25% of available memory. This default is reasonable when running one node per host. When you run multiple nodes on a single host, however, this default may lead to out of memory errors, especially if you test in a serious way. To avoid such errors, you can limit each node's cache size by setting the <code>--cache</code> flag in the <code>start</code> command.{{site.data.alerts.end}}
55
49
56
50
## Step 2. Add nodes to the cluster
57
51
52
+
At this point, your cluster is live and operational. With just one node, you can already connect a SQL client and start building out your database. In real deployments, however, you'll always want 3 or more nodes to take advantage of CockroachDB's [automatic replication](demo-data-replication.html), [rebalancing](demo-automatic-rebalancing.html), and [fault tolerance](demo-fault-tolerance-and-recovery.html) capabilities.
53
+
54
+
To simulate a real deployment, scale your cluster by adding two more nodes:
55
+
58
56
~~~shell
59
-
# Start your second node:
57
+
# Start the second node:
60
58
$ cockroach start --background \
61
59
--store=node2 \
62
60
--port=26258 \
63
61
--http-port=8081 \
64
62
--join=localhost:26257
65
63
66
-
# Start your third node:
64
+
# Start the third node:
67
65
$ cockroach start --background \
68
66
--store=node3 \
69
67
--port=26259 \
70
68
--http-port=8082 \
71
69
--join=localhost:26257
72
70
~~~
73
71
74
-
These commands add two nodes to the cluster, but you can add as many as you like. For each node:
75
-
76
-
- Set the `--store` flag to a storage location not in use by other nodes. To use multiple stores, set this flag separately for each.
77
-
78
-
- Set the `--port` and `--http-port` flags to ports not in use by other nodes.
79
-
80
-
- The `--join` flag connects the new node to the cluster. Set this flag to `localhost` and the port of the first node.
81
-
82
-
- The `--background` flag runs the node in the background so you can continue the next steps in the same shell.
72
+
The main difference here is that you use the `--join` flag to connect the new nodes to the cluster, specifying the address and port of the first node. Since you're running all nodes on the same machine, you also set the `--store`, `--port`, and `--http-port` flags to locations and ports not used by other nodes, but in a real deployment, with each node on a different machine, the defaults would suffice.
83
73
84
-
{{site.data.alerts.callout_success}}If you don't plan to use more than one node, you can avoid unnecessary log messages about replication by editing the default <ahref="configure-replication-zones.html">replication zone</a> to specify one node instead of three. See <ahref="troubleshoot.html#replication-error-in-a-single-node-cluster">here</a> for more details.{{site.data.alerts.end}}
74
+
## Step 3. Test the cluster
85
75
86
-
## Step 3. Use the built-in SQL client
76
+
Now that you've scaled to 3 nodes, you can use any node as a SQL gateway to the cluster. To demonstrate this, start the [built-in SQL cleint](use-the-built-in-sql-client.html) on node 1 and run some basic [CockroachDB SQL statements](learn-cockroachdb-sql.html):
87
77
88
-
Start the [built-in SQL shell](use-the-built-in-sql-client.html) on node 1:
78
+
{{site.data.alerts.callout_info}}The SQL client is built into the <code>cockroach</code> binary, so nothing extra is needed.{{site.data.alerts.end}}
89
79
90
80
~~~shell
91
-
$ cockroach sql
81
+
$ cockroach sql --port=26257
92
82
# Welcome to the cockroach SQL interface.
93
83
# All statements must be terminated by a semicolon.
94
84
# To exit: CTRL + D.
95
85
~~~
96
86
97
-
Then run some [CockroachDB SQL statements](learn-cockroachdb-sql.html):
98
-
99
87
~~~sql
100
88
> CREATE DATABASE bank;
101
-
~~~
102
89
103
-
~~~
104
-
CREATE DATABASE
105
-
~~~
106
-
107
-
~~~sql
108
90
> CREATE TABLE bank.accounts (id INTPRIMARY KEY, balance DECIMAL);
91
+
92
+
>INSERT INTObank.accountsVALUES (1, 1000.50);
93
+
94
+
>SELECT*FROMbank.accounts;
109
95
~~~
110
96
111
97
~~~
112
-
CREATE TABLE
98
+
+----+---------+
99
+
| id | balance |
100
+
+----+---------+
101
+
| 1 | 1000.5 |
102
+
+----+---------+
103
+
(1 row)
113
104
~~~
114
105
106
+
Exit the SQL shell on node 1:
107
+
115
108
~~~sql
116
-
>INSERT INTObank.accountsVALUES (1, 1000.50);
109
+
>\q
117
110
~~~
118
111
119
-
~~~
120
-
INSERT 1
112
+
Then start the SQL shell on node 2 and run the same `SELECT` query:
113
+
114
+
~~~shell
115
+
$ cockroach sql --port=26258
116
+
# Welcome to the cockroach SQL interface.
117
+
# All statements must be terminated by a semicolon.
118
+
# To exit: CTRL + D.
121
119
~~~
122
120
123
121
~~~sql
@@ -133,38 +131,86 @@ INSERT 1
133
131
(1 row)
134
132
~~~
135
133
136
-
When you're done, use **CTRL + D**, **CTRL + C**, or `\q` to exit the SQL shell.
134
+
As you can see, node 1 and node 2 behaved identically as SQL gateways.
137
135
138
-
## Step 4. Open the Admin UI
136
+
When you're done, exit the SQL shell on node 2:
137
+
138
+
~~~sql
139
+
> \q
140
+
~~~
139
141
140
-
The CockroachDB [Admin UI](explore-the-admin-ui.html) lets you monitor cluster-wide, node-level, and database-level metrics and events. To start up the Admin UI, point your browser to `http://localhost:8080`. You can also find the address in the `admin` field in the standard output of any node on startup.
142
+
## Step 4. Monitor the cluster
141
143
142
-
{% include prometheus-callout.html %}
144
+
To access the [Admin UI](explore-the-admin-ui.html) for your cluster, point a browser to `http://localhost:8080`, or to the address in the `admin` field in the standard output of any node on startup:
As mentioned earlier, CockroachDB automatically replicates your data behind-the-scenes. To verify that data written in the previous step was replicated successfully, scroll down to the **Replicas per Store** graph and hover over the line:
As you can see, the replica count on each node is identical, indicating that all data in the cluster was replicated 3 times (the default).
153
+
154
+
{{site.data.alerts.callout_success}}For more insight into how CockroachDB automatically replicates and rebalances data, and tolerates and recovers from failures, see our <ahref="demo-data-replication.html">replication</a>, <ahref="demo-automatic-rebalancing.html">rebalancing</a>, <ahref="demo-fault-tolerance-and-recovery.html">fault tolerance</a> demos.{{site.data.alerts.end}}
155
+
146
156
## Step 5. Stop the cluster
147
157
148
-
You can stop the nodes (and therefore the cluster) as follows:
158
+
Once you're done with your test cluster, stop the first node:
149
159
150
160
~~~shell
151
-
# Stop node 1:
152
161
$ cockroach quit
162
+
~~~
163
+
164
+
With 2 nodes still online, the cluster remains operational because a majority of replicas are still available. You can verify that the cluster has tolerated this "failure" by starting the built-in SQL shell on nodes 2 or 3:
165
+
166
+
~~~shell
167
+
$ cockroach sql --port=26258
168
+
# Welcome to the cockroach SQL interface.
169
+
# All statements must be terminated by a semicolon.
170
+
# To exit: CTRL + D.
171
+
~~~
172
+
173
+
~~~sql
174
+
>SELECT*FROMbank.accounts;
175
+
~~~
176
+
177
+
~~~
178
+
+----+---------+
179
+
| id | balance |
180
+
+----+---------+
181
+
| 1 | 1000.5 |
182
+
+----+---------+
183
+
(1 row)
184
+
~~~
185
+
186
+
Now stop the second node:
153
187
154
-
# Stop node 2:
188
+
~~~
155
189
$ cockroach quit --port=26258
190
+
~~~
191
+
192
+
With only 1 node online, a majority of replicas are no longer available, and so the cluster is not operational. As a result, you can't use `cockroach quit` to stop the last node, but instead must get the node's process ID and then force kill it:
156
193
157
-
# Stop node 3:
158
-
$ cockroach quit --port=26259
194
+
~~~shell
195
+
# Get the process ID for node 3:
196
+
$ ps | grep cockroach
159
197
~~~
160
198
161
-
For more details about the `cockroach quit` command, see [Stop a Node](stop-a-node.html).
0 commit comments