TiDB版本7.4初体验与评测

网友投稿 305 2024-03-01



一、背景

随着公司业务的日益增长,以及国产化数据库的发展趋势,公司开始着手进行数据库国产化选型,主要考虑如下几个因素:

TiDB版本7.4初体验与评测

数据安全和合规性:在当前信息安全意识增强的环境下,公司对数据安全和合规性的要求日益提高。因此,选择一个符合国家相关法律法规要求的国产数据库可以降低数据泄露和违规风险。

数据性能和扩展性:随着业务的发展,公司的数据量和访问量可能会不断增加,因此需要一个具备良好性能和扩展性的数据库,以满足高并发访问、大规模存储和复杂查询等需求。

技术支持和生态系统:选择一个有稳定可靠的技术支持团队和完善的生态系统的国产数据库,可以提供及时的技术支持和解决方案,帮助公司快速响应和解决问题。

成本效益:作为一个企业,成本效益是选择国产数据库的重要考虑因素之一。相较于国外商业数据库,国产数据库可能拥有更具竞争力的价格,并且节约了跨境购买和维护成本。

综上所述,公司在进行数据库国产化选型时,需要考虑数据安全、性能、技术支持、成本效益等因素,以确保选择一个符合需求并具备竞争力的国产数据库。经过一段时间对TIDB的了解,刚好条件都符合,所以进行一下初步体验,本次主要测试playground方式运行和单机部署集群方式进行初步部署测试。

二、在线安装TiUP

1、设置环境变量,如果不修改默认会安装到/root/.tiup [root@dmdca /]# export TIUP_HOME=/data [root@dmdca /]# echo $TIUP_HOME /data

2、执行如下命令安装 TiUP 工具:

[root@dmdca /]# 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 7385k 100 7385k 0 0 7363k 0 0:00:01 0:00:01 --:--:-- 7363k WARN: adding root certificate via internet:https://tiup-mirrors.pingcap.com/root.json You can revoke this by remove /data/bin/7b8e153f2e2d0928.root.json Successfully set mirror to https://tiup-mirrors.pingcap.comDetected shell: bash Shell profile: /root/.bash_profile /root/.bash_profile has been modified to add tiup to PATH open a new terminal or source /root/.bash_profile to use it Installed path: /data/bin/tiup

3、按如下步骤设置 TiUP 环境变量: [root@dmdca /]# source .bash_profile -bash: .bash_profile: 没有那个文件或目录 [root@dmdca /]# source /root/.bash_profile

4、确认 TiUP 工具是否安装: [root@dmdca /]# which tiup /data/bin/tiup

5、安装 TiUP cluster 组件: [root@dmdca /]# tiup cluster tiup is checking updates for component cluster ... A new version of cluster is available: The latest version: v1.13.1 Local installed version:Update current component: tiup update cluster Update all components: tiup update --all

The component cluster version is not installed; downloading from repository. download https://tiup-mirrors.pingcap.com/cluster-v1.13.1-linux-amd64.tar.gz 8.74 MiB / 8.74 MiB 100.00% 15.06 MiB/sStarting component cluster: /data/components/cluster/v1.13.1/tiup-cluster Deploy a TiDB cluster for production

Usage: tiup cluster [command]

Available Commands: check Perform preflight checks for the cluster. deploy Deploy a cluster for production start Start a TiDB cluster stop Stop a TiDB cluster restart Restart a TiDB cluster scale-in Scale in a TiDB cluster scale-out Scale out a TiDB cluster destroy Destroy a specified cluster clean (EXPERIMENTAL) Cleanup a specified cluster upgrade Upgrade a specified TiDB cluster display Display information of a TiDB cluster prune Destroy and remove instances that is in tombstone state list List all clusters audit Show audit log of cluster operation import Import an exist TiDB cluster from TiDB-Ansible edit-config Edit TiDB cluster config show-config Show TiDB cluster config reload Reload a TiDB clusters config and restart if needed patch Replace the remote package with a specified package and restart the service rename Rename the cluster enable Enable a TiDB cluster automatically at boot disable Disable automatic enabling of TiDB clusters at boot replay Replay previous operation and skip successed steps template Print topology template tls Enable/Disable TLS between TiDB components meta backup/restore meta information rotatessh rotate ssh keys on all nodes help Help about any command completion Generate the autocompletion script for the specified shell

Flags: -c, --concurrency int max number of parallel tasks allowed (default 5) --format string (EXPERIMENTAL) The format of output, available values are [default, json] (default "default") -h, --help help for tiup --ssh string (EXPERIMENTAL) The executor type: builtin, system, none. --ssh-timeout uint Timeout in seconds to connect host via SSH, ignored for operations that dont need an SSH connection. (default 5) -v, --version version for tiup --wait-timeout uint Timeout in seconds to wait for an operation to complete, ignored for operations that dont fit. (default 120) -y, --yes Skip all confirmations and assumes yes

Use "tiup cluster help [command]" for more information about a command.

6、如果已经安装,则更新 TiUP cluster 组件至最新版本:

tiup update --self && tiup update cluster 预期输出 “Update successfully!” 字样。

验证当前 TiUP cluster 版本信息。执行如下命令查看 TiUP cluster 组件版本: [root@dmdca /]# tiup --binary cluster /data/components/cluster/v1.13.1/tiup-cluster [root@dmdca /]#

三、playground方式运行

以这种方式执行的 playground,在结束部署测试后 TiUP 会清理掉原集群数据,重新执行该命令后会得到一个全新的集群。 若希望持久化数据,可以执行 TiUP 的 --tag 参数:tiup --tag playground 1、直接运行 tiup playground 命令会运行最新版本的 TiDB 集群,其中 TiDB、TiKV、PD 和 TiFlash 实例各 1 个: tiup playground

2、也可以指定 TiDB 版本以及各组件实例个数,命令类似于: tiup playground v7.1.1 --db 2 --pd 3 --kv 3

3、指定host:不指定host默认只能本机127.0.0.1访问,指定0.0.0.0没有限制。 tiup playground --host 0.0.0.0

[root@dmdca /]# tiup playground --host 0.0.0.0tiup is checking updates for component playground ... Starting component playground: /data/components/playground/v1.13.1/tiup-playground --host 0.0.0.0 Using the version v7.4.0 for version constraint "".

If youd like to use a TiDB version other than v7.4.0, cancel and retry with the following arguments: Specify version manually: tiup playground Specify version range: tiup playground ^5 The nightly version: tiup playground nightly

Start pd instance:v7.4.0 Start tikv instance:v7.4.0 Start tidb instance:v7.4.0 Waiting for tidb instances ready 172.16.60.94:4000 ... Done Start tiflash instance:v7.4.0 tiflash quit: signal: segmentation fault Waiting for tiflash instances ready 172.16.60.94:3930 ... Error

Connect TiDB: mysql --comments --host 172.16.60.94 --port 4000 -u root TiDB Dashboard: http://172.16.60.94:2379/dashboard Grafana: http://0.0.0.0:3000

4、新开启一个 session 以访问 TiDB 数据库。 使用 TiUP client 连接 TiDB: tiup client

[root@dmdca bin]# tiup clientPlease check for root manifest file, you may download one from the repository mirror, or try tiup mirror setto force reset it. Error: initial repository from mirror(https://tiup-mirrors.pingcap.com/) failed: error loading manifest root.json: open /root/.tiup/bin/root.json: no such file or directory [root@dmdca bin]# cd [root@dmdca ~]# echo $TIUP_HOME

[root@dmdca ~]# pwd /root [root@dmdca ~]# vi .bash_profile 增加环境变量:export TIUP_HOME=/data,修改后配置如下:

.bash_profile

Get the aliases and functions

if [ -f ~/.bashrc ]; then . ~/.bashrc fi

User specific environment and startup programs

export TIUP_HOME=/data PATH=$PATH:$HOME/bin

export PATH

export PATH=/data/bin:$PATH

[root@dmdca ~]# source .bash_profile [root@dmdca ~]# tiup client tiup is checking updates for component client ... A new version of client is available: The latest version: v1.13.1 Local installed version:Update current component: tiup update client Update all components: tiup update --all

The component client version is not installed; downloading from repository. download https://tiup-mirrors.pingcap.com/client-v1.13.1-linux-amd64.tar.gz4.81 MiB / 4.81 MiB 100.00% 19.43 MiB/sStarting componentclient: /data/components/client/v1.13.1/tiup-client Connected with driver mysql (8.0.11-TiDB-v7.4.0) Type "help" for help.

my:root@172.16.60.94:4000=> show databases; Database

INFORMATION_SCHEMA METRICS_SCHEMA PERFORMANCE_SCHEMA mysql test (6 rows) my:root@172.16.60.94:4000=> use test; USE my:root@172.16.60.94:4000=> show tables; Tables_in_test

t_test (1 row)

my:root@172.16.60.94:4000=> select * from t_test; f_id | f_name------+----------------- 1 | 测试修改内容 2 | 测试修改内容 4 | test中文测试123 5 | test中文测试123 6 | test中文测试123 (5 rows)

my:root@172.16.60.94:4000=>my:root@172.16.60.94:4000=> quit

