TiDB已经发布到6.4版本,此篇文章根据TiDB官方文档,可以很便捷的部署一套测试单机 TiDB 集群环境,用于平时手头练习用。
既然都是国产数据库了,那操作系统也需要使用麒麟 kylin V10 SP2
操作系统环境:
[root@192 ~]# nkvers############## Kylin Linux Version #################Release:Kylin Linux Advanced Server release V10 (Sword)Kernel:4.19.90-24.4.v2101.ky10.x86_64Build:Kylin Linux Advanced Serverrelease V10 (SP2) (Sword)-x86_64-Build09/20210524#################################################
安装步骤如下:
1. 下载并安装TiUP 工具:
打开终端
Linux: 进入Terminal
执行以下命令,下载并安装TiUP 工具。注意 $ 为终端提示符, 常见的也有可能是 %:
[root@192 ~]# curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
% Total % Received % Xferd Average Speed Time Time Time CurrentDload Upload Total Spent Left Speed100 7085k 100 7085k 0 0 1311k 0 0:00:05 0:00:05 --:--:-- 1317kSuccessfully set mirror to https://tiup-mirrors.pingcap.comDetected shell: bashShell profile: /root/.bash_profileInstalled path: /root/.tiup/bin/tiup===============================================Have a try: tiup playground===============================================
[root@192 ~]# export PATH=~/.tiup/bin:$PATH
2. 启动集群 (指定各个组件的实例数量),保持会话窗口打开:
[root@192 ~]# tiup playground v6.0.0 --tag classroom --db 3 --pd 3 --kv 3 --tiflash 1
tiup is checking updates for component playground ...Starting component `playground`: /root/.tiup/components/playground/v1.11.0/tiup-playground v6.0.0 --tag classroom --db 3 --pd 3 --kv 3 --tiflash 1Playground Bootstrapping...Start pd instance:v6.0.0Start pd instance:v6.0.0Start pd instance:v6.0.0Start tikv instance:v6.0.0Start tikv instance:v6.0.0Start tikv instance:v6.0.0Start tidb instance:v6.0.0Start tidb instance:v6.0.0Start tidb instance:v6.0.0。。。check detail log from: /root/.tiup/data/classroom/tikv-2/tikv.logWaiting for tiflash instances ready127.0.0.1:3930 ... ErrorCLUSTER START SUCCESSFULLY, Enjoy it ^-^To connect TiDB: mysql --comments --host 127.0.0.1 --port 4002 -u root -p (no password)To connect TiDB: mysql --comments --host 127.0.0.1 --port 4000 -u root -p (no password)To connect TiDB: mysql --comments --host 127.0.0.1 --port 4001 -u root -p (no password)To view the dashboard: http://127.0.0.1:2379/dashboardPD 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:9090To view the Grafana: http://127.0.0.1:3000
3. 打开另一个终端,执行以下命令使用数据库客户端访问 TiDB 数据库,出现"mysql> "提示符:
[root@mysqlSlave ~]# mysql -h 127.0.0.1 -P 4000 -urootWelcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 407Server version: 5.7.25-TiDB-v6.0.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatibleCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database |+--------------------+| INFORMATION_SCHEMA || METRICS_SCHEMA || PERFORMANCE_SCHEMA || mysql || test |+--------------------+5 rows in set (0.00 sec)
4. 查看数据库版本,随机数和当前时间:
mysql> select connection_id(), version(), rand(), now();+-----------------+--------------------+--------------------+---------------------+| connection_id() | version() | rand() | now() |+-----------------+--------------------+--------------------+---------------------+| 407 | 5.7.25-TiDB-v6.0.0 | 0.3019098567794169 | 2022-11-20 22:29:01 |+-----------------+--------------------+--------------------+---------------------+1 row in set (0.00 sec)
5. 退出数据库会话 (如有必要)
exit
6. 停止测试集群:
回到第一个终端,按下ctrl + c 键停掉测试集群 (请勿连续按 ctrl + c,一次就够了, 耐心等待终端提示符的出现,比如 $ 或 %)
ctrl + c
7. 再次启动集群
$ tiup playground --tag classroom --db 2 --pd 3 --kv 3 --tiflash 1[root@192 ~]# tiup playground --tag classroom --db 2 --pd 3 --kv 3 --tiflash 1tiup is checking updates for component playground ...Starting component `playground`: /root/.tiup/components/playground/v1.11.0/tiup-playground v6.0.0 --tag classroom --db 3 --pd 3 --kv 3 --tiflash 1Playground Bootstrapping...Start pd instance:v6.0.0Start pd instance:v6.0.0Start pd instance:v6.0.0Start tikv instance:v6.0.0Start tikv instance:v6.0.0Start tikv instance:v6.0.0Start tidb instance:v6.0.0Start tidb instance:v6.0.0Start tidb instance:v6.0.0Waiting for tidb instances ready127.0.0.1:4000 ... ⠹127.0.0.1:4001 ... ⠹127.0.0.1:4002 ... ⠹
参考链接
https://learn.pingcap.com/learner/player/630005;id=630005;source=DETAIL;classroomId=960002;courseDetailId=600003;learnerAttemptId=1668919952822
文章至此。
以下是个人微信公众号,欢迎关注:





