Skip to content

Commit 129a842

Browse files
author
Jesse Seldess
committed
Surface core value props in start a cluster
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 #1191 Fixes #1252
1 parent 87f0934 commit 129a842

File tree

3 files changed

+99
-53
lines changed

3 files changed

+99
-53
lines changed

images/admin_ui.png

-9 KB
Loading

images/admin_ui_replicas.png

101 KB
Loading

start-a-local-cluster.md

Lines changed: 99 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ toc_not_nested: true
66
asciicast: true
77
---
88

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 youve [installed CockroachDB](install-cockroachdb.html), its simple to start a multi-node cluster locally with each node listening on a different port.
1010

1111
{{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 <a href="manual-deployment.html">Manual Deployment</a>, <a href="cloud-deployment.html">Cloud Deployment</a>, or <a href="orchestration.html">Orchestration</a>.{{site.data.alerts.end}}
1212

@@ -20,7 +20,7 @@ Also, feel free to watch this process in action before going through the steps y
2020

2121
<asciinema-player class="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>
2222

23-
## Step 1. Start your first node
23+
## Step 1. Start the first node
2424

2525
~~~ shell
2626
$ cockroach start --background
@@ -40,84 +40,82 @@ nodeID: 1
4040

4141
This command starts a node, accepting all [`cockroach start`](start-a-node.html) defaults.
4242

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.
5045
- 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.
5147

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 <a href="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}}
5549

5650
## Step 2. Add nodes to the cluster
5751

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+
5856
~~~ shell
59-
# Start your second node:
57+
# Start the second node:
6058
$ cockroach start --background \
6159
--store=node2 \
6260
--port=26258 \
6361
--http-port=8081 \
6462
--join=localhost:26257
6563

66-
# Start your third node:
64+
# Start the third node:
6765
$ cockroach start --background \
6866
--store=node3 \
6967
--port=26259 \
7068
--http-port=8082 \
7169
--join=localhost:26257
7270
~~~
7371

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.
8373

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 <a href="configure-replication-zones.html">replication zone</a> to specify one node instead of three. See <a href="troubleshoot.html#replication-error-in-a-single-node-cluster">here</a> for more details.{{site.data.alerts.end}}
74+
## Step 3. Test the cluster
8575

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):
8777

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}}
8979

9080
~~~ shell
91-
$ cockroach sql
81+
$ cockroach sql --port=26257
9282
# Welcome to the cockroach SQL interface.
9383
# All statements must be terminated by a semicolon.
9484
# To exit: CTRL + D.
9585
~~~
9686

97-
Then run some [CockroachDB SQL statements](learn-cockroachdb-sql.html):
98-
9987
~~~ sql
10088
> CREATE DATABASE bank;
101-
~~~
10289

103-
~~~
104-
CREATE DATABASE
105-
~~~
106-
107-
~~~ sql
10890
> CREATE TABLE bank.accounts (id INT PRIMARY KEY, balance DECIMAL);
91+
92+
> INSERT INTO bank.accounts VALUES (1, 1000.50);
93+
94+
> SELECT * FROM bank.accounts;
10995
~~~
11096

11197
~~~
112-
CREATE TABLE
98+
+----+---------+
99+
| id | balance |
100+
+----+---------+
101+
| 1 | 1000.5 |
102+
+----+---------+
103+
(1 row)
113104
~~~
114105

106+
Exit the SQL shell on node 1:
107+
115108
~~~ sql
116-
> INSERT INTO bank.accounts VALUES (1, 1000.50);
109+
> \q
117110
~~~
118111

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.
121119
~~~
122120

123121
~~~ sql
@@ -133,38 +131,86 @@ INSERT 1
133131
(1 row)
134132
~~~
135133

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.
137135

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+
~~~
139141

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
141143

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

144146
<img src="images/admin_ui.png" alt="CockroachDB Admin UI" style="border:1px solid #eee;max-width:100%" />
145147

148+
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:
149+
150+
<img src="images/admin_ui_replicas.png" alt="CockroachDB Admin UI" style="border:1px solid #eee;max-width:100%" />
151+
152+
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 <a href="demo-data-replication.html">replication</a>, <a href="demo-automatic-rebalancing.html">rebalancing</a>, <a href="demo-fault-tolerance-and-recovery.html">fault tolerance</a> demos.{{site.data.alerts.end}}
155+
146156
## Step 5. Stop the cluster
147157

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

150160
~~~ shell
151-
# Stop node 1:
152161
$ 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 * FROM bank.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:
153187

154-
# Stop node 2:
188+
~~~
155189
$ 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:
156193

157-
# Stop node 3:
158-
$ cockroach quit --port=26259
194+
~~~ shell
195+
# Get the process ID for node 3:
196+
$ ps | grep cockroach
159197
~~~
160198

161-
For more details about the `cockroach quit` command, see [Stop a Node](stop-a-node.html).
199+
~~~
200+
5084 ttys001 0:50.15 cockroach start --store=node3 --port=26259 --http-port=8082 --join=localhost:26257
201+
~~~
202+
203+
~~~ shell
204+
# Force quit the process:
205+
$ kill -9 5084
206+
~~~
162207

163208
## What's Next?
164209

165210
[Secure your cluster](secure-a-cluster.html) with authentication and encryption. You might also be interested in:
166211

167-
- [Manual Deployment](manual-deployment.html): How to run CockroachDB across multiple machines
168-
- [Cloud Deployment](cloud-deployment.html): How to run CockroachDB in the cloud
169-
- [Orchestration](orchestration.html): How to further automate CockroachDB with orchestration tools
170-
- [Import Data](import-data.html): How to import data from your application's current database
212+
- [Explore Core Feature](demo-data-replication.html)
213+
- [Manual Deployment](manual-deployment.html)
214+
- [Cloud Deployment](cloud-deployment.html)
215+
- [Orchestration](orchestration.html)
216+
- [Import Data](import-data.html)

0 commit comments

Comments
 (0)