[root@shawnyan ~ 11:57:40]$ 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 5095k 100 5095k 0 0 5065k 0 0:00:01 0:00:01 --:--:-- 5069k Successfully set mirror to https://tiup-mirrors.pingcap.com Detected shell: bash Shell profile: /root/.bash_profile Installed path: /root/.tiup/bin/tiup =============================================== Have a try: tiup playground =============================================== [root@shawnyan ~ 11:57:46]$ source /root/.bash_profile
[root@shawnyan ~ 12:04:17]$ tiup cluster start mytidb --init Starting cluster mytidb... + [ Serial ] - SSHKeySet: privateKey=/root/.tiup/storage/cluster/clusters/mytidb/ssh/id_rsa, publicKey=/root/.tiup/storage/cluster/clusters/mytidb/ssh/id_rsa.pub + [Parallel] - UserSSH: user=tidb, host=192.168.8.161 ... + [ Serial ] - StartCluster Starting component pd Starting component tikv Starting component tidb Starting component tiflash Starting component prometheus Starting component grafana Starting component node_exporter Starting component blackbox_exporter + [ Serial ] - UpdateTopology: cluster=mytidb Started cluster `mytidb` successfully The root password of TiDB database has been changed. The new password is: '2mKNM_976^-+1h8BEL'. Copy and record it to somewhere safe, it is only displayed once, and will not be stored. The generated password can NOT be get and shown again.
[root@shawnyan ~ 12:05:20]$ mysql -h 192.168.8.161 -P 4000 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3290431496 Server version: 8.0.11-TiDB-v8.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select tidb_version()\G *************************** 1. row *************************** tidb_version(): Release Version: v8.0.0 Edition: Community Git Commit Hash: 8ba1fa452b1ccdbfb85879ea94b9254aabba2916 Git Branch: HEAD UTC Build Time: 2024-03-28 14:22:15 GoVersion: go1.21.4 Race Enabled: false Check Table Before Drop: false Store: tikv 1 row in set (0.00 sec)
mysql> \q Bye
查看 TiDB 集群列表。
1 2 3 4
[root@shawnyan ~ 12:05:46]$ tiup cluster list Name User Version Path PrivateKey ---- ---- ------- ---- ---------- mytidb tidb v8.0.0 /root/.tiup/storage/cluster/clusters/mytidb /root/.tiup/storage/cluster/clusters/mytidb/ssh/id_rsa
查看集群拓扑结构和状态。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
[root@shawnyan ~ 12:05:54]$ tiup cluster display mytidb Cluster type: tidb Cluster name: mytidb Cluster version: v8.0.0 Deploy user: tidb SSH type: builtin Dashboard URL: http://192.168.8.161:2379/dashboard Grafana URL: http://192.168.8.161:3000 ID Role Host Ports OS/Arch Status Data Dir Deploy Dir -- ---- ---- ----- ------- ------ -------- ---------- 192.168.8.161:3000 grafana 192.168.8.161 3000 linux/x86_64 Up - /tidb-deploy/grafana-3000 192.168.8.161:2379 pd 192.168.8.161 2379/2380 linux/x86_64 Up|L|UI /tidb-data/pd-2379 /tidb-deploy/pd-2379 192.168.8.161:9090 prometheus 192.168.8.161 9090/12020 linux/x86_64 Up /tidb-data/prometheus-9090 /tidb-deploy/prometheus-9090 192.168.8.161:4000 tidb 192.168.8.161 4000/10080 linux/x86_64 Up - /tidb-deploy/tidb-4000 192.168.8.161:9000 tiflash 192.168.8.161 9000/8123/3930/20170/20292/8234 linux/x86_64 Up /tidb-data/tiflash-9000 /tidb-deploy/tiflash-9000 192.168.8.161:20160 tikv 192.168.8.161 20160/20180 linux/x86_64 Up /tidb-data/tikv-20160 /tidb-deploy/tikv-20160 192.168.8.161:20161 tikv 192.168.8.161 20161/20181 linux/x86_64 Up /tidb-data/tikv-20161 /tidb-deploy/tikv-20161 Total nodes: 7 [root@shawnyan ~ 12:06:04]$
到此,仅用了不到 10 分钟,就部署完成了一套 TiDB 集群。
遥想当年写 Shell 脚本和 Ansible 脚本的岁月,有 TiUP 助力简直不要 Ti 幸福。
在 TiDB 集群进行滚动重启、滚动升级、缩容等维护操作时,TiDB server 会发生变动,导致客户端与发生变化的 TiDB server 的连接中断。通过使用 TiProxy,可以在这些维护操作过程中平滑地将连接迁移至其他 TiDB server,从而让客户端不受影响。
所有客户端对 TiDB server 的连接都无法动态迁移至其他 TiDB server。当多个 TiDB server 的负载不均衡时,可能出现整体集群资源充足,但某些 TiDB server 资源耗尽导致延迟大幅度增加的情况。为解决此问题,TiProxy 提供连接动态迁移功能,在客户端无感的前提下,将连接从一个 TiDB server 迁移至其他 TiDB server,从而实现 TiDB 集群的负载均衡。
[root@shawnyan ~ 12:54:46]$ mysql -h 192.168.8.161 -P 6000 -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 0 Server version: 8.0.11-TiDB-v8.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 8.0 compatible
Copyright (c) 2000, 2024, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> select version(); +--------------------+ | version() | +--------------------+ | 8.0.11-TiDB-v8.0.0 | +--------------------+ 1 row in set (0.01 sec)
mysql> \q Bye
测试 TiProxy 在集群缩容时对客户端的影响
一般情况下,在使用 TiProxy 时,对 TiDB Server 进行缩容操作,TiProxy 可以将客户端平滑迁移到其他 TiDB Server。
下面通过一个小案例进行演示。
当前 TiDB 集群有 1 个 TiProxy 和 2 个 TiDB Server。
1 2 3 4 5 6 7 8 9
[root@shawnyan ~ 22:54:11]$ tiup cluster display mytidb ... ID Role Host Ports OS/Arch Status Data Dir Deploy Dir -- ---- ---- ----- ------- ------ -------- ---------- 192.168.8.161:4000 tidb 192.168.8.161 4000/10080 linux/x86_64 Up - /tidb-deploy/tidb-4000 192.168.8.161:4001 tidb 192.168.8.161 4001/10081 linux/x86_64 Up - /tidb-deploy/tidb-4001 192.168.8.161:6000 tiproxy 192.168.8.161 6000/3080 linux/x86_64 Up - /tidb-deploy/tiproxy-6000 ... Total nodes: 9
[root@shawnyan ~ 23:54:02]$ date; tiup cluster scale-in mytidb -N 192.168.8.161:4001 Tue Apr 9 23:54:28 CST 2024 This operation will delete the 192.168.8.161:4001 nodes in `mytidb` and all their data. Do you want to continue? [y/N]:(default=N) y Scale-in nodes... ... Scaled cluster `mytidb` in successfully [root@shawnyan ~ 23:54:42]$