也可使用 MySQL 客户端连接 TiDB: mysql --host 127.0.0.1 --port 4000 -u root

[root@dmdca ~]# mysql --host 127.0.0.1 --port 4000 -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Your MySQL connection id is 845152332 Server version: 8.0.11-TiDB-v7.4.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible

Copyright (c) 2000, 2018, ***, 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 | +--------------------+ 6 rows in set (0.024 sec)

MySQL [(none)]> use test; 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 [test]> show tables; +------------------+ | Tables_in_hdtydb | +------------------+ | t_test | +------------------+ 1 row in set (0.001 sec)

MySQL [test]> select * from t_test; +------+---------------------+ | f_id | f_name | +------+---------------------+ | 1 | 测试修改内容 | | 2 | 测试修改内容 | | 4 | test中文测试123 | | 5 | test中文测试123 | | 6 | test中文测试123 | +------+---------------------+ 5 rows in set (0.003 sec)

MySQL [hdtydb]> MySQL [hdtydb]> quit Bye [root@dmdca ~]#

5、通过 http://127.0.0.1:9090 访问 TiDB 的 Prometheus 管理界面。(这里要输入操作系统的用户及密码。)

6、通过 http://127.0.0.1:2379/dashboard 访问 TiDB Dashboard 页面,默认用户名为 root,密码为空。

7、通过 http://127.0.0.1:3000 访问 TiDB 的 Grafana 界面,默认用户名和密码都为 admin。

8、(可选)将数据加载到 TiFlash 进行分析。

9、测试完成之后,可以通过执行以下步骤来清理集群: 按下 Control+C 键停掉上述启用的 TiDB 服务。 等待服务退出操作完成后,执行以下命令: tiup clean --all

四、在单机上模拟部署生产环境集群

1、适用场景:希望用单台 Linux 服务器,体验 TiDB 最小的完整拓扑的集群,并模拟生产环境下的部署步骤。 本节介绍如何参照 TiUP 最小拓扑的一个 YAML 文件部署 TiDB 集群。

2、准备环境 开始部署 TiDB 集群前,准备一台部署主机,确保其软件满足需求:

推荐安装 CentOS 7.3 及以上版本 运行环境可以支持互联网访问,用于下载 TiDB 及相关软件安装包 最小规模的 TiDB 集群拓扑包含以下实例:

实例 个数 IP 配置 TiKV 3 172.16.60.94 避免端口和目录冲突 172.16.60.94 避免端口和目录冲突 172.16.60.94 避免端口和目录冲突 TiDB 1 172.16.60.94 默认端口、全局目录配置 PD 1 172.16.60.94 默认端口、全局目录配置 TiFlash 1 172.16.60.94 默认端口、全局目录配置 Monitor 1 172.16.60.94 默认端口、全局目录配置

3、部署主机软件和环境要求如下:

部署需要使用部署主机的 root 用户及密码 部署主机关闭防火墙或者开放 TiDB 集群的节点间所需端口 目前 TiUP Cluster 支持在 x86_64(AMD64)和 ARM 架构上部署 TiDB 集群 在 AMD64 架构下,建议使用 CentOS 7.3 及以上版本 Linux 操作系统 在 ARM 架构下,建议使用 CentOS 7.6 1810 版本 Linux 操作系统

4、实施部署 注意 你可以使用 Linux 系统的任一普通用户或 root 用户登录主机,以下步骤以 root 用户为例。

下载并安装 TiUP: curl --proto =https --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh| sh 声明全局环境变量: 注意 TiUP 安装完成后会提示对应 Shell profile 文件的绝对路径。在执行以下 source 命令前,需要将 ${your_shell_profile} 修改为 Shell profile 文件的实际位置。 source ${your_shell_profile} 安装 TiUP 的 cluster 组件: tiup cluster 如果机器已经安装 TiUP cluster,需要更新软件版本: tiup update --self && tiup update cluster 由于模拟多机部署,需要通过 root 用户调大 sshd 服务的连接数限制: 修改 /etc/ssh/sshd_config 将 MaxSessions 调至 20。 重启 sshd 服务: service sshd restart 创建并启动集群 按下面的配置模板,编辑配置文件,命名为 topo.yaml,其中: user: "tidb":表示通过 tidb 系统用户(部署会自动创建)来做集群的内部管理,默认使用 22 端口通过 ssh 登录目标机器 replication.enable-placement-rules:设置这个 PD 参数来确保 TiFlash 正常运行 host:设置为本部署主机的 IP

配置模板如下:

# 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: 22 deploy_dir: "/data/tidb-deploy" data_dir: "/data/tidb-data"

