tidb-使用tiup在线搭建tidb集群(代码片段)

小毕超 小毕超     2023-02-06     245

关键词:

一、TIUP简介

前面介绍了单机版本的环境搭建以及如何在docker中搭建环境,前面就讲到官方建议使用TiUP来搭建管理整个集群环境,下面我们来体验下。

TiUP 是 TiDB 4.0 版本引入的集群运维工具,TiUP cluster 是 TiUP 提供的使用 Golang 编写的集群管理组件,通过 TiUP cluster 组件就可以进行日常的运维工作,包括部署、启动、关闭、销毁、弹性扩缩容、升级 TiDB 集群,以及管理 TiDB 集群参数。

目前 TiUP 可以支持部署 TiDB、TiFlash、TiDB Binlog、TiCDC,以及监控系统。本文将介绍不同集群拓扑的具体部署步骤。

二、使用TIUP部署集群

整体架构

主机角色
192.168.40.130中控机,tidb-server,tikv-server,pd-server
192.168.40.158tikv-server,pd-server,monitoring_servers,grafana_servers,alertmanager_servers
192.168.40.159tikv-server,pd-server

tidb-server为无状态的服务这里搭建了一个节点作为测试,可通过lvs部署多个节点负载。注意:在生产环境中控机应该单独部署为一台主机中,管理整个集群。

下面开始安装,注意安装前关闭所有主机的防火墙和swap,以避免端口不通的问题。
临时关闭防火墙:

systemctl stop firewalld        

永久关闭防火墙,需要重启服务器:

systemctl disable firewalld

临时关闭swap:

swapoff -a

永久关闭swap,需要重启服务器:

sed -ri 's/.*swap.*/#&/' /etc/fstab

安装 TiUP 工具

以下所有操作均在中控机中执行。

1. 下载安装 TiUP 工具

curl --proto '=https' --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh

2. 声明全局环境变量

source /root/.bash_profile

3. 安装 TiUP cluster 组件

tiup cluster

4. 如果已经安装 TiUP cluster 组件,可以更新到最新版本

tiup update --self && tiup update cluster

使用 TiUP 工具部署TIDB集群

以下操作均在中控级中进行

1. 生成TIDB的配置模板

tiup cluster template > topology.yaml

2. 修改 topology.yaml 文件

这里主要修改,pd-server,tikv-server,tidb-server,monitoring_servers、grafana_servers、alertmanager_servers的ip,这里不安装tiflash-servers,先注释掉,下面是我的配置文件信息:

# 全局变量应用于所有部署,并用作的默认值
global:
  # 运行tidb集群的用户。
  user: "root"
  # 管理集群中服务器的SSH端口
  ssh_port: 22
  # 集群部署文件、启动脚本和配置文件的存放路径。
  deploy_dir: "/tidb-deploy"
  # TiDB集群数据存储目录
  data_dir: "/tidb-data"
  # 支持值:"amd64", "arm64"(默认值:"amd64")
  arch: "amd64"

# 监控变量应用于所有机器。
monitored:
  # TiDB集群中各节点上报系统信息的通信端口
  node_exporter_port: 9100
  # Blackbox_exporter 通信端口,用于TiDB集群端口监控。
  blackbox_exporter_port: 9115

# 服务器配置用于指定PD Servers的配置
pd_servers:
  - host: 192.168.40.130
  - host: 192.168.40.158
  - host: 192.168.40.159
    # # SSH port of the server.
    # ssh_port: 22
    # # PD Server name
    # name: "pd-1"
    # # communication port for TiDB Servers to connect.
    # client_port: 2379
    # # Communication port among PD Server nodes.
    # peer_port: 2380
    # # PD Server deployment file, startup script, configuration file storage directory.
    # deploy_dir: "/tidb-deploy/pd-2379"
    # # PD Server data storage directory.
    # data_dir: "/tidb-data/pd-2379"
    # # PD Server log file storage directory.
    # log_dir: "/tidb-deploy/pd-2379/log"
    # # numa node bindings.
    # numa_node: "0,1"
    # # The following configs are used to overwrite the `server_configs.pd` values.
    # config:
    #   schedule.max-merge-region-size: 20
    #   schedule.max-merge-region-keys: 200000
 

