TiUP playground 部署&启动集群

本文档演示了如何下载并使用TiUP工具,通过简单的命令行操作来设置环境变量、启动和停止一个包含TiDB、TiKV、PD和TiFlash实例的集群。此外,还展示了如何指定不同实例的数量以及连接到集群进行数据操作。最后,介绍了如何清理集群资源。

下载TiUP工具

frank@DESKTOP-6NF3B9K:~$ curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 6198k  100 6198k    0     0  4168k      0  0:00:01  0:00:01 --:--:-- 4168k
WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
You can revoke this by remove /home/frank/.tiup/bin/7b8e153f2e2d0928.root.json
Successfully set mirror to https://tiup-mirrors.pingcap.com
Detected shell: bash
Shell profile:  /home/frank/.bashrc
/home/frank/.bashrc has been modified to add tiup to PATH
open a new terminal or source /home/frank/.bashrc to use it
Installed path: /home/frank/.tiup/bin/tiup
===============================================
Have a try:     tiup playground
===============================================

设置环境变量

frank@DESKTOP-6NF3B9K:~$ source /home/frank/.bashrc

运行

运行最新的TiDB集群,其中TiDB、TiKV、PD和TiFlash实例各1个
frank@DESKTOP-6NF3B9K:~$ tiup playground
Starting component `playground`: /home/frank/.tiup/components/playground/v1.8.2/tiup-playground
Using the version v5.3.0 for version constraint "".
If you'd like to use a TiDB version other than v5.3.0, cancel and retry with the following arguments:
        Specify version manually:   tiup playground <version>
        Specify version range:      tiup playground ^5
        The nightly version:        tiup playground nightly
Playground Bootstrapping...
Start pd instance
Start tikv instance
Start tidb instance
127.0.0.1:4000 ... Done
Start tiflash instance
127.0.0.1:3930 ... Done
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --comments --host 127.0.0.1 --port 4000 -u root -p (no password)
To view the dashboard: http://127.0.0.1:2379/dashboard
PD client endpoints: [127.0.0.1:2379]
To view the Prometheus: http://127.0.0.1:9090
To view the Grafana: http://127.0.0.1:3000
指定版本,指定各实例启动数量
frank@DESKTOP-6NF3B9K:~$ tiup playground v5.0.0 --db 2 --pd 3 --kv 3 --monitor
Starting component `playground`: /home/frank/.tiup/components/playground/v1.8.2/tiup-playground v5.0.0 --db 2 --pd 3 --kv 3 --monitor
Flag --monitor has been deprecated, Please use --without-monitor to control whether to disable monitor.
Playground Bootstrapping...
Start pd instance
The component `pd` version v5.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/pd-v5.0.0-linux-amd64.tar.gz 41.09 MiB / 41.09 MiB 100.00% 9.57 MiB/s
Start pd instance
Start pd instance
Start tikv instance
The component `tikv` version v5.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tikv-v5.0.0-linux-amd64.tar.gz 161.21 MiB / 161.21 MiB 100.00% 9.64 MiB/s
Start tikv instance
Start tikv instance
Start tidb instance
The component `tidb` version v5.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tidb-v5.0.0-linux-amd64.tar.gz 45.73 MiB / 45.73 MiB 100.00% 4.56 MiB/s
Start tidb instance
Waiting for tidb instances ready
127.0.0.1:4000 ... Done
127.0.0.1:4001 ... Done
The component `prometheus` version v5.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/prometheus-v5.0.0-linux-amd64.tar.gz 39.84 MiB / 39.84 MiB 100.00% 10.14 MiB/s
download https://tiup-mirrors.pingcap.com/grafana-v5.0.0-linux-amd64.tar.gz 54.28 MiB / 54.28 MiB 100.00% 8.11 MiB/s
Start tiflash instance
The component `tiflash` version v5.0.0 is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/tiflash-v5.0.0-linux-amd64.tar.gz 407.93 MiB / 407.93 MiB 100.00% 8.14 MiB/s
Waiting for tiflash instances ready
127.0.0.1:3930 ... Done
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --comments --host 127.0.0.1 --port 4000 -u root -p (no password)
To connect TiDB: mysql --comments --host 127.0.0.1 --port 4001 -u root -p (no password)
To view the dashboard: http://127.0.0.1:2379/dashboard
PD client endpoints: [127.0.0.1:2379 127.0.0.1:2382 127.0.0.1:2384]
To view the Prometheus: http://127.0.0.1:9090
To view the Grafana: http://127.0.0.1:3000

