手把手教你搭建Tidb最新版4.0集群

导读

作者:杨漆
16年关系型数据库管理,从oracle 9i 、10g、11g、12c到Mysql5.5、5.6、5.7、8.0 到TiDB获得3个OCP、2个OCM;运维路上不平坦,跌过不少坑、熬过许多夜。把工作笔记整理出来分享给大伙儿,希望帮到大家少走弯路、少熬夜。

TiUP部署Tidb Cluster

TiUP 是 TiDB 4.0 版本引入的集群运维工具,TiUP cluster 是 TiUP 提供的使用 Golang 编写的集群管理组件,通过 TiUP cluster 组件就可以进行日常的运维工作,包括部署、启动、关闭、销毁、弹性扩缩容、升级 TiDB 集群、管理 TiDB 集群参数。
目前 TiUP 可以支持部署 TiDB、TiFlash、TiDB Binlog、TiCDC,以及监控系统。
第 1 步:软硬件环境需求及前置检查在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
注意:
生产环境中的 TiDB 和 PD 可以部署和运行在同服务器上,如对性能和可靠性有更高的要求,应尽可能分开部署。
生产环境强烈推荐使用更高的配置。
TiKV 硬盘大小配置建议 PCI-E SSD 不超过 2 TB,普通 SSD 不超过 1.5 TB。
TiFlash 支持多盘部署。
TiFlash 数据目录的第一块磁盘推荐用高性能 SSD 来缓冲 TiKV 同步数据的实时写入,该盘性能应不低于 TiKV 所使用的磁盘,比如 PCI-E SSD。并且该磁盘容量建议不小于总容量的 10%,否则它可能成为这个节点的能承载的数据量的瓶颈。而其他磁盘可以根据需求部署多块普通 SSD,当然更好的 PCI-E SSD 硬盘会带来更好的性能。
TiFlash 推荐与 TiKV 部署在不同节点,如果条件所限必须将 TiFlash 与 TiKV 部署在相同节点,则需要适当增加 CPU 核数和内存,且尽量将 TiFlash 与 TiKV 部署在不同的磁盘,以免互相干扰。
TiFlash 硬盘总容量大致为:整个 TiKV 集群的需同步数据容量 / TiKV 副本数 * TiFlash 副本数。例如整体 TiKV 的规划容量为 1 TB、TiKV 副本数为 3、TiFlash 副本数为 2,则 TiFlash 的推荐总容量为 1024 GB / 3 * 2。用户可以选择同步部分表数据而非全部,具体容量可以根据需要同步的表的数据量具体分析。
TiCDC 硬盘配置建议 200 GB+ PCIE-SSD。在这里插入图片描述
TiKV 部署目标机器上添加数据盘 EXT4 文件系统挂载参数
生产环境部署,建议使用 EXT4 类型文件系统的 NVME 类型的 SSD 磁盘存储 TiKV 数据文件。这个配置方案为最佳实施方案,其可靠性、安全性、稳定性已经在大量线上场景中得到证实。
使用 root 用户登录目标机器,将部署目标机器数据盘格式化成 ext4 文件系统,挂载时添加 nodelalloc 和 noatime 挂载参数。nodelalloc 是必选参数,否则 TiUP 安装时检测无法通过;noatime 是可选建议参数
注意:
如果你的数据盘已经格式化成 ext4 并挂载了磁盘,可先执行 umount /dev/nvme0n1p1 命令卸载,从编辑 /etc/fstab 文件步骤开始执行,添加挂载参数重新挂载即可。

以 /dev/nvme0n1 数据盘为例,具体操作步骤如下:
1.查看数据盘:
fdisk -l

Disk /dev/nvme0n1: 1000 GB
2.创建分区:
parted -s -a optimal /dev/nvme0n1 mklabel gpt – mkpart primary ext4 1 -1