# 服务器配置用于指定TiDB服务器的配置。
tidb_servers:
  - host: 192.168.40.130
    # # SSH port of the server.
    # ssh_port: 22
    # # The port for clients to access the TiDB cluster.
    # port: 4000
    # # TiDB Server status API port.
    # status_port: 10080
    # # TiDB Server deployment file, startup script, configuration file storage directory.
    # deploy_dir: "/tidb-deploy/tidb-4000"
    # # TiDB Server log file storage directory.
    # log_dir: "/tidb-deploy/tidb-4000/log"

#  服务器配置用于指定TiKV服务器的配置。
tikv_servers:
  - host: 192.168.40.130
  - host: 192.168.40.158
  - host: 192.168.40.159
    # # SSH port of the server.
    # ssh_port: 22
    # # TiKV Server communication port.
    # port: 20160
    # # TiKV Server status API port.
    # status_port: 20180
    # # TiKV Server deployment file, startup script, configuration file storage directory.
    # deploy_dir: "/tidb-deploy/tikv-20160"
    # # TiKV Server data storage directory.
    # data_dir: "/tidb-data/tikv-20160"
    # # TiKV Server log file storage directory.
    # log_dir: "/tidb-deploy/tikv-20160/log"
    # # The following configs are used to overwrite the `server_configs.tikv` values.
    # config:
    #   log.level: warn

# 服务器配置用于指定Prometheus Server的配置。 
monitoring_servers:
  - host: 192.168.40.158
    # # SSH port of the server.
    # ssh_port: 22
    # # Prometheus Service communication port.
    # port: 9090
    # # Prometheus deployment file, startup script, configuration file storage directory.
    # deploy_dir: "/tidb-deploy/prometheus-8249"
    # # Prometheus data storage directory.
    # data_dir: "/tidb-data/prometheus-8249"
    # # Prometheus log file storage directory.
    # log_dir: "/tidb-deploy/prometheus-8249/log"

# 服务器配置用于指定Grafana服务器的配置。  
grafana_servers:
  - host: 192.168.40.158
    # # Grafana web port (browser access)
    # port: 3000
    # # Grafana deployment file, startup script, configuration file storage directory.
    # deploy_dir: /tidb-deploy/grafana-3000

# 服务器配置用于指定Alertmanager服务器的配置。 
alertmanager_servers:
  # # The ip address of the Alertmanager Server.
  - host: 192.168.40.158
    # # SSH port of the server.
    # ssh_port: 22
    # # Alertmanager web service port.
    # web_port: 9093
    # # Alertmanager communication port.
    # cluster_port: 9094
    # # Alertmanager deployment file, startup script, configuration file storage directory.
    # deploy_dir: "/tidb-deploy/alertmanager-9093"
    # # Alertmanager data storage directory.
    # data_dir: "/tidb-data/alertmanager-9093"
    # # Alertmanager log file storage directory.
    # log_dir: "/tidb-deploy/alertmanager-9093/log"

3. 检查和自动修复集群存在的潜在风险

tiup cluster check ./topology.yaml --apply --user root -p


如果出现Fail表示有错误,比如,在我部署过程中出现了numactl not usable, bash: numactl: command not found, auto fixing not supported的错误,是因为缺少了numactl工具,需要在每个部署主机安装numactl:

 yum -y install numactl.x86_64

出现其他错误可以参考下面这篇博客中的内容哦:

https://blog.csdn.net/whiteBearClimb/article/details/116058997

4. 部署 TiDB 集群
注意部署的tidb版本,可以通过 tiup cluster list 来查看现有的版本。tidb-test 表示集群的名称。

tiup cluster deploy tidb-test v5.0.0 ./topology.yaml --user root -p


执行上面指令会出现以上显示,输入y开始在每个节点下载。

出现上面的信息,就证明集群已经安装成功了。

