引言
TiDB 是一款开源的分布式 NewSQL 数据库,支持在线弹性伸缩、自动故障恢复等特性,适用于在线事务处理(OLTP)和在线分析处理(OLAP)场景。本文将为您详细介绍如何在 CentOS 系统上安装并配置 TiDB 数据库。
环境说明
- 操作系统:CentOS 7.3
- CPU:8 核
- 内存:48GB
- 硬盘:100GB
- 网络情况:中控机与外网相连,中控机与部署机网络互通
第一步:安装 TiUP 工具
- 下载 TiUP 安装脚本:
curl --proto 'https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | bash
- 重新声明全局环境变量:
source .bashprofile
- 确认 TiUP 是否安装:
which tiup
- 安装 TiUP cluster 组件:
tiup cluster
- 查看 TiUP cluster 版本:
tiup --binary cluster
第二步:编写集群拓扑文件
- 创建集群拓扑文件
tidb-cluster.yml
:
global:
user: "tidb"
sshport: 22
deploydir: "/tidb-deploy"
datadir: "/tidb-data"
pd:
count: 1
ports:
- 9090
tikv:
count: 3
ports:
- 10101
tidb:
count: 2
ports:
- 4000
修改 sshport
为部署机实际的 SSH 端口。
修改 deploydir
和 datadir
为实际部署路径。
第三步:部署 TiDB 集群
- 部署 TiDB 集群:
tiup cluster deploy tidb-cluster tidb-cluster.yml
- 查看集群状态:
tiup cluster status tidb-cluster
第四步:访问 TiDB 集群
- 使用 MySQL 客户端连接 TiDB:
mysql -h 127.0.0.1 -P 4000 -u root -p
- 创建数据库并执行 SQL 语句:
CREATE DATABASE test;
USE test;
CREATE TABLE t1 (id INT PRIMARY KEY, name VARCHAR(100));
INSERT INTO t1 VALUES (1, 'TiDB');
SELECT * FROM t1;
总结
通过以上步骤,您已经成功在 CentOS 系统上安装并配置了 TiDB 数据库。接下来,您可以继续学习和使用 TiDB 的更多功能,为您的应用程序提供高性能、高可靠性的数据存储解决方案。