Alexu
发布于 2025-03-10 / 2 阅读
0
0

TiDB本地部署测试

TiDB 是一个分布式系统。最基础的 TiDB 测试集群通常由 2 个 TiDB 实例、3 个 TiKV 实例、3 个 PD 实例和可选的 TiFlash 实例构成。通过 TiUP Playground,可以快速搭建出上述的一套基础测试集群,步骤如下:

  1. 下载并安装 TiUP。

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

    安装完成后会提示如下信息:

    Successfully set mirror to https://tiup-mirrors.pingcap.com
    Detected shell: zsh
    Shell profile:  /Users/user/.zshrc
    /Users/user/.zshrc has been modified to add tiup to PATH
    open a new terminal or source /Users/user/.zshrc to use it
    Installed path: /Users/user/.tiup/bin/tiup
    ===============================================
    Have a try:     tiup playground
    ===============================================
    

    请注意上述输出中的 Shell profile 文件路径,下一步中需要使用该路径。

    注意

    v5.2.0 及以上版本的 TiDB 支持在 Apple silicon 芯片的机器上运行 tiup playground

  2. 声明全局环境变量。

    注意

    TiUP 安装完成后会提示 Shell profile 文件的绝对路径。在执行以下 source 命令前,需要将 ${your_shell_profile} 修改为 Shell profile 文件的实际位置。

    source ${your_shell_profile}
    
  3. 在当前 session 执行以下命令启动集群。

    注意

    • 如果按以下方式执行 playground,在结束部署测试后,TiUP 会自动清理掉原集群数据,重新执行命令会得到一个全新的集群。

    • 如果希望持久化数据,需要在启动集群时添加 TiUP 的 --tag 参数,详见启动集群时指定 tag 以保留数据

      tiup playground --tag ${tag_name}
      
    • 直接执行 tiup playground 命令会运行最新版本的 TiDB 集群,其中 TiDB、TiKV、PD 和 TiFlash 实例各 1 个:

      tiup playground
      

      如果这是你第一次运行该命令,TiUP 会下载最新版本的 TiDB 并启动集群。命令输出中将显示集群的端点列表:

      🎉 TiDB Playground Cluster is started, enjoy!
      
      Connect TiDB:    mysql --comments --host 127.0.0.1 --port 4000 -u root
      TiDB Dashboard:  http://127.0.0.1:2379/dashboard
      Grafana:         http://127.0.0.1:3000
      
    • 也可以指定 TiDB 版本以及各组件实例个数,命令类似于:

      tiup playground v8.5.1 --db 2 --pd 3 --kv 3
      

      如果要查看当前支持部署的所有 TiDB 版本,执行 tiup list tidb

  4. 新开启一个 session 以访问 TiDB 数据库和集群端点。

    • 连接 TiDB 数据库:

      • 使用 TiUP client 连接 TiDB:

        tiup client
        
      • 或者使用 MySQL 客户端连接 TiDB:

        mysql --host 127.0.0.1 --port 4000 -u root
        
  5. (可选)将数据加载到 TiFlash 进行分析。

  6. 测试完成之后,可以通过执行以下步骤来清理集群:

    1. 按下 Control+C 键停掉上述启用的 TiDB 服务。

    2. 等待服务退出操作完成后,执行以下命令:

      tiup clean --all
      

tidb自带dashboard

自带grafana:

数据库连接:

默认数据库与MySQL类似,都有infomation_schema和performance_schema, sys和mysql数据库。比mysql表多了tidb相关的库mertics_schema


评论