5. 检查集群情况

tiup cluster display tidb-test


可以看到服务都处于停止状态,上面只是进行了集群的部署,启动还需进行集群的启动。

6. 启动集群

tiup cluster start tidb-test


到这里我们再查看下集群的状态:

tiup cluster display tidb-test


这下都处于启动状态了,下面可以通过mysql客户端进行连接测试了:

7. 使用navicat 连接TIDB

默认端口为4000,没有密码。

到这里集群就已经搭建成功了。

8. 查看监控monitoring服务

http://192.168.40.158:9090/


9. 查看grafana服务

http://192.168.40.158:3000

默认用户名和密码都是admin,确定后需要重置新密码,进去后可看到我们部署的tidb-test集群:

点击群可以查看每个组件的详细情况:


10. 查看告警管理alertmanager服务

http://192.168.40.158:9093

关于TIUP的详细指令介绍,可以参考下面一篇我的博客:https://blog.csdn.net/qq_43692950/article/details/121460770

在开发环境使用tiup安装tidb集群(代码片段)

...TiDB4.0版本引入的集群运维工具,TiUPcluster是TiUP提供的使用Golang编写的集群管理组件,通过TiUPcluster组件就可以进行日常的运维工作,包括部署、启动、关闭、销毁、弹性扩缩容、升级TiDB集群;管理TiDB集群参数。... 查看详情

在开发环境使用tiup安装tidb集群(代码片段)

...TiDB4.0版本引入的集群运维工具,TiUPcluster是TiUP提供的使用Golang编写的集群管理组件,通过TiUPcluster组件就可以进行日常的运维工作,包括部署、启动、关闭、销毁、弹性扩缩容、升级TiDB集群;管理TiDB集群参数。... 查看详情

tiup部署tidb数据库集群

一、部署本地测试集群(Linux版本)适用场景:利用本地Mac或者单机Linux环境快速部署TiDB测试集群,体验TiDB集群的基本架构,以及TiDB、TiKV、PD、监控等基础组件的运行。1、创建tidb用户组及用户[root@tidbhome]#groupaddtidb[root@tidbhome]#u... 查看详情

数据库必知必会:tidb(11)tidb数据库集群安装(代码片段)

(数据库必知必会:TiDB(11)TiDB数据库集群安装)TiDB数据库集群安装TiDB集群的安装,需要先安装一台中控机,然后通过中控机进行集群的安装及管理。单机环境上安装集群单机环境集群式将所有节点都安装在同一台服务器上。在... 查看详情

使用pingcapclinic诊断tidb集群(代码片段)

对于使用TiUP部署的TiDB集群和DM集群,PingCAPClinic诊断服务(以下简称为PingCAPClinic)可以通过Diag诊断客户端(以下简称为Diag)与ClinicServer云诊断平台(以下简称为ClinicServer)实现远程定位集群问题和本... 查看详情

猿创征文|国产数据库实战之使用docker部署tidb集群(代码片段)

猿创征文|国产数据库实战之使用Docker部署TiDB集群一、TiDB介绍1.TiDB简介2.TiDB特性3.TiDB集群整体架构4.TiDB集群各部分介绍5.本次TiDB集群组件二、检查本地环境1.检查docker状态2.检查docker版本3.检查docker-compose版本三、下载tidb-docker-comp... 查看详情

猿创征文|国产数据库实战之使用docker部署tidb集群(代码片段)

猿创征文|国产数据库实战之使用Docker部署TiDB集群一、TiDB介绍1.TiDB简介2.TiDB特性3.TiDB集群整体架构4.TiDB集群各部分介绍5.本次TiDB集群组件二、检查本地环境1.检查docker状态2.检查docker版本3.检查docker-compose版本三、下载tidb-docker-comp... 查看详情

猿创征文|国产数据库实战之使用docker部署tidb集群(代码片段)

