安装单机部署TiDB
1、下载并安装 TiUP
curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh
2、声明全局环境变量
注意看第一步执行完的内容,页面的日志中会打印相关的source相关信息,直接复制执行即可
source ${your_shell_profile}
3、安装 TiUP 的 cluster 组件
tiup cluster
执行如上命令,若机器已经安装 TiUP cluster,需要更新软件版本:
tiup update --self && tiup update cluster
4、修改配置
由于模拟多机部署,需要通过 root 用户调大 sshd 服务的连接数限制:
- 修改 /etc/ssh/sshd_config 将 MaxSessions 调至 20。
- 重启 sshd 服务:
service sshd restart
5、创建并启动集群
- 按下面的配置模板,编辑配置文件,命名为 topo.yaml
- host:设置为本部署主机的 IP
# # Global variables are applied to all deployments and used as the default value of
# # the deployments if a specific deployment value is missing.
global:
user: "tidb"
ssh_port: 22
deploy_dir: "/tidb-deploy"
data_dir: "/tidb-data"
# # Monitored variables are applied to all the machines.
monitored:
node_exporter_port: 9100
blackbox_exporter_port: 9115
server_configs:
tidb:
log.slow-threshold: 300
tikv:
readpool.storage.use-unified-pool: false
readpool.coprocessor.use-unified-pool: true
pd:
replication.enable-placement-rules: true
replication.location-labels: ["host"]
tiflash:
logger.level: "info"
pd_servers:
- host: 192.168.30.43
tidb_servers:
- host: 192.168.30.43
tikv_servers:
- host: 192.168.30.43
port: 20160
status_port: 20180
config:
server.labels: { host: "logic-host-1" }
- host: 192.168.30.43
port: 20161
status_port: 20181
config:
server.labels: { host: "logic-host-2" }
- host: 192.168.30.43
port: 20162
status_port: 20182
config:
server.labels: { host: "logic-host-3" }
tiflash_servers:
- host: 192.168.30.43
monitoring_servers:
- host: 192.168.30.43
grafana_servers:
- host: 192.168.30.43
6、执行集群部署命令
#tiup cluster deploy <cluster-name> <tidb-version> ./topo.yaml --user root -p
tiup cluster deploy tidb_v640 v6.4.0 ./topo.yaml --user root -p
- 参数 <cluster-name> 表示设置集群名称
- 参数 <tidb-version> 表示设置集群版本,可以通过 tiup list tidb 命令来查看当前支持部署的 TiDB 版本
注意错误提示:ssh: unable to authenticate, attempted methods [none password], no supported methods remain
[root@HAST04 tidb]# tiup cluster deploy tidb_v640 v6.4.0 ./topo.yaml -i ~/.ssh/ --user root -p
tiup is checking updates for component cluster ...
Starting component `cluster`: /root/.tiup/components/cluster/v1.11.0/tiup-cluster deploy tidb_v640 v6.4.0 ./topo.yaml -i /root/.ssh/ --user root -p
Input SSH password:
+ Detect CPU Arch Name
- Detecting node 192.168.30.43 Arch info ... Error
Error: failed to fetch cpu-arch or kernel-name: executor.ssh.execute_failed: Failed to execute command over SSH for 'root@192.168.30.43:22' {ssh_stderr: , ssh_stdout: , ssh_command: export LANG=C; PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin uname -m}, cause: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none password], no supported methods remain
Verbose debug logs has been written to /root/.tiup/logs/tiup-cluster-debug-2022-11-22-17-07-18.log.
问题原因:跟TiDB依赖的SSH秘钥相关
解决方法:所在服务器上生成密钥,再次执行部署命令
[root@master spark]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
/root/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub. #注意此时可以看到公共密钥的位置存放地址,记住这个,下面会用到
The key fingerprint is:
SHA256:7bUrm6Bob+rSnLSXwp+uu8guOkZr+pNCOcp2Zzv6JVc root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| |
| |
| |
| . |
| . SE. . |
| = . .. . . |
|= o* + +. . . |
|=B+oO=Bo ... . |
|O***%#O oo. |
+----[SHA256]-----+
tiup cluster deploy tidb_v640 v6.4.0 ./topo.yaml --user root i
执行完如上的操作后,若还是继续报错,则继续向下执行:
vim /etc/ssh/sshd_config

