• 国产数据库TiDB初体验:简单易用,快速上手


    最近开始关注国产数据库的发展,为了能从技术人员的角度来实际体验国产中目前最流行的TiDB数据库,从今天起,在官方公布的课程开始正面了解TiDB的设计理念。

    看了2小时的入门课程介绍,总体来说,还是有不少的惊喜,首先从这个最简单的“TiDB 快速起步”课程中,大致了解了TiDB的前世今生,从基本架构中的基础组件:主要是PD、TiDB Server、TiKV、TiFlash等高度分层的设计理念,对MySQL的完备兼容性,以及TiDB自己的一些创新。

    刚开始听概念时会觉得这种较为复杂的分层架构设计一定会对初学者产生困扰,因为很多DBA初学某一款数据库时,都是先被最基础的安装部署耗费了很多精力,到头来反而忽略对产品的核心功能特性的体验和理解。

    这一点顾虑在课程最后得到了一个很好的解决方案,直接在自己的笔记本中,就可以快速部署本地测试集群,包括这些核心组件以及监控,整个过程只需要简单几条命令,连虚拟机都不需要。

    所以任何使用者想自己快速搭建一套测试环境,完全都不需要啥运维基础,就可以在自己的电脑上快速部署一套完整的TiDB数据库集群系统用于学习测试。

    下面就来实际体会下这个便捷性:

    课程中还是讲的TiDB 5.0 版本,为了感受最新的 TiDB 6.1 版本,结合课程和官方手册在我的MBP上直接运行以下步骤来获得一套完整的TiDB数据库集群系统,体验 TiDB 集群的基本架构,以及 TiDB、TiKV、PD、监控等基础组件的运行:

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

    1. 安装TiUP工具

    执行如下命令安装 TiUP 工具:
    curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
    

    实际执行和输出结果:

    jingyuzhao@jingyuzhao-mac ~ % 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 7277k  100 7277k    0     0  7138k      0  0:00:01  0:00:01 --:--:-- 7212k
    WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
    You can revoke this by remove /Users/jingyuzhao/.tiup/bin/7b8e153f2e2d0928.root.json
    Successfully set mirror to https://tiup-mirrors.pingcap.com
    Detected shell: zsh
    Shell profile:  /Users/jingyuzhao/.zshrc
    /Users/jingyuzhao/.zshrc has been modified to add tiup to PATH
    open a new terminal or source /Users/jingyuzhao/.zshrc to use it
    Installed path: /Users/jingyuzhao/.tiup/bin/tiup
    ===============================================
    Have a try:     tiup playground
    ===============================================
    jingyuzhao@jingyuzhao-mac ~ % 
    

    2. 设置环境变量

    按如下步骤设置 TiUP 环境变量:
    source ${your_shell_profile}
    

    实际执行和输出结果:

    jingyuzhao@jingyuzhao-mac ~ % source /Users/jingyuzhao/.zshrc
    jingyuzhao@jingyuzhao-mac ~ % which tiup
    /Users/jingyuzhao/.tiup/bin/tiup
    

    3. 部署并启动集群

    在当前 session 执行以下命令启动集群 如果直接执行 tiup playground 命令会运行最新版本的 TiDB 集群,其中 TiDB、TiKV、PD 和 TiFlash 实例各 1 个。 我们也可以指定 TiDB 版本以及各组件实例个数,命令类似于:
    tiup playground v6.1.0 --db 2 --pd 3 --kv 3
    

    实际执行和输出结果:

    jingyuzhao@jingyuzhao-mac ~ % tiup playground v6.1.0 --db 2 --pd 3 --kv 3
    
    tiup is checking updates for component playground ...
    A new version of playground is available:
       The latest version:         v1.10.2
       Local installed version:    
       Update current component:   tiup update playground
       Update all components:      tiup update --all
    
    The component `playground` version  is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/playground-v1.10.2-darwin-amd64.tar.gz 7.64 MiB / 7.64 MiB 100.00% 13.78 MiB/s                          
    Starting component `playground`: /Users/jingyuzhao/.tiup/components/playground/v1.10.2/tiup-playground v6.1.0 --db 2 --pd 3 --kv 3
    Playground Bootstrapping...
    Start pd instance:v6.1.0
    The component `pd` version v6.1.0 is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/pd-v6.1.0-darwin-amd64.tar.gz 43.73 MiB / 43.73 MiB 100.00% 10.03 MiB/s                                 
    Start pd instance:v6.1.0
    Start pd instance:v6.1.0
    Start tikv instance:v6.1.0
    The component `tikv` version v6.1.0 is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/tikv-v6.1.0-darwin-amd64.tar.gz 23.85 MiB / 23.85 MiB 100.00% 9.48 MiB/s                                
    Start tikv instance:v6.1.0
    Start tikv instance:v6.1.0
    Start tidb instance:v6.1.0
    The component `tidb` version v6.1.0 is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/tidb-v6.1.0-darwin-amd64.tar.gz 49.80 MiB / 49.80 MiB 100.00% 9.89 MiB/s                                
    Start tidb instance:v6.1.0
    Waiting for tidb instances ready
    127.0.0.1:4000 ... Done
    127.0.0.1:4001 ... Done
    The component `prometheus` version v6.1.0 is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/prometheus-v6.1.0-darwin-amd64.tar.gz 90.08 MiB / 90.08 MiB 100.00% 9.56 MiB/s                                                                                    
    download https://tiup-mirrors.pingcap.com/grafana-v6.1.0-darwin-amd64.tar.gz 47.19 MiB / 47.19 MiB 100.00% 9.99 MiB/s                                                                                       
    Start tiflash instance:v6.1.0
    The component `tiflash` version v6.1.0 is not installed; downloading from repository.
    download https://tiup-mirrors.pingcap.com/tiflash-v6.1.0-darwin-amd64.tar.gz 88.24 MiB / 88.24 MiB 100.00% 9.59 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 4001 -u root -p (no password)
    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 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
    

    这个过程居然不到1分钟,而且还包含了在线下载介质的时间..
    然后这个窗口最小化即可。

    4. 访问 TiDB 数据库

    新开启一个 session 以访问 TiDB 数据库: 到这里就完成了本机的测试环境部署,新开一个窗口测试连接,可以使用TiUP client 连接 TiDB:
    tiup client
    

    实际执行和输出结果:

    jingyuzhao@jingyuzhao-mac ~ % tiup client
    tiup is checking updates for component client ...
    Starting component `client`: /Users/jingyuzhao/.tiup/components/client/v1.10.2/tiup-client
    Connected with driver mysql (5.7.25-TiDB-v6.1.0)
    Type "help" for help.
    
    my:root@127.0.0.1:4000=> 
    my:root@127.0.0.1:4000=> show databases;
          Database      
    --------------------
     INFORMATION_SCHEMA 
     METRICS_SCHEMA 
     PERFORMANCE_SCHEMA 
     mysql 
     test 
    (5 rows)
    
    my:root@127.0.0.1:4000=>  
    

    也可使用 MySQL 客户端连接 TiDB:

    mysql --host 127.0.0.1 --port 4000 -u root
    

    我这里没装MySQL客户端,就不贴输出了,反正和上面类似一样的结果。

    5. 访问TiDB 的管理界面

    此外,这套环境还集成了常用图形化的管理、监控界面:

    通过 http://127.0.0.1:9090 访问 TiDB 的 Prometheus 管理界面。
    通过 http://127.0.0.1:2379/dashboard 访问 TiDB Dashboard 页面,默认用户名为 root,密码为空。
    通过 http://127.0.0.1:3000 访问 TiDB 的 Grafana 界面,默认用户名和密码都为 admin。

    6. 一键清理集群

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

    按下 Control+C 键停掉上述启用的 TiDB 服务。
    实际执行和输出结果:

    ^CPlayground receive signal:  interrupt
    Wait tiflash(18160) to quit...
    Wait grafana(17978) to quit...
    Wait prometheus(17728) to quit...
    Wait ng-monitoring(17729) to quit...
    Got signal interrupt (Component: playground ; PID: 17020)
    Grafana quit
    tiflash quit
    Wait tidb(17291) to quit...
    tikv quit
    prometheus quit
    tikv quit
    tikv quit
    ng-monitoring quit
    pd quit
    pd quit
    tidb quit
    Wait tidb(17292) to quit...
    pd quit
    Wait tikv(17205) to quit...
    tidb quit
    Wait tikv(17211) to quit...
    Wait tikv(17212) to quit...
    Wait pd(17115) to quit...
    Wait pd(17116) to quit...
    Wait pd(17117) to quit...
    jingyuzhao@jingyuzhao-mac ~ % 
    

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

    tiup clean --all
    

    实际执行和输出结果:

    jingyuzhao@jingyuzhao-mac ~ % tiup clean --all
    jingyuzhao@jingyuzhao-mac ~ % 
    

    7. 参考官方课程和文档

    这里再提一点感受,无论是课程设计还是官方手册内容编排,这一块基本不需要自己二次整理什么逻辑,课程简单易懂,官方文档的条理也非常清晰,切切实实的感受到了用心在做事情,在国产数据库中的确可以说是一股清流。如果要问对TiDB的第一印象如何,那么我个人觉得还是相当不错的,也愿意去做进一步的学习了解。

  • 相关阅读:
    centos git编译
    Unix/Linux小计
    centos gcc编译
    c++隐式转换(implicit conversion)
    通用c程序Makefile
    对弈的Python学习笔记
    LeetCode最长回文子串
    JDBC09 CLOB文本大对象
    JDBC08时间处理
    JDBC07 事务
  • 原文地址:https://www.cnblogs.com/jyzhao/p/16443140.html
Copyright © 2020-2023  润新知