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
Copy file name to clipboardexpand all lines: v2.0/secure-a-cluster.md
+39
Original file line number
Diff line number
Diff line change
@@ -30,23 +30,37 @@ Also, feel free to watch this process in action before going through the steps y
30
30
31
31
You can use either `cockroach cert` commands or [`openssl` commands](create-security-certificates-openssl.html) to generate security certificates. This section features the `cockroach cert` commands.
32
32
33
+
{% include copy-clipboard.html %}
33
34
~~~shell
34
35
# Create a certs directory and safe directory for the CA key.
35
36
# If using the default certificate directory (`${HOME}/.cockroach-certs`), make sure it is empty.
36
37
$ mkdir certs
38
+
~~~
39
+
40
+
{% include copy-clipboard.html %}
41
+
~~~
37
42
$ mkdir my-safe-directory
43
+
~~~
38
44
45
+
{% include copy-clipboard.html %}
46
+
~~~shell
39
47
# Create the CA key pair:
40
48
$ cockroach cert create-ca \
41
49
--certs-dir=certs \
42
50
--ca-key=my-safe-directory/ca.key
51
+
~~~
43
52
53
+
{% include copy-clipboard.html %}
54
+
~~~shell
44
55
# Create a client key pair for the root user:
45
56
$ cockroach cert create-client \
46
57
root \
47
58
--certs-dir=certs \
48
59
--ca-key=my-safe-directory/ca.key
60
+
~~~
49
61
62
+
{% include copy-clipboard.html %}
63
+
~~~shell
50
64
# Create a key pair for the nodes:
51
65
$ cockroach cert create-node \
52
66
localhost \
@@ -62,6 +76,7 @@ $(hostname) \
62
76
63
77
## Step 2. Start the first node
64
78
79
+
{% include copy-clipboard.html %}
65
80
~~~shell
66
81
$ cockroach start \
67
82
--certs-dir=certs \
@@ -95,6 +110,7 @@ At this point, your cluster is live and operational. With just one node, you can
95
110
96
111
In a new terminal, add the second node:
97
112
113
+
{% include copy-clipboard.html %}
98
114
~~~shell
99
115
$ cockroach start \
100
116
--certs-dir=certs \
@@ -108,6 +124,7 @@ $ cockroach start \
108
124
109
125
In a new terminal, add the third node:
110
126
127
+
{% include copy-clipboard.html %}
111
128
~~~shell
112
129
$ cockroach start \
113
130
--certs-dir=certs \
@@ -127,6 +144,7 @@ Now that you've scaled to 3 nodes, you can use any node as a SQL gateway to the
127
144
128
145
{{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}}
129
146
147
+
{% include copy-clipboard.html %}
130
148
~~~shell
131
149
$ cockroach sql \
132
150
--certs-dir=certs
@@ -137,13 +155,23 @@ $ cockroach sql \
137
155
138
156
Run some basic [CockroachDB SQL statements](learn-cockroachdb-sql.html):
139
157
158
+
{% include copy-clipboard.html %}
140
159
~~~sql
141
160
> CREATE DATABASE bank;
161
+
~~~
142
162
163
+
{% include copy-clipboard.html %}
164
+
~~~sql
143
165
> CREATE TABLE bank.accounts (id INTPRIMARY KEY, balance DECIMAL);
166
+
~~~
144
167
168
+
{% include copy-clipboard.html %}
169
+
~~~sql
145
170
>INSERT INTObank.accountsVALUES (1, 1000.50);
171
+
~~~
146
172
173
+
{% include copy-clipboard.html %}
174
+
~~~sql
147
175
>SELECT*FROMbank.accounts;
148
176
~~~
149
177
@@ -158,12 +186,14 @@ Run some basic [CockroachDB SQL statements](learn-cockroachdb-sql.html):
158
186
159
187
Exit the SQL shell on node 1:
160
188
189
+
{% include copy-clipboard.html %}
161
190
~~~sql
162
191
> \q
163
192
~~~
164
193
165
194
Then connect the SQL shell to node 2, this time specifying the node's non-default port:
166
195
196
+
{% include copy-clipboard.html %}
167
197
~~~shell
168
198
$ cockroach sql \
169
199
--certs-dir=certs \
@@ -177,6 +207,7 @@ $ cockroach sql \
177
207
178
208
Now run the same `SELECT` query:
179
209
210
+
{% include copy-clipboard.html %}
180
211
~~~sql
181
212
>SELECT*FROMbank.accounts;
182
213
~~~
@@ -194,6 +225,7 @@ As you can see, node 1 and node 2 behaved identically as SQL gateways.
194
225
195
226
Exit the SQL shell on node 2:
196
227
228
+
{% include copy-clipboard.html %}
197
229
~~~sql
198
230
> \q
199
231
~~~
@@ -222,6 +254,7 @@ Once you're done with your test cluster, switch to the terminal running the firs
222
254
223
255
At this point, with 2 nodes still online, the cluster remains operational because a majority of replicas are available. To verify that the cluster has tolerated this "failure", connect the built-in SQL shell to nodes 2 or 3. You can do this in the same terminal or in a new terminal.
224
256
257
+
{% include copy-clipboard.html %}
225
258
~~~shell
226
259
$ cockroach sql \
227
260
--certs-dir=certs \
@@ -231,6 +264,7 @@ $ cockroach sql \
231
264
# To exit: CTRL + D.
232
265
~~~
233
266
267
+
{% include copy-clipboard.html %}
234
268
~~~sql
235
269
>SELECT*FROMbank.accounts;
236
270
~~~
@@ -246,6 +280,7 @@ $ cockroach sql \
246
280
247
281
Exit the SQL shell:
248
282
283
+
{% include copy-clipboard.html %}
249
284
~~~sql
250
285
> \q
251
286
~~~
@@ -256,6 +291,7 @@ Now stop nodes 2 and 3 by switching to their terminals and pressing **CTRL-C**.
256
291
257
292
If you don't plan to restart the cluster, you may want to remove the nodes' data stores:
258
293
294
+
{% include copy-clipboard.html %}
259
295
~~~shell
260
296
$ rm -rf cockroach-data node2 node3
261
297
~~~
@@ -266,6 +302,7 @@ If you decide to use the cluster for further testing, you'll need to restart at
266
302
267
303
Restart the first node from the parent directory of `cockroach-data/`:
268
304
305
+
{% include copy-clipboard.html %}
269
306
~~~shell
270
307
$ cockroach start \
271
308
--certs-dir=certs \
@@ -278,6 +315,7 @@ $ cockroach start \
278
315
279
316
In a new terminal, restart the second node from the parent directory of `node2/`:
280
317
318
+
{% include copy-clipboard.html %}
281
319
~~~shell
282
320
$ cockroach start \
283
321
--certs-dir=certs \
@@ -291,6 +329,7 @@ $ cockroach start \
291
329
292
330
In a new terminal, restart the third node from the parent directory of `node3/`:
0 commit comments