前言
TiDB 是 PingCAP 公司自主设计、研发的开源分布式关系型数据库,是一款同时支持在线事务处理与在线分析处理 (Hybrid Transactional and Analytical Processing, HTAP) 的融合型分布式数据库产品,具备水平扩容或者缩容、金融级高可用、实时 HTAP、云原生的分布式数据库、兼容 MySQL 5.7 协议和 MySQL 生态等重要特性。目标是为用户提供一站式 OLTP (Online Transactional Processing)、OLAP (Online Analytical Processing)、HTAP 解决方案。
文章目录
1、部署方式选择
部署方式:部署方式https://pingcap.com/docs-cn/stable/overview/
通过查阅官方文档和网友踩坑经验,我们学习测试时就就直接使用官网推荐的Docker Compose方式快速构建TiDB集群即可(或者使用单机版)
2、TiDB-Local单机版
在Centos 6的版本中如果要部署,这个难度还是比较大的,而且会有很多未知的坑,根据官方的建议,是需要在Centos 7以上的版本中,否则glibc的版本问题会很快碰到。
我们安装一套Centos7,采用快速的单机部署的方式来尝鲜。
- 下载安装包
wget http://download.pingcap.org/tidb-latest-linux-amd64.tar.gz
- 解压文件
tar -zxvf tidb-latest-linux-amd64.tar.gz
cd tidb-latest-linux-amd64
- 启动
启动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 &
- 登录
mysql -h 127.0.0.1-P4000-u root
WelcometotheMySQLmonitor. Commands end with; or \g.
YourMySQL connection id is 3Server version:5.7.25-TiDB-v4.0.0-beta-185-g065deca8f TiDBServer(ApacheLicense2.0),MySQL5.7 compatible
Copyright(c)2000,2020,Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h'forhelp. Type'\c'toclear the current input statement.
- 体验
mysql> \s
--------------
mysql Ver14.14Distrib5.7.29,forLinux(x86_64) using EditLine wrapper
Connection id:3Current database:Current user: [email protected]
SSL:Not in use
Current pager: stdout
Using outfile: ''
Using delimiter:;Server version:5.7.25-TiDB-v4.0.0-beta-185-g065deca8f TiDBServer(ApacheLicense2.0),MySQL5.7 compatible
Protocol version:10Connection: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()|+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+|ReleaseVersion: v4.0.0-beta-185-g065deca8f
GitCommitHash:065deca8f00cd61b357ba0f1a61119d55111f758
GitBranch: master
UTC BuildTime:2020-02-2012:18:56GoVersion: go1.13RaceEnabled:falseTiKVMinVersion: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
CheckTableBeforeDrop: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
3、TiDB-Docker集群版
- 准备环境 确保你的机器上已安装: Docker(17.06.0 及以上版本) Docker Compose Git
- 快速部署 下载
tidb-docker-compose``````git clone
https://github.com/pingcap/tidb-docker-compose.git - 创建并启动集群
获取最新 Docker 镜像:
cd tidb-docker-compose && docker-compose pull && docker-compose up -d
**注意:
得先启动Docker
sudo systemctl start docker
再执行上面的docker-compose命令**
- 访问集群
mysql -h 127.0.0.1-P4000-u root
[root@node01 tidb-docker-compose]# mysql -h 127.0.0.1-P4000-u root
WelcometotheMySQLmonitor. Commands end with; or \g.
YourMySQL connection id is 1Server version:5.7.25-TiDB-v4.0.0-beta-177-g5a00c80e4 TiDBServer(ApacheLicense2.0),MySQL5.7 compatible
Copyright(c)2000,2020,Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of OracleCorporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type'help;' or '\h'forhelp. Type'\c'toclear 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]#
- 访问集群 Grafana 监控页面
http://node01:3000/
默认用户名和密码均为 admin。 - 集群数据可视化
http://node01:8010/
4、补充内容
(1)CentOS安装MySQL
- 下载并安装MySQL官方的 Yum Repository
wget -i -c
http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
- yum安装
yum -y install mysql57-community-release-el7-10.noarch.rpm
- 安装MySQL服务器
yum -y install mysql-community-server
- 启动MySQL
systemctl start mysqld.service
- 查看MySQL运行状态
systemctl status mysqld.service
- 设置开机启动
systemctl enable mysqld
- 找出输入初始密码:
grep "password" /var/log/mysqld.log
- 进入数据库:
mysql -uroot -p
- 修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root@1234';
注意:密码设置必须要大小写字母数字和特殊符号(,/';:等),不然不能配置成功
- 开启mysql的远程访问
grant all privileges on *.* to'root'@'%' identified by 'Root@1234' withgrant option;
flush privileges;
exit
(2)CentOS安装Git
- 查看是否安装过git,若出现版本号,则代表已经安装了git
git --version
- 使用yum安装git
yum -y install git
版权归原作者 热爱编程的小点点 所有, 如有侵权,请联系我们删除。