掌握TiDB数据库的安装部署

Posted 黑马程序员官方

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了掌握TiDB数据库的安装部署相关的知识,希望对你有一定的参考价值。

https://pingcap.com/docs-cn/stable/overview/#部署方式

一、部署方式选择

部署方式选择

tidb: TiDB is an open source distributed HTAP database compatible with the MySQL protocol

通过查阅官方文档和网友踩坑经验,我们学习测试时就就直接使用官网推荐的Docker Compose方式快速构建TiDB集群即可(或者使用单机版)

二、TiDB-Local单机版

部署TiDB就是摆在我们面前的第一节课,其实有很多的部署方式,限于环境,我先开始琢磨单机版如何部署。

在Centos 6的版本中如果要部署,这个难度还是比较大的,而且会有很多未知的坑,根据官方的建议,是需要在Centos 7以上的版本中,否则glibc的版本问题会很快碰到。

我们安装一套Centos7,采用快速的单机部署的方式来尝鲜。

  1. 下载安装包 wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz

  2. 解压文件 tar -zxvf tidb-latest-linux-amd64.tar.gz cd tidb-latest-linux-amd64

  3. 启动 启动PD ./bin/pd-server --data-dir=pd --log-file=pd.log & 启动tikv ./bin/tikv-server --pd="127.0.0.1:2379" --data-dir=tikv --log-file=tikv.log & 启动tidb-server ./bin/tidb-server --store=tikv --path="127.0.0.1:2379" --log-file=tidb.log &

  4. 登录: mysql -h 127.0.0.1 -P 4000 -u root Welcome to the MySQL monitor. Commands end with ; or \\g. Your MySQL connection id is 3 Server version: 5.7.25-TiDB-v4.0.0-beta-185-g065deca8f TiDB Server (Apache License 2.0), MySQL 5.7 compatible Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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.

  5. 体验

mysql> \\s

--------------

mysql Ver 14.14 Distrib 5.7.29, for Linux (x86_64) using EditLine wrapper

Connection id: 3

Current database:

Current user: root@127.0.0.1

SSL: Not in use

Current pager: stdout

Using outfile: ''

Using delimiter: ;

Server version: 5.7.25-TiDB-v4.0.0-beta-185-g065deca8f TiDB Server (Apache License 2.0), MySQL 5.7 compatible

Protocol version: 10

Connection: 127.0.0.1 via TCP/IP

Server characterset: utf8mb4

Db characterset: utf8mb4

Client characterset: utf8

Conn. characterset: utf8

TCP port: 4000

--------------

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| INFORMATION_SCHEMA |

| INSPECTION_SCHEMA |

| METRIC_SCHEMA |

| PERFORMANCE_SCHEMA |

| mysql |

| test |

+--------------------+

6 rows in set (0.00 sec)

mysql> select tidb_version();

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| tidb_version() |

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

| Release Version: v4.0.0-beta-185-g065deca8f

Git Commit Hash: 065deca8f00cd61b357ba0f1a61119d55111f758

Git Branch: master

UTC Build Time: 2020-02-20 12:18:56

GoVersion: go1.13

Race Enabled: false

TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306

Check Table Before Drop: false |

+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

mysql> select version();

+----------------------------------------+

| version() |

+----------------------------------------+

| 5.7.25-TiDB-v4.0.0-beta-185-g065deca8f |

+----------------------------------------+

1 row in set (0.00 sec)

mysql> select user,host from mysql.user;

+------+------+

| user | host |

+------+------+

| root | % |

+------+------+

1 row in set (0.00 sec)

mysql> exit

TiDB-Docker集群版

1.准备环境

确保你的机器上已安装:

Docker(17.06.0 及以上版本)

Docker Compose

Git

2.快速部署

下载 tidb-docker-compose

git clone GitHub - pingcap/tidb-docker-compose

3.创建并启动集群

获取最新 Docker 镜像:

cd tidb-docker-compose && docker-compose pull && docker-compose up -d

注意:

得先启动Docker

sudo systemctl start docker

再执行上面的docker-compose命令

4.访问集群

mysql -h 127.0.0.1 -P 4000 -u root

[root@node01 tidb-docker-compose]# mysql -h 127.0.0.1 -P 4000 -u root

Welcome to the MySQL monitor. Commands end with ; or \\g.

Your MySQL connection id is 1

Server version: 5.7.25-TiDB-v4.0.0-beta-177-g5a00c80e4 TiDB Server (Apache License 2.0), MySQL 5.7 compatible

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

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> show databases;

+--------------------+

| Database |

+--------------------+

| INFORMATION_SCHEMA |

| INSPECTION_SCHEMA |

| METRIC_SCHEMA |

| PERFORMANCE_SCHEMA |

| mysql |

| test |

+--------------------+

6 rows in set (0.00 sec)

mysql> exit

Bye

[root@node01 tidb-docker-compose]#

5.访问集群 Grafana 监控页面:

http://node01:3000/

默认用户名和密码均为 admin。

6.集群数据可视化:

http://node01:8010/

以上是关于掌握TiDB数据库的安装部署的主要内容,如果未能解决你的问题,请参考以下文章

安装部署TIDB分布式数据库

分布式数据库TiDB的部署

tidb部署

在开发环境使用 TiUP安装TiDB集群

在开发环境使用 TiUP安装TiDB集群

猿创征文 | 国产数据库实战之TiDB 数据库快速入门