暂无图片
暂无图片
5
暂无图片
暂无图片
暂无图片

快速体验 TiDB 5.0

1281

TiDB 是 平凯星辰 PingCAP 公司自主设计、研发的开源分布式关系型数据库,是一款同时支持在线事务处理与在线分析处理 (Hybrid Transactional and Analytical Processing, HTAP) 的融合型分布式数据库产品,具备水平扩容或者缩容、金融级高可用、实时 HTAP、云原生的分布式数据库、兼容 MySQL 5.7 协议和 MySQL 生态等重要特性。目标是为用户提供一站式 OLTP (Online Transactional Processing)、OLAP (Online Analytical Processing)、HTAP 解决方案。TiDB 适合高可用、强一致要求较高、数据规模较大等各种应用场景。今年四月份发布了 5.0 版本,具体的核心架构如下:
image.png

大体上由 TiDB 、TiKV 、 PD 三部分集群构成,Grafana 、dashboard 等监控服务,看了下面最小部署的拓扑图,个人学习想要在自己的笔记本上安装这么一套环境那绝对是不可能的。

image.png

但 TiDB 5.0 提供了一个 playground 的命令可以在个人笔记本上使用一台 Linux 机器模拟搭建一个集群环境,只要你的机器可联网就可以搭建出来。步骤很简单,下面我们一起体验一下吧。

首先需要一台 Linux 机器并可以上网,如何能够上网可参考我之前安装 openGauss 的文章。https://www.modb.pro/db/28668

网络适配器选择【NAT】模式,查看宿主机无线适配器关于 net8 的网络配置,然后 VM 里选择【编辑】——>【虚拟网络编辑器】——>【DHCP设置】,子网 IP 需要和前面看到的在同一网段里,然后选择 DHCP 自动获取。

image.png

网卡配置如下:


[root@JiekeXu-Test network-scripts]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.7 (Maipo)
[root@JiekeXu-Test network-scripts]# free -m 
              total        used        free      shared  buff/cache   available
Mem:           7802        5682         142          42        1977        1832
Swap:          6143           0        6143
[root@JiekeXu-Test network-scripts]# more ifcfg-ens32
TYPE="Ethernet"
PROXY_METHOD="none"
BROWSER_ONLY="no"
BOOTPROTO="dhcp"
DEFROUTE="yes"
IPV4_FAILURE_FATAL="yes"
IPV6INIT="yes"
IPV6_AUTOCONF="yes"
IPV6_DEFROUTE="yes"
IPV6_FAILURE_FATAL="no"
IPV6_ADDR_GEN_MODE="stable-privacy"
NAME="ens32"
UUID="e8332396-7724-410f-9887-1fc0e27fc818"
DEVICE="ens32"
ONBOOT="yes"
GATEWAY="192.168.75.2"
IPADDR="192.168.75.128"
PREFIX="24"
IPV6_PRIVACY="no"

下载并安装 TiUP

使用如下 curl 命令下载

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

image.png

source /root/.bash_profile

使用 tiup playground 模拟出一个集群环境

当然也可以指定各组件和实例个数

[root@JiekeXu-Test ~]# tiup playground v5.0.0 --db 2 --pd 3 --kv 3 --monitor

image.png
image.png

image.png

可以使用 MySQL 客户端或者 tiup client 连接到 TiDB 5.0

[root@JiekeXu-Test ~]# tiup client
选择客户端连接

image.png

image.png

[root@JiekeXu-Test ~]# tiup client
Starting component `client`: /root/.tiup/components/client/v1.5.2/tiup-client
Connected with driver mysql (5.7.25-TiDB-v5.0.0)
Type "help" for help.

my:root@127.0.0.1:4000=> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v5.0.0
Edition: Community
Git Commit Hash: bdac0885cd11bdf571aad9353bfc24e13554b91c
Git Branch: heads/refs/tags/v5.0.0
UTC Build Time: 2021-04-06 16:36:29
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

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=> use test;
USE
my:root@127.0.0.1:4000=> show tables;
(0 rows)

my:root@127.0.0.1:4000=> 
my:root@127.0.0.1:4000=> use mysql;
USE
my:root@127.0.0.1:4000=> show tables;
     Tables_in_mysql     
-------------------------
 GLOBAL_VARIABLES 
 bind_info 
 columns_priv 
 db 
 default_roles 
 expr_pushdown_blacklist 
 gc_delete_range 
 gc_delete_range_done 
 global_priv 
 help_topic 
 opt_rule_blacklist 
 role_edges 
 schema_index_usage 
 stats_buckets 
 stats_extended 
 stats_feedback 
 stats_fm_sketch 
 stats_histograms 
 stats_meta 
 stats_top_n 
 tables_priv 
 tidb 
 user 
(23 rows)

image.png

my:root@127.0.0.1:4001=> show databases;
      Database      
--------------------
 INFORMATION_SCHEMA 
 METRICS_SCHEMA 
 PERFORMANCE_SCHEMA 
 mysql 
 test 
(5 rows)

my:root@127.0.0.1:4001=> use METRICS_SCHEMA;
USE
my:root@127.0.0.1:4001=>  

image.png

MySQL 客户端连接

[root@JiekeXu-Test ~]# mysql --host 127.0.0.1 --port 4001 -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.25-TiDB-v5.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| INFORMATION_SCHEMA |
| METRICS_SCHEMA     |
| PERFORMANCE_SCHEMA |
| mysql              |
| test               |
+--------------------+
5 rows in set (0.00 sec)

MySQL [(none)]> select version();
+--------------------+
| version()          |
+--------------------+
| 5.7.25-TiDB-v5.0.0 |
+--------------------+
1 row in set (0.01 sec)

MySQL [(none)]> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MySQL [mysql]> 
MySQL [mysql]> show processlist;
+------+------+-----------------+-------+---------+------+------------+------------------+
| Id   | User | Host            | db    | Command | Time | State      | Info             |
+------+------+-----------------+-------+---------+------+------------+------------------+
|    9 | root | 127.0.0.1:43032 | mysql | Query   |    0 | autocommit | show processlist |
|   11 | root | 127.0.0.1:43182 | mysql | Sleep   |  127 | autocommit | NULL             |
+------+------+-----------------+-------+---------+------+------------+------------------+
2 rows in set (0.00 sec)

MySQL [mysql]> 

image.png

除了连接还可以登录监控系统,通过虚拟机图形界面打开火狐,通过 http://127.0.0.1:9090 访问 TiDB 的 Prometheus 管理界面。
通过 http://127.0.0.1:2379/dashboard 访问 TiDB Dashboard 页面,默认用户名为 root,密码为空。

image.png
image.png
image.png
image.png

当然本次只是一个快速体验,当 tiup playground v5.0.0 --db 2 --pd 3 --kv 3 --monitor 执行结果窗口 ctrl + c 取消后,集群也就不存在了,下次使用还得使用 tiup playground 命令,体验不是很好,希望能够继续改进改进。

image.png

[root@JiekeXu-Test ~]# tiup playground v5.0.0 --db 2 --pd 3 --kv 3 --monitor
Starting component `playground`: /root/.tiup/components/playground/v1.5.2/tiup-playground v5.0.0 --db 2 --pd 3 --kv 3 --monitor
Using the version v5.0.0 for version constraint "v5.0.0".

If you'd like to use a TiDB version other than v5.0.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 pd instance
Start pd instance
Start tikv instance
Start tikv instance
Start tikv instance
Start tidb instance
Start tidb instance
Waiting for tidb instances ready
127.0.0.1:4000 ... Done
127.0.0.1:4001 ... Done
Start tiflash instance
Waiting for tiflash instances ready
127.0.0.1:3930 ... Done
CLUSTER START SUCCESSFULLY, Enjoy it ^-^
To connect TiDB: mysql --host 127.0.0.1 --port 4000 -u root -p (no password) --comments
To connect TiDB: mysql --host 127.0.0.1 --port 4001 -u root -p (no password) --comments
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

如何使用备份恢复工具 BR 进行备份恢复,如何使用数据导出工具 Dumpling 等等,有机会在学习体验,今天的快速体验就先到这里咯,也欢迎更多小伙伴体验哦!以下是我的地址,欢迎更多小伙伴来撩。。。
———————————————————————————

公众号:JiekeXu DBA之路
墨天轮:https://www.modb.pro/u/4347
CSDN :https://blog.csdn.net/JiekeXu
腾讯云:https://cloud.tencent.com/developer/user/5645107

———————————————————————————
image.png

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
1人已赞赏
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论