# Monitored variables are applied to all the machines.

monitored: node_exporter_port: 9100 blackbox_exporter_port: 9115

server_configs: tidb: instance.tidb_slow_log_threshold: 300 tikv: readpool.storage.use-unified-pool: false readpool.coprocessor.use-unified-pool: true pd: replication.enable-placement-rules: true replication.location-labels: ["host"] tiflash: logger.level: "info"

pd_servers:

host: 172.16.60.94

tidb_servers:

host: 172.16.60.94

tikv_servers:

host: 172.16.60.94 port: 20160 status_port: 20180 config: server.labels: { host: "logic-host-1" }

host: 172.16.60.94 port: 20161 status_port: 20181 config: server.labels: { host: "logic-host-2" }

host: 172.16.60.94 port: 20162 status_port: 20182 config: server.labels: { host: "logic-host-3" }

tiflash_servers:

host: 172.16.60.94

monitoring_servers:

host: 172.16.60.94

grafana_servers:

host: 172.16.60.94 执行集群部署命令:

tiup cluster deploy ./topo.yaml --user root -p 参数 表示设置集群名称

参数 表示设置集群版本,例如 v7.1.1。可以通过 tiup list tidb 命令来查看当前支持部署的 TiDB 版本

参数 -p 表示在连接目标机器时使用密码登录

注意 如果主机通过密钥进行 SSH 认证,请使用 -i 参数指定密钥文件路径,-i 与 -p 不可同时使用。

按照引导,输入”y”及 root 密码,来完成部署:

Do you want to conti

[root@dmdca /]# pwd / [root@dmdca /]# vi topo.yaml [root@dmdca /]# tiup cluster deploy tidb-cluster v7.4.0 topo.yaml --user root -ptiup is checking updates for component cluster ... Starting componentcluster: /data/components/cluster/v1.13.1/tiup-cluster deploy tidb-cluster v7.4.0 topo.yaml --user root -p Input SSH password:

Detect CPU Arch Name

Detecting node 172.16.60.94 Arch info ... Done

Detect CPU OS Name

Detecting node 172.16.60.94 OS info ... Done Please confirm your topology: Cluster type: tidb Cluster name: tidb-cluster Cluster version: v7.4.0 Role Host Ports OS/Arch Directories

pd 172.16.60.94 2379/2380 linux/x86_64 /data/tidb-deploy/pd-2379,/data/tidb-data/pd-2379 tikv 172.16.60.94 20160/20180 linux/x86_64 /data/tidb-deploy/tikv-20160,/data/tidb-data/tikv-20160 tikv 172.16.60.94 20161/20181 linux/x86_64 /data/tidb-deploy/tikv-20161,/data/tidb-data/tikv-20161 tikv 172.16.60.94 20162/20182 linux/x86_64 /data/tidb-deploy/tikv-20162,/data/tidb-data/tikv-20162 tidb 172.16.60.94 4000/10080 linux/x86_64 /data/tidb-deploy/tidb-4000 tiflash 172.16.60.94 9000/8123/3930/20170/20292/8234 linux/x86_64 /data/tidb-deploy/tiflash-9000,/data/tidb-data/tiflash-9000 prometheus 172.16.60.94 9090/12020 linux/x86_64 /data/tidb-deploy/prometheus-9090,/data/tidb-data/prometheus-9090 grafana 172.16.60.94 3000 linux/x86_64 /data/tidb-deploy/grafana-3000 Attention: 1. If the topology is not what you expected, check your yam

Generate SSH keys ... Done

Download TiDB components

Download pd:v7.4.0 (linux/amd64) ... Done

Download tikv:v7.4.0 (linux/amd64) ... Done

Download tidb:v7.4.0 (linux/amd64) ... Done

Download tiflash:v7.4.0 (linux/amd64) ... Done

Download prometheus:v7.4.0 (linux/amd64) ... Done

Download grafana:v7.4.0 (linux/amd64) ... Done

Download node_exporter: (linux/amd64) ... Done

Download blackbox_exporter: (linux/amd64) ... Done

Initialize target host environments

Prepare 172.16.60.94:22 ... Done

Deploy TiDB instance

Copy pd -> 172.16.60.94 ... Done

Copy tikv -> 172.16.60.94 ... Done

Copy tikv -> 172.16.60.94 ... Done

Copy tikv -> 172.16.60.94 ... Done

Copy tidb -> 172.16.60.94 ... Done

Copy tiflash -> 172.16.60.94 ... Done

Copy prometheus -> 172.16.60.94 ... Done

Copy grafana -> 172.16.60.94 ... Done

Deploy node_exporter -> 172.16.60.94 ... Done