注意:
使用 lsblk 命令查看分区的设备号:对于 nvme 磁盘生成的分区设备号一般为 nvme0n1p1;对于普通磁盘(例如 /dev/sdb),生成的的分区设备号一般为 sdb1

  1. 格式化文件系统:
    mkfs.ext4 /dev/nvme0n1p1

  2. 查看数据盘分区UUID:在这里插入图片描述
    检测及关闭系统 swap
    TiDB 运行需要有足够的内存,并且不建议使用 swap 作为内存不足的缓冲,这会降低性能。因此建议永久关闭系统 swap,并且不要使用 swapoff -a 方式关闭,否则重启机器后该操作会失效。在这里插入图片描述
    检测及关闭目标部署机器的防火墙
    在 TiDB 集群中,需要将节点间的访问端口打通才可以保证读写请求、数据心跳等信息的正常的传输。在普遍线上场景中,数据库到业务服务和数据库节点的网络联通都是在安全域内完成数据交互。如果没有特殊安全的要求,建议将目标节点的防火墙进行关闭。否则建议按照端口使用规则,将端口信息配置到防火墙服务的白名单中。在这里插入图片描述
    检测及安装 NTP 服务
    TiDB 是一套分布式数据库系统,需要节点间保证时间的同步,从而确保 ACID 模型的事务线性一致性。目前解决授时的普遍方案是采用 NTP 服务,可以通过互联网中的 pool.ntp.org 授时服务来保证节点的时间同步,也可以使用离线环境自己搭建的 NTP 服务来解决授时。
    采用如下步骤检查是否安装 NTP 服务以及与 NTP 服务器正常同步:
    1.执以下命令,如果输出 running 表示 NTP 服务正在运行:
    sudo systemctl status ntpd.service在这里插入图片描述
    1.执行 ntpstat 命令检测是否与 NTP 服务器同步:在这里插入图片描述
    手动配置 SSH 互信及 sudo 免密码
    对于有需求,通过手动配置中控机至目标节点互信的场景,可参考本段。通常推荐使用 TiUP 部署工具会自动配置 SSH 互信及免密登陆,可忽略本段内容在这里插入图片描述
    在这里插入图片描述
    第 2 步:在中控机上安装 TiUP 组件
    使用普通用户登录中控机,以 tidb 用户为例,后续安装 TiUP 及集群管理操作均通过该用户完成:
    1.执行如下命令安装 TiUP 工具:
    curl --proto ‘=https’ --tlsv1.2 -sSf https://tiup-mirrors.pingcap.com/install.sh | sh在这里插入图片描述
    第 3 步:编辑初始化配置文件
    请根据不同的集群拓扑,编辑 TiUP 所需的集群初始化配置文件。
    这里举出常见的 6 种场景,请根据链接中的拓扑说明,以及给出的配置文件模板,新建一个配置文件 topology.yaml。如果有其他组合场景的需求,请根据多个模板自行调整。

A. 最小拓扑架构
最基本的集群拓扑,包括 tidb-server、tikv-server、pd-server,适合 OLTP 业务。在这里插入图片描述

  1. 简易配置如下:
    cat simple-mini.yaml

# 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”

pd_servers:

  • host: 10.0.1.4
  • host: 10.0.1.5
  • host: 10.0.1.6

tidb_servers:

  • host: 10.0.1.1
  • host: 10.0.1.2
  • host: 10.0.1.3

tikv_servers:

  • host: 10.0.1.7
  • host: 10.0.1.8
  • host: 10.0.1.9

monitoring_servers:

  • host: 10.0.1.10

grafana_servers:

  • host: 10.0.1.10

alertmanager_servers:

  • host: 10.0.1.10
  1. 详细配置:
    cat complex-mini.yaml

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

deploy_dir: “/tidb-deploy/monitored-9100”

data_dir: “/tidb-data/monitored-9100”

log_dir: “/tidb-deploy/monitored-9100/log”

# Server configs are used to specify the runtime configuration of TiDB components.

# All configuration items can be found in TiDB docs:

# - TiDB: https://pingcap.com/docs/stable/reference/configuration/tidb-server/configuration-file/

- TiKV: https://pingcap.com/docs/stable/reference/configuration/tikv-server/configuration-file/

# - PD: https://pingcap.com/docs/stable/reference/configuration/pd-server/configuration-file/

# All configuration items use points to represent the hierarchy, e.g:

# readpool.storage.use-unified-pool

# You can overwrite this configuration via the instance-level config field.

