Skip to content

Commit 2926b0c

Browse files
authored
tiup: add --user (#15664)
1 parent d3d4c18 commit 2926b0c

File tree

2 files changed

+13
-77
lines changed

2 files changed

+13
-77
lines changed

production-deployment-using-tiup.md

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
3131

3232
1. 执行如下命令安装 TiUP 工具:
3333

34-
{{< copyable "shell-regular" >}}
35-
3634
```shell
3735
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
3836
```
@@ -41,41 +39,31 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
4139

4240
1. 重新声明全局环境变量:
4341

44-
{{< copyable "shell-regular" >}}
45-
4642
```shell
4743
source .bash_profile
4844
```
4945

5046
2. 确认 TiUP 工具是否安装:
5147

52-
{{< copyable "shell-regular" >}}
53-
5448
```shell
5549
which tiup
5650
```
5751

58-
3. 安装 TiUP cluster 组件:
59-
60-
{{< copyable "shell-regular" >}}
52+
3. 安装 TiUP 集群组件:
6153

6254
```shell
6355
tiup cluster
6456
```
6557

66-
4. 如果已经安装,则更新 TiUP cluster 组件至最新版本:
67-
68-
{{< copyable "shell-regular" >}}
58+
4. 如果已经安装,则更新 TiUP 集群组件至最新版本:
6959

7060
```shell
7161
tiup update --self && tiup update cluster
7262
```
7363

7464
预期输出 `“Updated successfully!` 字样。
7565

76-
5. 验证当前 TiUP cluster 版本信息。执行如下命令查看 TiUP cluster 组件版本:
77-
78-
{{< copyable "shell-regular" >}}
66+
5. 验证当前 TiUP 集群版本信息。执行如下命令查看 TiUP 集群组件版本:
7967

8068
```shell
8169
tiup --binary cluster
@@ -95,24 +83,18 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
9583

9684
1. 执行如下命令安装 TiUP 工具:
9785

98-
{{< copyable "shell-regular" >}}
99-
10086
```shell
10187
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
10288
```
10389

10490
2. 重新声明全局环境变量:
10591

106-
{{< copyable "shell-regular" >}}
107-
10892
```shell
10993
source .bash_profile
11094
```
11195

11296
3. 确认 TiUP 工具是否安装:
11397

114-
{{< copyable "shell-regular" >}}
115-
11698
```shell
11799
which tiup
118100
```
@@ -121,8 +103,6 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
121103

122104
1. 在一台和外网相通的机器上拉取需要的组件:
123105

124-
{{< copyable "shell-regular" >}}
125-
126106
```bash
127107
tiup mirror clone tidb-community-server-${version}-linux-amd64 ${version} --os=linux --arch=amd64
128108
```
@@ -131,8 +111,6 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
131111

132112
2. 通过 tar 命令将该组件包打包然后发送到隔离环境的中控机:
133113

134-
{{< copyable "shell-regular" >}}
135-
136114
```bash
137115
tar czvf tidb-community-server-${version}-linux-amd64.tar.gz tidb-community-server-${version}-linux-amd64
138116
```
@@ -145,8 +123,6 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
145123

146124
1. 在制作离线镜像时,可通过参数指定具体的组件和版本等信息,获得不完整的离线镜像。例如,要制作一个只包括 v1.12.3 版本 TiUP 和 TiUP Cluster 的离线镜像,可执行如下命令:
147125

148-
{{< copyable "shell-regular" >}}
149-
150126
```bash
151127
tiup mirror clone tiup-custom-mirror-v1.12.3 --tiup v1.12.3 --cluster v1.12.3
152128
```
@@ -157,8 +133,6 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
157133

158134
3. 在隔离环境的中控机上,查看当前使用的离线镜像路径。较新版本的 TiUP 可以直接通过命令获取当前的镜像地址:
159135

160-
{{< copyable "shell-regular" >}}
161-
162136
```bash
163137
tiup mirror show
164138
```
@@ -169,16 +143,12 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
169143

170144
首先将当前离线镜像中的 `keys` 目录复制到 `$HOME/.tiup` 目录中:
171145

172-
{{< copyable "shell-regular" >}}
173-
174146
```bash
175147
cp -r ${base_mirror}/keys $HOME/.tiup/
176148
```
177149

178150
然后使用 TiUP 命令将不完整的离线镜像合并到当前使用的镜像中:
179151

180-
{{< copyable "shell-regular" >}}
181-
182152
```bash
183153
tiup mirror merge tiup-custom-mirror-v1.12.3
184154
```
@@ -189,8 +159,6 @@ TiUP 还支持部署 TiDB、TiFlash、TiCDC 以及监控系统。本指南介绍
189159

190160
将离线包发送到目标集群的中控机后,执行以下命令安装 TiUP 组件:
191161

192-
{{< copyable "shell-regular" >}}
193-
194162
```bash
195163
tar xzvf tidb-community-server-${version}-linux-amd64.tar.gz && \
196164
sh tidb-community-server-${version}-linux-amd64/local_install.sh && \
@@ -205,8 +173,6 @@ source /home/tidb/.bash_profile
205173

206174
执行以下命令合并离线组件到 server 目录下。
207175

208-
{{< copyable "shell-regular" >}}
209-
210176
```bash
211177
tar xf tidb-community-toolkit-${version}-linux-amd64.tar.gz
212178
ls -ld tidb-community-server-${version}-linux-amd64 tidb-community-toolkit-${version}-linux-amd64
@@ -221,8 +187,6 @@ tiup mirror merge ../tidb-community-toolkit-${version}-linux-amd64
221187

222188
执行如下命令,生成集群初始化配置文件:
223189

224-
{{< copyable "shell-regular" >}}
225-
226190
```shell
227191
tiup cluster template > topology.yaml
228192
```
@@ -231,23 +195,17 @@ tiup cluster template > topology.yaml
231195

232196
- 混合部署场景:单台机器部署多个实例,详情参见[混合部署拓扑架构](/hybrid-deployment-topology.md)。
233197

234-
{{< copyable "shell-regular" >}}
235-
236198
```shell
237199
tiup cluster template --full > topology.yaml
238200
```
239201

240202
- 跨机房部署场景:跨机房部署 TiDB 集群,详情参见[跨机房部署拓扑架构](/geo-distributed-deployment-topology.md)。
241203

242-
{{< copyable "shell-regular" >}}
243-
244204
```shell
245205
tiup cluster template --multi-dc > topology.yaml
246206
```
247207

248-
执行 vi topology.yaml,查看配置文件的内容:
249-
250-
{{< copyable "shell-regular" >}}
208+
执行 `vi topology.yaml`,查看配置文件的内容:
251209

252210
```shell
253211
global:
@@ -276,7 +234,7 @@ alertmanager_servers:
276234
- host: 10.0.1.4
277235
```
278236

279-
下表列出了常用的 7 种场景,请根据链接中的拓扑说明以及配置文件模板配置`topology.yaml`。如果有其他组合场景的需求,请根据多个模板自行调整。
237+
下表列出了常用的 6 种场景,请根据链接中的拓扑说明以及配置文件模板配置 `topology.yaml`。如果有其他组合场景的需求,请根据多个模板自行调整。
280238

281239
| 场景 | 配置任务 | 配置文件模板 | 拓扑说明 |
282240
| :-- | :-- | :-- | :-- |
@@ -290,11 +248,8 @@ alertmanager_servers:
290248
> **注意:**
291249
>
292250
> - 对于需要全局生效的参数,请在配置文件中 `server_configs` 的对应组件下配置。
293-
>
294251
> - 对于需要某个节点生效的参数,请在具体节点的 `config` 中配置。
295-
>
296252
> - 配置的层次结构使用 `.` 表示。如:`log.slow-threshold`。更多格式参考 [TiUP 配置参数模版](https://github.com/pingcap/tiup/blob/master/embed/examples/cluster/topology.example.yaml)。
297-
>
298253
> - 如果需要指定在目标机创建的用户组名,可以参考[这个例子](https://github.com/pingcap/tiup/blob/master/embed/examples/cluster/topology.example.yaml#L7)。
299254

300255
更多参数说明,请参考:
@@ -308,42 +263,35 @@ alertmanager_servers:
308263

309264
> **注意:**
310265
>
311-
> 通过 TiUP 进行集群部署可以使用密钥或者交互密码方式来进行安全认证:
312-
>
313-
> - 如果是密钥方式,可以通过 -i 或者 --identity_file 来指定密钥的路径。
314-
>
315-
> - 如果是密码方式,可以通过 -p 进入密码交互窗口。
266+
> 通过 TiUP 部署集群时用于初始化的用户(通过 `--user` 指定),可以使用密钥或者交互密码的方式进行安全认证:
316267
>
268+
> - 如果使用密钥方式,可以通过 `-i` 或者 `--identity_file` 指定密钥的路径。
269+
> - 如果使用密码方式,可以通过 `-p` 进入密码交互窗口。
317270
> - 如果已经配置免密登录目标机,则不需填写认证。
318271
>
319-
> 一般情况下 TiUP 会在目标机器上创建 topology.yaml 中约定的用户和组,以下情况例外
272+
> TiUP 用于实际执行相关进程的用户和组(通过 `topology.yaml` 指定,默认值为 `tidb`),一般情况下会在目标机器上自动创建,但以下情况例外
320273
>
321274
> - `topology.yaml` 中设置的用户名在目标机器上已存在。
275+
> - 在命令行上使用了参数 `--skip-create-user` 明确指定跳过创建用户的步骤。
322276
>
323-
> - 在命令行上使用了参数 --skip-create-user 明确指定跳过创建用户的步骤
277+
> 无论 `topology.yaml` 中约定的用户和组是否被自动创建,TiUP 都会自动生成一对 ssh key,并为每台机器的该用户设置免密登录。在此后的操作中都会使用这个用户和 ssh key 去管理机器,而用于初始化的用户和密码在部属完成后不再被使用
324278

325279
执行部署命令前,先使用 `check``check --apply` 命令检查和自动修复集群存在的潜在风险:
326280

327281
1. 检查集群存在的潜在风险:
328282

329-
{{< copyable "shell-regular" >}}
330-
331283
```shell
332284
tiup cluster check ./topology.yaml --user root [-p] [-i /home/root/.ssh/gcp_rsa]
333285
```
334286

335287
2. 自动修复集群存在的潜在风险:
336288

337-
{{< copyable "shell-regular" >}}
338-
339289
```shell
340290
tiup cluster check ./topology.yaml --apply --user root [-p] [-i /home/root/.ssh/gcp_rsa]
341291
```
342292

343293
3. 部署 TiDB 集群:
344294

345-
{{< copyable "shell-regular" >}}
346-
347295
```shell
348296
tiup cluster deploy tidb-test v8.5.0 ./topology.yaml --user root [-p] [-i /home/root/.ssh/gcp_rsa]
349297
```
@@ -354,14 +302,12 @@ alertmanager_servers:
354302
- `v8.5.0` 为部署的集群版本,可以通过执行 `tiup list tidb` 来查看 TiUP 支持的最新可用版本。
355303
- 初始化配置文件为 `topology.yaml`
356304
- `--user root` 表示通过 root 用户登录到目标主机完成集群部署,该用户需要有 ssh 到目标机器的权限,并且在目标机器有 sudo 权限。也可以用其他有 ssh 和 sudo 权限的用户完成部署。
357-
- [-i] 及 [-p] 为可选项,如果已经配置免密登录目标机,则不需填写。否则选择其一即可,[-i] 为可登录到目标机的 root 用户(或 --user 指定的其他用户)的私钥,也可使用 [-p] 交互式输入该用户的密码。
305+
- [-i] 及 [-p] 为可选项,如果已经配置免密登录目标机,则不需填写。否则选择其一即可,[-i] 为可登录到目标机的 root 用户(或 `--user` 指定的其他用户)的私钥,也可使用 [-p] 交互式输入该用户的密码。
358306

359307
预期日志结尾输出 ```Deployed cluster `tidb-test` successfully``` 关键词,表示部署成功。
360308

361309
## 第 5 步:查看 TiUP 管理的集群情况
362310

363-
{{< copyable "shell-regular" >}}
364-
365311
```shell
366312
tiup cluster list
367313
```
@@ -372,8 +318,6 @@ TiUP 支持管理多个 TiDB 集群,该命令会输出当前通过 TiUP cluste
372318

373319
例如,执行如下命令检查 `tidb-test` 集群情况:
374320

375-
{{< copyable "shell-regular" >}}
376-
377321
```shell
378322
tiup cluster display tidb-test
379323
```
@@ -389,21 +333,16 @@ tiup cluster display tidb-test
389333
> **注意:**
390334
>
391335
> - 使用安全启动方式后,不能通过无密码的 root 用户登录数据库,你需要记录命令行返回的密码进行后续操作。
392-
>
393336
> - 该自动生成的密码只会返回一次,如果没有记录或者忘记该密码,请参照[忘记 root 密码](/user-account-management.md#忘记-root-密码)修改密码。
394337

395338
方式一:安全启动
396339

397-
{{< copyable "shell-regular" >}}
398-
399340
```shell
400341
tiup cluster start tidb-test --init
401342
```
402343

403344
预期结果如下,表示启动成功。
404345

405-
{{< copyable "shell-regular" >}}
406-
407346
```shell
408347
Started cluster `tidb-test` successfully.
409348
The root password of TiDB database has been changed.
@@ -414,8 +353,6 @@ The generated password can NOT be got again in future.
414353

415354
方式二:普通启动
416355

417-
{{< copyable "shell-regular" >}}
418-
419356
```shell
420357
tiup cluster start tidb-test
421358
```
@@ -424,8 +361,6 @@ tiup cluster start tidb-test
424361

425362
## 第 8 步:验证集群运行状态
426363

427-
{{< copyable "shell-regular" >}}
428-
429364
```shell
430365
tiup cluster display tidb-test
431366
```

quick-start-with-tidb.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ TiDB 是一个分布式系统。最基础的 TiDB 测试集群通常由 2 个 Ti
445445
446446
- 参数 `<cluster-name>` 表示设置集群名称
447447
- 参数 `<version>` 表示设置集群版本,例如 `v8.5.0`。可以通过 `tiup list tidb` 命令来查看当前支持部署的 TiDB 版本
448+
- 参数 `--user` 表示初始化环境的用户
448449
- 参数 `-p` 表示在连接目标机器时使用密码登录
449450
450451
> **注意:**

0 commit comments

Comments
 (0)