在CentOS 8上安装单节点TiDB数据库集群
。
您可以通过以下链接以PDF格式下载本文来支持我们。
将指南下载为PDF
关
。
。
。
欢迎阅读今天有关如何在CentOS 8 Linux服务器上安装单节点TiDB数据库集群的文章。 TiDB是MySQL兼容的开源NewSQL数据库,它支持分析处理(HTAP)和混合事务工作负载。 TiDB的关键功能是高可用性,水平可伸缩性和强一致性。该数据库解决方案旨在用于OLTP(在线事务处理),OLAP(在线分析处理)和HTAP服务。
此设置在单个节点实例上运行,并且适用于实验室和开发环境。在需要高可用性集群且集群中至少有三台计算机的生产环境中,请勿参考本指南。请教 TiDB官方文档 生产要求和建议页面。检查一下 发行说明 了解所有新软件功能
在CentOS 8上安装单节点TiDB数据库集群
此设置是在具有以下硬件和软件要求的服务器上完成的:
- 操作系统:CentOS 8(64位)
- 记忆: 16 GB
- 中央处理器:8核+
- 磁盘空间:50 GB或更多
- root用户的SSH访问
- 服务器上的Internet访问
这些最低要求可能不足以使用其他组件(例如PD,TiKV,TiFlash,TiCDC和显示器)进行密集操作。在提交特定组件之前,请熟悉文档中提供的建议。
步骤1:更新服务器
在CentOS 8上开始安装TiDB数据库之前,请登录到您的机器并执行系统更新。
sudo dnf -y update
升级后重新启动系统。
sudo systemctl reboot
步骤2:停用系统交换和防火墙
TiDB需要足够的内存空间来进行操作,因此不建议进行交换。因此,我们建议您永久禁用系统交换。
echo "vm.swappiness = 0" | sudo tee -a /etc/sysctl.conf
sudo swapoff -a && sudo swapon -a
sudo sysctl -p
TiDB集群需要在节点之间打开访问端口,以确保它们发送诸如读写请求和数据心跳之类的信息。我们建议为此实验设置禁用firewalld。
sudo firewall-cmd --state
sudo systemctl status firewalld.service
检查是否要在防火墙中打开端口 网络端口 需求文件。
步骤3:下载并安装TiUP
然后将TiUP安装程序脚本下载到您的CentOS 8计算机上。
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh -o tiup_installer.sh
给出脚本的执行位。
chmod +x tiup_installer.sh
确保已安装tar软件包。
sudo yum -y install tar
运行脚本以开始安装。
sudo ./tiup_installer.sh
执行输出:
WARN: adding root certificate via internet: https://tiup-mirrors.pingcap.com/root.json
You can revoke this by remove /root/.tiup/bin/7b8e153f2e2d0928.root.json
Set mirror to https://tiup-mirrors.pingcap.com success
Detected shell: bash
Shell profile: /root/.bash_profile
/root/.bash_profile has been modified to to add tiup to PATH
open a new terminal or source /root/.bash_profile to use it
Installed path: /root/.tiup/bin/tiup
===============================================
Have a try: tiup playground
===============================================
更新了源bash配置文件。
source /root/.bash_profile
下一步是安装TiUP集群组件。
# tiup cluster
The component `cluster` is not installed; downloading from repository.
download https://tiup-mirrors.pingcap.com/cluster-v1.1.2-linux-amd64.tar.gz 9.87 MiB / 9.87 MiB 100.00% 9.28 MiB p/s
Starting component `cluster`:
Deploy a TiDB cluster for production
如果您的计算机上已经安装了TiUP集群,请更新软件版本。
# tiup update --self && tiup update cluster
download https://tiup-mirrors.pingcap.com/tiup-v1.1.2-linux-amd64.tar.gz 4.32 MiB / 4.32 MiB 100.00% 4.91 MiB p/s
Updated successfully!
component cluster version v1.1.2 is already installed
Updated successfully!
步骤4:创建并启动本地TiDB集群
由于TiUP需要模拟到多台计算机的部署,因此我们建议增加sshd服务的连接限制。
# vi /etc/ssh/sshd_config
MaxSessions 30
进行更改后,重新启动sshd服务。
sudo systemctl restart sshd
创建一个名为tidb-topology.yaml的拓扑配置文件。
cat >tidb-topology.yaml<
哪里:
- 用户:“ tidb”:使用tidb系统用户(在部署过程中自动创建)来执行集群的内部管理。默认情况下,端口22用于通过SSH登录到目标计算机。
- 复制。启用放置规则:设置此PD参数以确保TiFlash成功运行。
- 主办:目标机器的IP。
运行集群部署命令。
tiup cluster deploy ./tidb-topology.yaml --user root -p
交换:
替换为要使用的群集名称。 TiDB集群版本。使用以下命令获取所有受支持的TiDB版本。
# tiup list tidb
使用上述命令返回的最新版本。
# tiup cluster deploy local-tidb v4.0.6 ./tidb-topology.yaml --user root -p
”ÿ按下“键”并输入root用户密码以完成部署。
Attention:
1. If the topology is not what you expected, check your yaml file.
2. Please confirm there is no port/directory conflicts in same host.
Do you want to continue? [y/N]: y
Input SSH password:
+ Generate SSH keys ... Done
+ Download TiDB components
......
TiDB组件应该已经下载。
Input SSH password:
+ Generate SSH keys ... Done
+ Download TiDB components
- Download pd:v4.0.6 (linux/amd64) ... Done
- Download tikv:v4.0.6 (linux/amd64) ... Done
- Download tidb:v4.0.6 (linux/amd64) ... Done
- Download tiflash:v4.0.6 (linux/amd64) ... Done
- Download prometheus:v4.0.6 (linux/amd64) ... Done
- Download grafana:v4.0.6 (linux/amd64) ... Done
- Download node_exporter:v0.17.0 (linux/amd64) ... Done
- Download blackbox_exporter:v0.12.0 (linux/amd64) ... Done
+ Initialize target host environments
- Prepare 127.0.0.1:22 ... Done
+ Copy files
- Copy pd -> 127.0.0.1 ... Done
- Copy tikv -> 127.0.0.1 ... Done
- Copy tikv -> 127.0.0.1 ... Done
- Copy tikv -> 127.0.0.1 ... Done
- Copy tidb -> 127.0.0.1 ... Done
- Copy tiflash -> 127.0.0.1 ... Done
- Copy prometheus -> 127.0.0.1 ... Done
- Copy grafana -> 127.0.0.1 ... Done
- Copy node_exporter -> 127.0.0.1 ... Done
- Copy blackbox_exporter -> 127.0.0.1 ... Done
+ Check status
Deployed cluster `local-tidb` successfully, you can start the cluster via `tiup cluster start local-tidb`
启动集群。
# tiup cluster start local-tidb
输出示例:
....
Starting component pd
Starting instance pd 127.0.0.1:2379
Start pd 127.0.0.1:2379 success
Starting component node_exporter
Starting instance 127.0.0.1
Start 127.0.0.1 success
Starting component blackbox_exporter
Starting instance 127.0.0.1
Start 127.0.0.1 success
Starting component tikv
Starting instance tikv 127.0.0.1:20162
Starting instance tikv 127.0.0.1:20160
Starting instance tikv 127.0.0.1:20161
Start tikv 127.0.0.1:20161 success
Start tikv 127.0.0.1:20162 success
Start tikv 127.0.0.1:20160 success
Starting component tidb
Starting instance tidb 127.0.0.1:4000
Start tidb 127.0.0.1:4000 success
....
步骤5:访问TiDB集群
要查看当前部署的群集列表:
# tiup cluster list
Starting component `cluster`: /root/.tiup/components/cluster/v1.1.2/tiup-cluster list
Name User Version Path PrivateKey
---- ---- ------- ---- ----------
local-tidb tidb v4.0.6 /root/.tiup/storage/cluster/clusters/local-tidb /root/.tiup/storage/cluster/clusters/local-tidb/ssh/id_rsa
要查看集群的拓扑和状态:
# tiup cluster display local-tidb
Starting component `cluster`: /root/.tiup/components/cluster/v1.1.2/tiup-cluster display local-tidb
tidb Cluster: local-tidb
tidb Version: v4.0.6
ID Role Host Ports OS/Arch Status Data Dir Deploy Dir
-- ---- ---- ----- ------- ------ -------- ----------
127.0.0.1:3000 grafana 127.0.0.1 3000 linux/x86_64 inactive - /tidb-deploy/grafana-3000
127.0.0.1:2379 pd 127.0.0.1 2379/2380 linux/x86_64 Up|L|UI /tidb-data/pd-2379 /tidb-deploy/pd-2379
127.0.0.1:9090 prometheus 127.0.0.1 9090 linux/x86_64 inactive /tidb-data/prometheus-9090 /tidb-deploy/prometheus-9090
127.0.0.1:4000 tidb 127.0.0.1 4000/10080 linux/x86_64 Up - /tidb-deploy/tidb-4000
127.0.0.1:9000 tiflash 127.0.0.1 9000/8123/3930/20170/20292/8234 linux/x86_64 N/A /tidb-data/tiflash-9000 /tidb-deploy/tiflash-9000
127.0.0.1:20160 tikv 127.0.0.1 20160/20180 linux/x86_64 Up /tidb-data/tikv-20160 /tidb-deploy/tikv-20160
127.0.0.1:20161 tikv 127.0.0.1 20161/20181 linux/x86_64 Up /tidb-data/tikv-20161 /tidb-deploy/tikv-20161
127.0.0.1:20162 tikv 127.0.0.1 20162/20182 linux/x86_64 Up /tidb-data/tikv-20162 /tidb-deploy/tikv-20162
启动后,您可以使用mysql命令行客户端工具访问TiDB集群。
# yum install mariadb -y
# mysql -h 127.0.01 -P 4000 -u root
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MySQL connection id is 2
Server version: 5.7.25-TiDB-v4.0.6 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
MySQL [(none)]> SELECT VERSION();
+--------------------+
| VERSION() |
+--------------------+
| 5.7.25-TiDB-v4.0.6 |
+--------------------+
1 row in set (0.001 sec)
MySQL [(none)]> EXIT
访问仪表板:
- http:// {grafana-ip}:在3000处访问Grafana监控仪表板。默认用户名和密码
admin
.. - 进入 TiDB仪表板 http:// // {pd-ip}:2379 /位于仪表板上。默认用户名是
root
,密码为空。
下一步是什么
- 在为本地测试环境部署TiDB集群后,立即:
- 如果您准备将TiDB集群部署用于生产:
。
您可以通过以下链接以PDF格式下载本文来支持我们。
以PDF格式下载指南
关
。
。
。