# TiUP 离线部署 TiDB 集群

> 作者/来源: UCloud 运营管理员
> 发布时间: 2023-01-11T05:20:00.000Z
> 分类: 解决方案
> 标签: Linux
> 原文链接: http://117.50.162.249:3000/yun/articles/1130

---

# TiUP 离线部署 TiDB 集群

> 来源: https://www.ucloud.cn/yun/129747.html
> 作者: IT那活儿
> 发布日期: 发布于2023-01-11 13:20

TiUP 离线部署 TiDB 集群

## 点击上方“IT那活儿”，关注后了解更多精彩内容！！！

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_008.png)

一、准备 TiUP 离线组件包

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_009.png)

**使用 tiup mirror clone 命令手动打包离线组件包。**

### **step1.**在线环境中安装 TiUP 包管理器工具

#### **a.** 执行如下命令安装 TiUP 工具：

curl --proto =https --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

#### **b.** 重新声明全局环境变量：

source .bash\_profile

#### **c.** 确认 TiUP 工具是否安装：

which tiup

### **step2.**使用 TiUP 制作离线镜像

#### **a.** 在一台和外网相通的机器上拉取需要的组件：

```
tiup mirror clone tidb-community-server-${version}-linux-amd64 ${version} --os=linux --arch=amd64
```

该命令会在当前目录下创建一个名叫 tidb-community-server-${version}-linux-amd64 的目录，里面包含 TiUP 管理的组件包。

#### **b.** 通过 tar 命令将该组件包打包然后发送到隔离环境的中控机：

```
tar czvf tidb-community-server-${version}-linux-amd64.tar.gztidb-community-server-${version}-linux-amd64
```

此时，tidb-community-server-${version}-linux-amd64.tar.gz 就是一个独立的离线环境包。

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_008.png)

二、 部署离线环境 TiUP 组件

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_009.png)

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

```
tar xzvf tidb-community-server-${version}-linux-amd64.tar.gzsh tidb-community-server-${version}-linux-amd64/local_install.shsource /home/tidb/.bash_profilelocal_install.sh 脚本会自动执行 tiup mirror set tidb-community-server-${version}-linux-amd64 命令将当前镜像地址设置为 tidb-community-server-${version}-linux-amd64。
```

若需将镜像切换到其他目录，可以通过手动执行 tiup mirror set  进行切换。如果需要切换到在线环境，可执行 tiup mirror set https://tiup-mirrors.pingcap.com。

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_008.png)

三、 TiKV 数据盘挂载

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_009.png)

使用 root 用户登录目标机器，将部署目标机器数据盘格式化成 ext4 文件系统，挂载时添加 nodelalloc 和 noatime 挂载参数。nodelalloc 是必选参数，否则 TiUP 安装时检测无法通过；noatime 是可选建议参数。

以 /dev/nvme0n1 数据盘为例，具体操作步骤如下：

### **step1.** 查看数据盘。

```
fdisk -lDisk /dev/nvme0n1: 1000 GB
```

### **step2.** 创建分区表。

```
parted -s -a optimal /dev/nvme0n1 mklabel gpt -- mkpartprimary ext4 1 -1
```

### **step3.** 格式化文件系统。

```
mkfs.ext4 /dev/nvme0n1p1
```

### **step4.**查看数据盘分区 UUID。

本例中 nvme0n1p1 的 UUID 为 c51eb23b-195c-4061-92a9-3fad812cc12f。

```
lsblk -fNAME FSTYPE LABEL UUID MOUNTPOINTsda├─sda1 ext4 237b634b-a565-477b-8371-6dff0c41f5ab /boot├─sda2 swap f414c5c0-f823-4bb1-8fdf-e531173a72ed└─sda3 ext4 547909c1-398d-4696-94c6-03e43e317b60 /sr0nvme0n1└─nvme0n1p1 ext4 c51eb23b-195c-4061-92a9-3fad812cc12f
```

### **step5.**编辑 /etc/fstab 文件，添加 nodelalloc 挂载参数。

```
vi /etc/fstabUUID=c51eb23b-195c-4061-92a9-3fad812cc12f /data1 ext4 defaults,nodelalloc,noatime 0 2
```

### **step6.**挂载数据盘。

```
mkdir /data1 && mount -a
```

**step7.**执行以下命令，如果文件系统为 ext4，并且挂载参数中包含 nodelalloc，则表示已生效。

```
mount -t ext4/dev/nvme0n1p1 on /data1 type e
```

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_008.png)

四、 配置初始化参数文件

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_009.png)

集群初始化配置文件需要手动编写，完整的全配置参数模版可以参考 Github TiUP 项目配置参数模版。需要在中控机上面创建 YAML 格式配置文件，例如 topology.yaml:

```
cat topology.yaml# # Global variables are applied to all deployments and used as the default value of# # the deployments if a specific deployment value is missing.global:user: "tidb"ssh_port: 22deploy_dir: "/tidb-deploy"data_dir: "/tidb-data"server_configs:pd:replication.enable-placement-rules: truepd_servers:- host: 10.0.1.4- host: 10.0.1.5- host: 10.0.1.6tidb_servers:- host: 10.0.1.7- host: 10.0.1.8- host: 10.0.1.9tikv_servers:- host: 10.0.1.1- host: 10.0.1.2- host: 10.0.1.3tiflash_servers:- host: 10.0.1.10data_dir: /data1/tiflash/data,/data2/tiflash/datacdc_servers:- host: 10.0.1.6- host: 10.0.1.7- host: 10.0.1.8monitoring_servers:- host: 10.0.1.4grafana_servers:- host: 10.0.1.4alertmanager_servers:- host: 10.0.1.4
```

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_008.png)

五、 部署 TiDB 集群

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_009.png)

### **step1.**执行以下命令来部署 TiDB 集群。

```
tiup cluster deploy tidb-test v4.0.0 topology.yaml --user tidb [-p] [-i /home/root/.ssh/gcp_rsa]tiup cluster start tidb-test
```

### **step2.**参数说明：

**a.** 通过 TiUP cluster 部署的集群名称为 tidb-test

**b.** 部署版本为 v4.0.0，其他版本可以执行 tiup list tidb 获取

**c.** 初始化配置文件为 topology.yaml

**d.** --user tidb：通过 tidb 用户登录到目标主机完成集群部署，该用户需要有 ssh 到目标机器的权限，并且在目标机器有 sudo 权限。也可以用其他有 ssh 和 sudo 权限的用户完成部署。

**e.** [-i] 及 [-p]：非必选项，如果已经配置免密登陆目标机，则不需填写。否则选择其一即可，[-i] 为可登录到部署机 root 用户（或 --user 指定的其他用户）的私钥，也可使用 [-p] 交互式输入该用户的密码

**f.** 预期日志结尾输出会有 Deployed cluster `tidb-test` successfully 关键词，表示部署成功。

**g.** 部署完成后，集群相关操作可参考 cluster 命令。

**END**

更多精彩干货分享

点击下方名片关注

IT那活儿

![](https://ucloud-blog.cn-bj.ufileos.com/articles/129747/images/129747_010.png)