猿创征文|国产数据库实战之使用Docker部署TiDB集群一、TiDB介绍1.TiDB简介2.TiDB特性3.TiDB集群整体架构4.TiDB集群各部分介绍5.本次TiDB集群组件二、检查本地环境1.检查docker状态2.检查docker版本3.检查docker-compose版本三、下载tidb-docker-comp... 查看详情

猿创征文|国产数据库实战之tidb数据库快速入门(代码片段)

...速入门一、系统检查1.检查系统版本2.查看本地IP地址3.TiDB集群介绍二、快速部署本地测试集群1.安装TiUP工具2.声明全局环境变量3.快速部署TiDB集群三、连接TiDB数据库1.新开一个session以访问TiDB数据库2.通过Mysql客户端连接TiDB数据库... 查看详情

tidb-docker环境集群搭建(代码片段)

一、TIDBTIDB的介绍已经在我上篇博客中介绍了,并且介绍了单机版的TIDB安装。TIDB-分布式关系型数据库讲解https://blog.csdn.net/qq_43692950/article/details/121304249本文继续就TIDB的部署进行讲解,当然官方的文档也写的比较详细࿰... 查看详情

tidb之mac上搭建及调试技巧

...问这个端口。第二个问题,我还是思考了一会,最后决定使用修改本机host的方式来完成映射。mac上需要增加的host如下:127.0.0.1pd0127.0.0.1pd1127.0.0.1pd2127.0.0.1tikv0127.0.0.1tikv1127.0.0.1tikv2大家一看也就明白了,我就是想把docker集群内部... 查看详情

tidb的安装与使用(代码片段)

一.下载安装包镜像wgethttp://download.pingcap.org/tidb-community-server-$version-linux-amd64.tar.gzmvtidb-community-server-$version-linux-amd64.tar.gzpackage.tar.gz其中$version处填入希望下载的离线镜像包版本,例如v4.0.0。此时,package.tar.gz就是一个... 查看详情

tidb修改配置参数

...化,那么如何持久化呢?a.手工修改TiDB的配置文件:b.并使用tiupedit-config来修改对应的配置项,不需要做tiupreload:内容如下:目前查看官方文档,发现只有3个只读变量:hostname、tidb_config、tidb_current_ts,没法通过setvariables修改。... 查看详情

tidb-使用tidbbinlog将日志同步至下游kafka中(代码片段)

一、TiDBBinlog在上篇文章中我们介绍了使用TiDBBinlog将数据同步至下游的Mysql中,本篇我们学习下使用TiDBBinlog工具将数据同步至Kafka中自定义业务逻辑,比如可以做TIDB和ES、MongoDB或Redis的数据同步,这功能就和Canal解析Mys... 查看详情

tidb-使用tidblightning迁移mysql数据至tidb中(代码片段)

...Mydumper或CSV输出格式的数据源。你可以在以下两种场景下使用Lightning:迅速导入大量新数据。备份恢复所有数据。TiDBLightning主要包含两个部分:tidb-lightning(“前端”):主要完成适配工作,通过读取数据源ÿ... 查看详情

使用tiupcluster在单机上模拟生产环境部署步骤(代码片段)

一实验环境适用场景:希望用单台Linux服务器,体验TiDB最小的完整拓扑的集群,并模拟生产的部署步骤。本节介绍如何参照TiUP最小拓扑的一个YAML文件部署TiDB集群。准备一台部署主机,确保其软件满足需求:... 查看详情

使用tiupcluster在单机上模拟生产环境部署步骤(代码片段)

一实验环境适用场景:希望用单台Linux服务器,体验TiDB最小的完整拓扑的集群,并模拟生产的部署步骤。本节介绍如何参照TiUP最小拓扑的一个YAML文件部署TiDB集群。准备一台部署主机,确保其软件满足需求:... 查看详情

使用dockercompose安装tidb(代码片段)

参考文章:https://blog.csdn.net/weixin_33729196/article/details/86018480目标单机上通过DockerCompose快速一键部署一套TiDB测试集群前提条件1.centos版本在7.3以上,内存大于6G2.安装git3.安装docker4.安装docker-compose开始安装1.下载tidb-docker-c 查看详情