查看面板

在这里插入图片描述

客户端链接集群

frank@DESKTOP-6NF3B9K:~$ mycli -h127.0.0.1 -P4000 -uroot
MySQL 5.7.25
mycli 1.24.3
Home: http://mycli.net
Bug tracker: https://github.com/dbcli/mycli/issues
Thanks to the contributor - mrdeathless
MySQL root@127.0.0.1:(none)> show databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA     |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
5 rows in set
Time: 0.006s
MySQL root@127.0.0.1:(none)>

停止集群

ctrl-c
^CPlayground receive signal:  interrupt
Got signal interrupt (Component: playground ; PID: 10334)
Wait tiflash(10923) to quit...
tiflash quit
Wait tidb(10803) to quit...
tidb quit
Wait tidb(10797) to quit...
tidb quit
Wait tikv(10453) to quit...
tikv quit
Wait tikv(10442) to quit...
tikv quit
Wait tikv(10440) to quit...
tikv quit
Wait pd(10371) to quit...
pd quit
Wait pd(10363) to quit...
pd quit
Wait pd(10355) to quit...
pd quit
prometheus quit
Grafana quit

清理集群

frank@DESKTOP-6NF3B9K:~$ tiup clean --all
&lt;think&gt;好的,我现在需要帮助用户了解TiUP Cluster的使用指南和配置教程。首先,我得回忆一下用户提供的引用内容,里面提到了TiUP Cluster是TiDB 4.0引入的运维工具,用于集群管理,包括部署启动、关闭、扩缩容、升级和参数管理。用户还提到了一些引用内容,比如备份恢复、安装注意事项等。 用户的问题是关于TiUP Cluster的使用和配置,所以需要系统性地分步骤讲解。首先,我应该从安装开始,因为这是第一步。根据引用[4],安装TiDB时可能需要配置NTP服务器,所以安装TiUP是否需要这些步骤呢?不过引用[1]提到TiUP本身是运维工具,安装TiUP可能不需要修改NTP,但部署集群时需要。这点需要注意。 接下来,用户可能需要了解如何部署集群。引用[1]提到TiUP cluster组件可以部署集群,所以需要给出具体的部署命令,比如tiup cluster deploy。同时,引用[2]提到使用tag来持久化数据,这可能是在部署时需要注意的参数,需要包含在示例中。 然后是关于日常运维操作,如启动、停止、销毁集群,这些应该是基本操作,需要列出对应的命令。弹性扩缩容也是TiUP cluster的功能之一,需要说明如何添加节点或缩容节点。 升级集群部分,引用[1]提到升级功能,所以需要给出升级命令,比如tiup cluster upgrade。管理配置参数方面,可能需要使用edit-config命令,并重载配置。 备份和恢复方面,引用[3]提到BR工具的使用,但用户可能想知道如何结合TiUP进行备份恢复,所以需要提到使用tiup br命令,并给出示例,比如全量备份和恢复的命令。 配置方面,用户可能需要了解集群的拓扑文件结构,如何设置不同的组件参数,比如TiDB、TiKV、PD的配置项。引用[4]中的NTP配置可能在拓扑文件中设置,或者在部署时通过其他方式配置。 注意事项部分,需要提到备份时的数据安全,引用[3]中的定期备份建议,以及使用--force参数的风险。还有,测试环境部署后数据会被清理,使用--tag可以持久化,这点来自引用[2],需要强调。 最后,最佳实践和常见问题处理,比如版本兼容性、性能调优、监控集成,这些内容虽然引用中没有详细说明,但作为指南应该提及,并引导用户查阅官方文档或社区资源。 现在需要把这些内容组织成结构清晰的步骤,每个部分给出具体命令和示例,同时引用相关的内容作为支持。确保使用中文,并按照系统指令中的格式要求,行内公式用$...$,独立公式用$$...$$,但可能这里数学公式较少,主要关注命令和配置。同时生成相关问题,可能需要考虑用户在使用TiUP Cluster时可能遇到的疑问,比如安装问题、配置优化、备份策略等。&lt;/think&gt;### TiUP Cluster 使用指南及配置教程 TiUP Cluster 是 TiDB 生态中的核心运维工具,支持集群的全生命周期管理。以下是详细的使用指南和配置说明: --- #### 一、安装 TiUP 及 Cluster 组件 1. **安装 TiUP** 执行以下命令一键安装 TiUP: ```bash curl --proto &#39;=https&#39; --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh source ~/.bashrc # 使环境变量生效 ``` 验证安装:`tiup --version` 2. **安装 Cluster 组件** ```bash tiup cluster ``` 首次运行会自动下载组件。 --- #### 二、部署 TiDB 集群 1. **准备拓扑文件** 创建 `topology.yaml`,定义集群架构,例如: ```yaml global: user: &quot;tidb&quot; deploy_dir: &quot;/data/tidb&quot; pd_servers: - host: 10.0.1.1 - host: 10.0.1.2 tidb_servers: - host: 10.0.1.3 tikv_servers: - host: 10.0.1.4 - host: 10.0.1.5 ``` [^1] 2. **执行部署命令** ```bash tiup cluster deploy &lt;cluster-name&gt; v7.5.0 ./topology.yaml -y ``` 参数说明: - `&lt;cluster-name&gt;`: 自定义集群名称 - `v7.5.0`: TiDB 版本号 - `-y`: 自动确认操作 3. **启动集群** ```bash tiup cluster start &lt;cluster-name&gt; ``` 查看状态:`tiup cluster display &lt;cluster-name&gt;` --- #### 三、日常运维操作 1. **启停集群** - 启动:`tiup cluster start &lt;cluster-name&gt;` - 停止:`tiup cluster stop &lt;cluster-name&gt;` - 销毁:`tiup cluster destroy &lt;cluster-name&gt;`(谨慎操作)[^2] 2. **弹性扩缩容** - **扩容节点**:编辑拓扑文件后执行: ```bash tiup cluster scale-out &lt;cluster-name&gt; ./topology.yaml -y ``` - **缩容节点**: ```bash tiup cluster scale-in &lt;cluster-name&gt; --node 10.0.1.6:20160 -y ``` 3. **升级集群** ```bash tiup cluster upgrade &lt;cluster-name&gt; v7.5.1 -y ``` 4. **管理配置参数** - 修改配置: ```bash tiup cluster edit-config &lt;cluster-name&gt; ``` 编辑后保存,重启生效: ```bash tiup cluster reload &lt;cluster-name&gt; -R tidb,tikv ``` --- #### 四、备份与恢复 1. **使用 BR 工具备份** ```bash tiup br backup full --pd &lt;PD_Endpoint&gt; --storage &quot;s3://backup-bucket/&quot; --ratelimit 128 ``` 参数说明: - `--storage`: 备份存储路径(支持本地或 S3) - `--ratelimit`: 限速(单位:MB/s)[^3] 2. **恢复数据** ```bash tiup br restore full --pd &lt;PD_Endpoint&gt; --storage &quot;s3://backup-bucket/&quot; --force ``` ⚠️ `--force` 会覆盖现有数据,需谨慎使用[^3] --- #### 五、配置优化实践 1. **关键组件配置建议** - **TiKV**:调整 `raftstore.capacity` 控制存储容量。 - **PD**:设置 `replication.location-labels` 实现多机房容灾。 - **TiDB**:优化 `performance.max-procs` 限制 CPU 使用率。 2. **NTP 时间同步** 确保所有节点时间一致,编辑 `/etc/ntp.conf` 添加阿里云 NTP 服务器: ```conf server time1.aliyun.com server time2.aliyun.com ... ``` 重启服务:`systemctl restart ntpd`[^4] --- #### 六、注意事项 1. **数据持久化** 测试环境默认清理数据,若需保留,部署时添加 `--tag`: ```bash tiup --tag playground cluster deploy ... ```[^2] 2. **版本兼容性** 升级前需验证拓扑文件与目标版本的兼容性,建议先在测试环境操作[^3]。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

夏 克

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值