server_configs:
tidb:
log.slow-threshold: 300
binlog.enable: false
binlog.ignore-error: false
tikv:
# server.grpc-concurrency: 4
# raftstore.apply-pool-size: 2
# raftstore.store-pool-size: 2
# rocksdb.max-sub-compactions: 1
# storage.block-cache.capacity: “16GB”
# readpool.unified.max-thread-count: 12
readpool.storage.use-unified-pool: false
readpool.coprocessor.use-unified-pool: true
pd:
schedule.leader-schedule-limit: 4
schedule.region-schedule-limit: 2048
schedule.replica-schedule-limit: 64

pd_servers:

  • host: 10.0.1.4

    ssh_port: 22

    name: “pd-1”

    client_port: 2379

    peer_port: 2380

    deploy_dir: “/tidb-deploy/pd-2379”

    data_dir: “/tidb-data/pd-2379”

    log_dir: “/tidb-deploy/pd-2379/log”

    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

  • host: 10.0.1.5
  • host: 10.0.1.6

tidb_servers:

  • host: 10.0.1.1

    ssh_port: 22

    port: 4000

    status_port: 10080

    deploy_dir: “/tidb-deploy/tidb-4000”

    log_dir: “/tidb-deploy/tidb-4000/log”

    numa_node: “0,1”

    # The following configs are used to overwrite the server_configs.tidb values.

    config:

    log.slow-query-file: tidb-slow-overwrited.log

  • host: 10.0.1.2
  • host: 10.0.1.3

tikv_servers:

  • host: 10.0.1.7

    ssh_port: 22

    port: 20160

    status_port: 20180

    deploy_dir: “/tidb-deploy/tikv-20160”

    data_dir: “/tidb-data/tikv-20160”

    log_dir: “/tidb-deploy/tikv-20160/log”

    numa_node: “0,1”

    # The following configs are used to overwrite the server_configs.tikv values.

    config:

    server.grpc-concurrency: 4

    server.labels: { zone: “zone1”, dc: “dc1”, host: “host1” }

  • host: 10.0.1.8
  • host: 10.0.1.9

monitoring_servers:

  • host: 10.0.1.10

    ssh_port: 22

    port: 9090

    deploy_dir: “/tidb-deploy/prometheus-8249”

    data_dir: “/tidb-data/prometheus-8249”

    log_dir: “/tidb-deploy/prometheus-8249/log”

grafana_servers:

  • host: 10.0.1.10

    port: 3000

    deploy_dir: /tidb-deploy/grafana-3000

alertmanager_servers:

  • host: 10.0.1.10

ssh_port: 22

# web_port: 9093 
# cluster_port: 9094 
# deploy_dir: "/tidb-deploy/alertmanager-9093" 
# data_dir: "/tidb-data/alertmanager-9093" 
# log_dir: "/tidb-deploy/alertmanager-9093/log" ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210318102812243.jpg#pic_center)

B. 增加 TiFlash 拓扑架构
包含最小拓扑的基础上,同时部署 TiFlash
TiFlash 是列式的存储引擎,已经逐步成为集群拓扑的标配。适合 Real-Time HTAP 业务。在这里插入图片描述
1.简易配置如下:
cat simple-tiflash.yaml

# 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
de

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
TiDB集群环境的部署可以通过使用TiUP来完成。TiUP是TiDB 4.0版本引入的集群运维工具,它提供了集群管理组件TiUP cluster,可以用于管理TiDB集群的部署、启动、关闭、销毁、弹性扩缩容、升级等工作。通过执行TiUP命令,可以输出当前通过TiUP cluster管理的所有集群信息,包括集群名称、部署用户、版本、密钥信息等。 具体的部署步骤如下: 1. 安装TiUP组件:执行TiUP命令进行组件安装。 2. 创建集群配置文件:使用TiUP cluster命令创建一个新的集群配置文件。 3. 配置集群参数:根据需求修改集群配置文件中的参数,例如副本数、节点数量等。 4. 部署TiDB集群:执行TiUP cluster命令进行集群的部署。 5. 检查部署情况:执行TiUP cluster命令检查部署的TiDB集群情况。 通过以上步骤,可以完成TiDB集群环境的部署和配置。使用TiUP作为集群管理工具,可以方便地进行TiDB生态下各个组件的管理和运维工作,极大地降低了管理难度。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [使用 TiUP 部署 TiDB 集群](https://blog.csdn.net/weixin_42241611/article/details/125518329)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] - *3* [TIDB集群部署](https://blog.csdn.net/qq_21040559/article/details/127716535)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值