Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lightning: update get started doc #12059

Merged
merged 4 commits into from
Dec 14, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 34 additions & 29 deletions get-started-with-tidb-lightning.md
Original file line number Diff line number Diff line change
@@ -1,54 +1,61 @@
---
title: TiDB Lightning 教程
title: TiDB Lightning 快速上手
aliases: ['/docs-cn/dev/get-started-with-tidb-lightning/','/docs-cn/dev/how-to/get-started/tidb-lightning/']
---

# TiDB Lightning 快速上手

本教程假设使用的是若干新的、纯净版 CentOS 7 实例,你可以(使用 VMware、VirtualBox 及其他工具)在本地虚拟化或在供应商提供的平台上部署一台小型的云虚拟主机。因为 TiDB Lightning 对计算机资源消耗较高,建议分配 16 GB 以上的内存以及 32 核以上的 CPU 以获取最佳性能
本文档介绍如何快速上手 TiDB Lightning,将 MySQL 数据导入到 TiDB 集群中

> **警告:**
>
> 本教程中的部署方法只适用于测试及功能体验,并不适用于生产或开发环境。

## 准备全量备份数据
## 第 1 步:准备全量备份数据

我们使用 [`dumpling`](/dumpling-overview.md) 从 MySQL 导出数据,如下:
你可以使用 [`dumpling`](/dumpling-overview.md) 从 MySQL 导出数据

{{< copyable "shell-regular" >}}
1. 安装 Dumpling:

```sh
tiup dumpling -h 127.0.0.1 -P 3306 -u root -t 16 -F 256MB -B test -f 'test.t[12]' -o /data/my_database/
```
```shell
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command is to install TiUP, right ?
Maybe you can make it as a separate step to verify whether TiUP is installed. If not , use curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh to install the TiUP

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 66194be

tiup install dumpling
```

其中
2. 从 MySQL 导出数据

- `-B test`:从 `test` 数据库导出。
- `-f test.t[12]`:只导出 `test.t1` 和 `test.t2` 这两个表。
- `-t 16`:使用 16 个线程导出数据。
- `-F 256MB`:将每张表切分成多个文件,每个文件大小约为 256 MB。
```sh
tiup dumpling -h 127.0.0.1 -P 3306 -u root -t 16 -F 256MB -B test -f 'test.t[12]' -o /data/my_database/
```

这样全量备份数据就导出到了 `/data/my_database` 目录中。
其中:

## 部署 TiDB Lightning
- `-B test`:从 `test` 数据库导出。
- `-f test.t[12]`:只导出 `test.t1` 和 `test.t2` 这两个表。
- `-t 16`:使用 16 个线程导出数据。
- `-F 256MB`:将每张表切分成多个文件,每个文件大小约为 256 MB。

### 第 1 步:部署 TiDB 集群
这样全量备份数据就导出到了 `/data/my_database` 目录中。

在开始数据导入之前,需先部署一套要进行导入的 TiDB 集群。本教程以 TiDB v5.4.0 版本为例,具体部署方法可参考[使用 TiUP 部署 TiDB 集群](/production-deployment-using-tiup.md)。
## 第 2 步:部署 TiDB 集群

### 第 2 步:下载 TiDB Lightning 安装包
在开始导入数据之前,你需要先部署一套要进行导入的 TiDB 集群。如果你已经有 TiDB 集群,可以跳过这一步。

TiDB Lightning 的安装包位于 TiDB 离线工具包中。下载方式,请参考 [TiDB 工具下载](/download-ecosystem-tools.md)。
关于部署 TiDB 集群的步骤,请参考 [TiDB 数据库快速上手指南](/quick-start-with-tidb.md)。

### 第 3 步:启动 `tidb-lightning`
## 第 3 步:安装 TiDB Lightning

1. 将安装包里的 `bin/tidb-lightning` 及 `bin/tidb-lightning-ctl` 上传至部署 TiDB Lightning 的服务器。
运行如下命令,安装 TiDB Lightning 最新版本:

2. 将数据源也上传到同样的服务器。
```shell
tiup install tidb-lightning
```

3. 配置 `tidb-lightning.toml`。
## 第 4 步:启动 TiDB Lightning

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```
1. 创建配置文件 `tidb-lightning.toml`,并根据你的集群信息,填写如下配置:

```toml
[lightning]
# 日志
level = "info"
Expand Down Expand Up @@ -79,16 +86,14 @@ TiDB Lightning 的安装包位于 TiDB 离线工具包中。下载方式,请
pd-addr = "172.16.31.3:2379"
```

4. 配置合适的参数运行 `tidb-lightning`。如果直接在命令行中用 `nohup` 启动程序,可能会因为 SIGHUP 信号而退出,建议把 `nohup` 放到脚本里面,如:
2. 运行 `tidb-lightning`。如果直接在命令行中用 `nohup` 启动程序,可能会因为 SIGHUP 信号而退出,建议把 `nohup` 放到脚本里面,如:

{{< copyable "shell-regular" >}}

```sh
```shell
#!/bin/bash
nohup tiup tidb-lightning -config tidb-lightning.toml > nohup.out &
```

### 第 4 步:检查数据
### 第 5 步:检查数据

导入完毕后,TiDB Lightning 会自动退出。若导入成功,日志的最后一行会显示 `tidb lightning exit`。

Expand Down