[root@localhost tidb]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service
此时,继续向下执行,执行后的正确打印信息如下:
[root@HAST04 tidb]# tiup cluster deploy tidb_v640 v6.4.0 ./topo.yaml --user root i
tiup is checking updates for component cluster ...
Starting component `cluster`: /root/.tiup/components/cluster/v1.11.0/tiup-cluster deploy tidb_v640 v6.4.0 ./topo.yaml --user root i
+ Detect CPU Arch Name
- Detecting node 192.168.30.43 Arch info ... Done
+ Detect CPU OS Name
- Detecting node 192.168.30.43 OS info ... Done
Please confirm your topology:
Cluster type: tidb
Cluster name: tidb_v640
Cluster version: v6.4.0
Role Host Ports OS/Arch Directories
---- ---- ----- ------- -----------
pd 192.168.30.43 2379/2380 linux/x86_64 /tidb-deploy/pd-2379,/tidb-data/pd-2379
............等等
7、启动集群
[root@HAST04 tidb]# tiup cluster start tidb_v640
8、停止集群
[root@HAST04 tidb]#tiup cluster stop tidb_v640
9、查看集群状态
[root@HAST04 tidb]# tiup cluster display tidb_v640
#打印的集群信息如下
tiup is checking updates for component cluster ...
A new version of cluster is available:
The latest version: v1.11.1
Local installed version: v1.11.0
Update current component: tiup update cluster
Update all components: tiup update --all
Starting component `cluster`: /root/.tiup/components/cluster/v1.11.0/tiup-cluster display tidb_v640
Cluster type: tidb
Cluster name: tidb_v640
Cluster version: v6.4.0
Deploy user: tidb
SSH type: builtin
Dashboard URL: http://192.168.30.43:2379/dashboard #tidb的面板
Grafana URL: http://192.168.30.43:3000 #tidb的监控界面
ID Role Host Ports OS/Arch Status Data Dir Deploy Dir
-- ---- ---- ----- ------- ------ -------- ----------
192.168.30.43:3000 grafana 192.168.30.43 3000 linux/x86_64 Up - /tidb-deploy/grafana-3000
192.168.30.43:2379 pd 192.168.30.43 2379/2380 linux/x86_64 Up|L|UI /tidb-data/pd-2379 /tidb-deploy/pd-2379
192.168.30.43:9090 prometheus 192.168.30.43 9090/12020 linux/x86_64 Up /tidb-data/prometheus-9090 /tidb-deploy/prometheus-9090
192.168.30.43:4000 tidb 192.168.30.43 4000/10080 linux/x86_64 Up - /tidb-deploy/tidb-4000
192.168.30.43:9000 tiflash 192.168.30.43 9000/8123/3930/20170/20292/8234 linux/x86_64 N/A /tidb-data/tiflash-9000 /tidb-deploy/tiflash-9000
192.168.30.43:20160 tikv 192.168.30.43 20160/20180 linux/x86_64 Up /tidb-data/tikv-20160 /tidb-deploy/tikv-20160
192.168.30.43:20161 tikv 192.168.30.43 20161/20181 linux/x86_64 Up /tidb-data/tikv-20161 /tidb-deploy/tikv-20161
192.168.30.43:20162 tikv 192.168.30.43 20162/20182 linux/x86_64 Up /tidb-data/tikv-20162 /tidb-deploy/tikv-20162
Total nodes: 8
注意:从如上的信息中可以看出:
- tiflash状态为N/A:如果你不用tiflash的列存储,只是看tikv的事务能力,则可忽略tiflash的状态,若需要HTAP能力,则需要启动Tiflash,,首先查看tiflash的使用Ports端口是否均未被占用,若被占用,则停止掉被占用的进程,重新启动集群。
- tiflash状态为down:则需要等一会,tiflash的启动会相比较慢一些,过一会了再次查看集群状态即可
10、访问集群
- 安装 MySQL 客户端。如果已安装 MySQL 客户端则可跳过这一步骤。
yum -y install mysql
- 访问 TiDB 数据库,密码为空:
mysql -h 192.168.30.43 -P 4000 -u root
[root@HAST04 .ssh]# mysql -h 192.168.30.43 -P 4000 -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 407
Server version: 5.7.25-TiDB-v6.4.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible
Copyright (c) 2021, 2022 StoneAtom Group Holding Limited
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
- 访问 TiDB 的 Grafana 监控:
通过 http://192.168.30.43:3000/login 访问集群 Grafana 监控页面,默认用户名和密码均为 admin。
- 访问 TiDB 的 Dashboard:
通过http://192.168.30.43:2379/dashboard/访问集群 TiDB Dashboard 监控页面,默认用户名为 root,密码为空。
- 执行以下命令确认当前已经部署的集群列表:
tiup cluster list
- 执行以下命令查看集群的拓扑结构和状态:
tiup cluster display <cluster-name>
增加Tiflash
tiup ctl:v6.4.0 pd -u http://192.168.30.43:2379 config set enable-placement-rules true
1.作者:Syw 2.出处:http://www.cnblogs.com/syw20170419/ 3.本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。 4.如果文中有什么错误,欢迎指出。以免更多的人被误导。 |
分类:
TiDB
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?