Deploy blackbox_exporter -> 172.16.60.94 ... Done

Copy certificate to remote host

Init instance configs

Generate config pd -> 172.16.60.94:2379 ... Done

Generate config tikv -> 172.16.60.94:20160 ... Done

Generate config tikv -> 172.16.60.94:20161 ... Done

Generate config tikv -> 172.16.60.94:20162 ... Done

Generate config tidb -> 172.16.60.94:4000 ... Done

Generate config tiflash -> 172.16.60.94:9000 ... Done

Generate config prometheus -> 172.16.60.94:9090 ... Done

Generate config grafana -> 172.16.60.94:3000 ... Done

Init monitor configs

Generate config node_exporter -> 172.16.60.94 ... Done

Generate config blackbox_exporter -> 172.16.60.94 ... Done Enabling component pd Enabling instance 172.16.60.94:2379 Enable instance 172.16.60.94:2379 success Enabling component tikv Enabling instance 172.16.60.94:20162 Enabling instance 172.16.60.94:20160 Enabling instance 172.16.60.94:20161 Enable instance 172.16.60.94:20160 success Enable instance 172.16.60.94:20161 success Enable instance 172.16.60.94:20162 success Enabling component tidb Enabling instance 172.16.60.94:4000 Enable instance 172.16.60.94:4000 success Enabling component tiflash Enabling instance 172.16.60.94:9000 Enable instance 172.16.60.94:9000 success Enabling component prometheus Enabling instance 172.16.60.94:9090 Enable instance 172.16.60.94:9090 success Enabling component grafana Enabling instance 172.16.60.94:3000 Enable instance 172.16.60.94:3000 success Enabling component node_exporter Enabling instance 172.16.60.94 Enable 172.16.60.94 success Enabling component blackbox_exporter Enabling instance 172.16.60.94 Enable 172.16.60.94 success Clustertidb-clusterdeployed successfully, you can start it with command:tiup cluster start tidb-cluster --init

启动集群:

tiup cluster start

[root@dmdca log]# tiup cluster start tidb-cluster tiup is checking updates for component cluster ... Starting component cluster: /data/components/cluster/v1.13.1/tiup-cluster start tidb-cluster Starting cluster tidb-cluster...

[ Serial ] - SSHKeySet: privateKey=/data/storage/cluster/clusters/tidb-cluster/ssh/id_rsa, publicKey=/data/storage/cluster/clusters/tidb-cluster/ssh/id_rsa.pub

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[Parallel] - UserSSH: user=tidb, host=172.16.60.94

[ Serial ] - StartCluster Starting component pd Starting instance 172.16.60.94:2379 Start instance 172.16.60.94:2379 success Starting component tikv Starting instance 172.16.60.94:20160 Starting instance 172.16.60.94:20162 Starting instance 172.16.60.94:20161 Start instance 172.16.60.94:20160 success Start instance 172.16.60.94:20161 success Start instance 172.16.60.94:20162 success Starting component tidb Starting instance 172.16.60.94:4000 Start instance 172.16.60.94:4000 success Starting component tiflash Starting instance 172.16.60.94:9000 Start instance 172.16.60.94:9000 success Starting component prometheus Starting instance 172.16.60.94:9090 Start instance 172.16.60.94:9090 success Starting component grafana Starting instance 172.16.60.94:3000 Start instance 172.16.60.94:3000 success Starting component node_exporter Starting instance 172.16.60.94 Start 172.16.60.94 success Starting component blackbox_exporter Starting instance 172.16.60.94 Start 172.16.60.94 success

[ Serial ] - UpdateTopology: cluster=tidb-cluster Started cluster tidb-clustersuccessfully [root@dmdca log]#

启动过程中有如下报错,多启动几次即可,可能是内存太小缘故,一共内存才4G,swap使用了6G,可用剩余内存只有600M. [root@dmdca log]# free -m total used free shared buff/cache available Mem: 4675 3904 125 50 645 437 Swap: 8191 6571 1620 [root@dmdca log]# free -g total used free shared buff/cache available Mem: 4 3 0 0 0 0 Swap: 7 6 1 [root@dmdca log]#

[root@dmdca /]# tiup cluster start tidb-cluster tiup is checking updates for component cluster ... Starting component cluster: /data/components/cluster/v1.13.1/tiup-cluster start tidb-cluster Starting cluster tidb-cluster...

[ Serial ] - SSHKeySet: privateKey=/data/storage/clus

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:TiDB新功能解读 DB和RG级别监控指标详细指南
下一篇:高并发场景下数据处理的关键是什么?探讨高并发下的技术挑战与解决方案
相关文章