【TiDB】08-离线部署TiDB 8.1

news2024/9/21 20:44:59

目录

1、环境检查

1.1、检测及关闭系统 swap

1.2、设置TiDB节点的临时空间

 1.3、安装NTP服务

1.3.1、更新apt源

1.3.2、安装NTP

1.3.3、将本机作为NTP服务器

1.3.4、客户端连接

1.4、配置SSH互信及sudo免密码

2、离线安装

2.1、下载离线安装包

2.2、解压安装

2.3、最小配置模板topology.yaml

2.4、风险检查

 2.5、风险自动修复

2.6、部署TiDB集群

3、集群管理

3.1、检查集群

3.2、启动集群

3.2、验证启动

3.4、访问平台


1、环境检查

1.1、检测及关闭系统 swap

TiDB 运行需要有足够的内存。如果想保持性能稳定,则建议永久关闭系统 swap,但可能在内存偏小时触发 OOM 问题;如果想避免此类 OOM 问题,则可只将 swap 优先级调低,但不做永久关闭。

  • 开启并使用 swap 可能会引入性能抖动问题,对于低延迟、稳定性要求高的数据库服务,建议永久关闭操作系统层 swap。要永久关闭 swap,可使用以下方法:

    • 在操作系统初始化阶段,不单独划分 swap 分区盘。

    • 如果在操作系统初始化阶段,已经单独划分了 swap 分区盘,并且启用了 swap,则使用以下命令进行关闭:

echo "vm.swappiness = 0">> /etc/sysctl.conf 
swapoff -a 
sysctl -p
  • 如果主机内存偏小,关闭系统 swap 可能会更容易触发 OOM 问题,可参考以如下方法将 swap 优先级调低,但不做永久关闭:

    echo "vm.swappiness = 0">> /etc/sysctl.conf 
    sysctl -p

1.2、设置TiDB节点的临时空间

TiDB 的部分操作需要向服务器写入临时文件,因此需要确保运行 TiDB 的操作系统用户具有足够的权限对目标目录进行读写。如果 TiDB 实例不是以 root 权限启动,则需要检查目录权限并进行正确设置。

  • TiDB 临时工作区

    哈希表构建、排序等内存消耗较大的操作可能会向磁盘写入临时数据,用来减少内存消耗,提升稳定性。写入的磁盘位置由配置项 tmp-storage-path 定义。在默认设置下,确保运行 TiDB 的用户对操作系统临时文件夹(通常为 /tmp)有读写权限。

  • Fast Online DDL 工作区

    当变量 tidb_ddl_enable_fast_reorg 被设置为 ON(v6.5.0 及以上版本中默认值为 ON)时,会激活 Fast Online DDL,这时部分 DDL 要对临时文件进行读写。临时文件位置由配置 temp-dir 定义,需要确保运行 TiDB 的用户对操作系统中该目录有读写权限。以默认目录 /tmp/tidb 为例:

    注意

    如果业务中可能存在针对大对象的 DDL 操作,推荐为 temp-dir 配置独立文件系统及更大的临时空间。

    sudo mkdir /tmp/tidb

    如果目录 /tmp/tidb 已经存在,需确保有写入权限。

    sudo chmod -R 777 /tmp/tidb

    注意

    如果目录不存在,TiDB 在启动时会自动创建该目录。如果目录创建失败,或者 TiDB 对该目录没有读写权限,Fast Online DDL 在运行时可能产生不可预知的问题。

 1.3、安装NTP服务

TiDB 是一套分布式数据库系统,需要节点间保证时间的同步,从而确保 ACID 模型的事务线性一致性。

可以通过互联网中的 pool.ntp.org 授时服务来保证节点的时间同步,

也可以使用离线环境自己搭建的 NTP 服务来解决授时

基于ubuntu20.04.1

1.3.1、更新apt源

cd /etc/apt 替换 sources.list 内容

deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse # deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse # deb-src https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

arm UOS 源

deb http://mirrors.aliyun.com/ubuntu-ports/ xenial main deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial main deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates main deb http://mirrors.aliyun.com/ubuntu-ports/ xenial universe deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial universe deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates universe deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-updates universe deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-security main deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-security main deb http://mirrors.aliyun.com/ubuntu-ports/ xenial-security universe deb-src http://mirrors.aliyun.com/ubuntu-ports/ xenial-security universe

更新软件列表

sudo apt-get update

1.3.2、安装NTP

# 检查是否存在 ntp服务
sudo systemctl status ntp.service

# 不存在,则安装
 apt install ntp
 # 启动服务
 service ntp start

1.3.3、将本机作为NTP服务器

# 在服务端修改ntp配置开放客户端所在的网段
vim /etc/ntp.conf
# /etc/ntp.conf, configuration for ntpd; see ntp.conf(5) for help

driftfile /var/lib/ntp/ntp.drift

# Leap seconds definition provided by tzdata
leapfile /usr/share/zoneinfo/leap-seconds.list

# Enable this if you want statistics to be logged.
#statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats
filegen loopstats file loopstats type day enable
filegen peerstats file peerstats type day enable

# 主要配置   


# 允许访问的网络端
restrict 192.168.20.113 mask 255.255.255.0 nomodify notrap

restrict 192.168.0.0
restrict 127.0.0.1
restrict ::1
service ntp restart
service ntp status

# 开放端口(一般情况下可省略)
# sudo ufw allow 123/udp

1.3.4、客户端连接

如果出现如下问题:no server suitable for synchronization found

等待五分钟

# 安装ntpdate
ntpdate -d 192.168.20.113

1.4、配置SSH互信及sudo免密码

对于有需求,通过手动配置中控机至目标节点互信的场景,可参考本段。

  1. 以 root 用户依次登录到部署目标机器创建 tidb 用户并设置登录密码。

    useradd tidb &&  passwd tidb

    # 将结尾处的 sh 修改为 bash
    vim  /etc/passwd

  2. 执行以下命令,将 tidb ALL=(ALL) NOPASSWD: ALL 添加到文件末尾,即配置好 sudo 免密码。

    visudo

    tidb ALL=(ALL) NOPASSWD: ALL

  3. 以 tidb 用户登录到中控机,执行以下命令。将 10.0.1.1 替换成你的部署目标机器 IP,按提示输入部署目标机器 tidb 用户密码,执行成功后即创建好 SSH 互信,其他机器同理。新建的 tidb 用户下没有 .ssh 目录,需要执行生成 rsa 密钥的命令来生成 .ssh 目录。如果要在中控机上部署 TiDB 组件,需要为中控机和中控机自身配置互信。

    # 登录tidb账号
    su tidb
    
    # 为了后续方便,直接按enter键
    ssh-keygen -t rsa 
    
    #
    ssh-copy-id -i ~/.ssh/id_rsa.pub 10.0.1.1
  4. 以 tidb 用户登录中控机,通过 ssh 的方式登录目标机器 IP。如果不需要输入密码并登录成功,即表示 SSH 互信配置成功。

    ssh 10.0.1.1

    [tidb@10.0.1.1 ~]$

  5. 以 tidb 用户登录到部署目标机器后,执行以下命令,不需要输入密码并切换到 root 用户,表示 tidb 用户 sudo 免密码配置成功。

    sudo -su root

    [root@10.0.1.1 tidb]#

2、离线安装

2.1、下载离线安装包

下载地址从文末 参考文档上,两个包都需要下载

 

2.2、解压安装

注意后续操作全部以 tidb 账号登录

mkdir -p /home/tidb
chown -R tidb:tidb /home/tidb
su tidb
cd /home/tidb

tar -zxf tidb-community-toolkit-v8.1.0-linux-amd64.tar.gz
tar -zxf tidb-community-server-v8.1.0-linux-amd64.tar.gz

sh tidb-community-server-v8.1.0-linux-amd64/local_install.sh
source /home/tidb/.bashrc

2.3、最小配置模板topology.yaml

其中

1)pd_server:元数据管理、集群一致性管理

2)tidb_server:对外提供连接访问,对内与tikv_server通信

3)tikv_server:实际存储数据节点

# # 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://docs.pingcap.com/zh/tidb/stable/tidb-configuration-file
# # - TiKV: https://docs.pingcap.com/zh/tidb/stable/tikv-configuration-file
# # - PD: https://docs.pingcap.com/zh/tidb/stable/pd-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:
    replication.location-labels: ["zone","dc","host"]
    schedule.leader-schedule-limit: 4
    schedule.region-schedule-limit: 2048
    schedule.replica-schedule-limit: 64

pd_servers:
  - host: 192.168.20.113
    # 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 

tidb_servers:
  - host: 192.168.20.113
    # 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
  

tikv_servers:
  - host: 192.168.20.113
    # ssh_port: 22
    port: 20161
    status_port: 20181
    deploy_dir: "/tidb-deploy/tikv-20161"
    data_dir: "/tidb-data/tikv-20161"
    log_dir: "/tidb-deploy/tikv-20161/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: 192.168.20.113
    port: 20162
    status_port: 20182
    deploy_dir: "/tidb-deploy/tikv-20162"
    data_dir: "/tidb-data/tikv-20162"
    log_dir: "/tidb-deploy/tikv-20162/log"
    config:
      server.labels: { zone: "zone1", dc: "dc1", host: "host2" }
      
  - host: 192.168.20.113
    port: 20163
    status_port: 20183
    deploy_dir: "/tidb-deploy/tikv-20163"
    data_dir: "/tidb-data/tikv-20163"
    log_dir: "/tidb-deploy/tikv-20163/log"
    config:
      server.labels: { zone: "zone1", dc: "dc1", host: "host3" }

monitoring_servers:
  - host: 192.168.20.113
    # 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: 192.168.20.113
    # port: 3000
    # deploy_dir: /tidb-deploy/grafana-3000

alertmanager_servers:
  - host: 192.168.20.113
    # 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"

也可以使用命令生成模板配置文件

#执行如下命令,生成集群初始化配置文件:
tiup cluster template > topology.yaml


#混合部署场景:单台机器部署多个实例
tiup cluster template --full > topology.yaml

#跨机房部署场景:跨机房部署 TiDB 集群
tiup cluster template --multi-dc > topology.yaml

2.4、风险检查

tiup cluster check ./topology.yaml --user tidb [-p] [-i /home/root/.ssh/gcp_rsa]

 2.5、风险自动修复

tiup cluster check ./topology.yaml --apply --user tidb [-p] [-i /home/root/.ssh/gcp_rsa]

 1)numactl not usable, bash: numectl: command not found

apt-get install numactl

2)CPU frequency governor is ondemand, should use performance

问题:CPU 频率调节器设置为 ondemand,应设置为 performance 以优化性能。

解决方法

sudo apt-get install cpufrequtils 
sudo cpufreq-set -r -g performance

检查设置是否生效:

cpufreq-info |grep ondemand

2.6、部署TiDB集群

tiup cluster deploy tidb-test v8.1.0 ./topology.yaml --user tidb [-p] [-i /home/root/.ssh/gcp_rsa]
  • tidb-test 为部署的集群名称。
  • v8.1.0 为部署的集群版本,可以通过执行 tiup list tidb 来查看 TiUP 支持的最新可用版本。
  • 初始化配置文件为 topology.yaml
  • --user root 表示通过 root 用户登录到目标主机完成集群部署,该用户需要有 ssh 到目标机器的权限,并且在目标机器有 sudo 权限。也可以用其他有 ssh 和 sudo 权限的用户完成部署。
  • [-i] 及 [-p] 为可选项,如果已经配置免密登录目标机,则不需填写。否则选择其一即可,[-i] 为可登录到目标机的 root 用户(或 --user 指定的其他用户)的私钥,也可使用 [-p] 交互式输入该用户的密码。

3、集群管理

3.1、检查集群

#查看 TiUP 管理的集群情况
tiup cluster list

#TiUP 支持管理多个 TiDB 集群,该命令会输出当前通过 TiUP cluster 管理的所有集群信息,包括集群名称、部署用户、版本、密钥信息等。

#执行如下命令检查 tidb-test 集群情况:
tiup cluster display tidb-test

3.2、启动集群

注意启动密码【请保管好密码】,如果不加 --init ,则无密码root访问集群

忘记密码修改

# 安全启动 
tiup cluster start tidb-test --init

只有第一次执行需要添加 --init 参数,后续则移除,否则再次启动报错

3.2、验证启动

tiup cluster display tidb-test

3.4、访问平台

输入root账号,及密码登录

http://192.168.20.113:2379/dashboard/

参考文档

TiDB 环境与系统配置检查 | PingCAP 文档中心

TiDB 社区版 离线安装包下载 | PingCAP

TiKV 配置文件描述 | PingCAP 文档中心

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2037969.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

YOLOv8改进 | 主干网络 | 动态调整目标的感受野的LSKNet【旋转目标检测SOTA】

秋招面试专栏推荐 :深度学习算法工程师面试问题总结【百面算法工程师】——点击即可跳转 💡💡💡本专栏所有程序均经过测试,可成功执行💡💡💡 专栏目录 :《YOLOv8改进有效…

程序员最常用的操作——git

软件安装 官方下载(比较慢):https://git-scm.com/downloads gitee 注册账号 https://gitee.com/ 新建仓库 honey2024 先全局配置下邮箱 配置 git config --global user.email “your_emailexample.com” git config --global user.name…

虚幻5|AI行为树,进阶篇

一,打开敌人的角色蓝图,编写以下蓝图,该蓝图只是创建一个敌人并非ai行为树 1.编写蓝图 2.打开主界面,创建一个导航网格体积,上一章都有讲,在添加体积这里面,找到导航网格体积,点击创…

安装buf工具和环境变量

安装buf工具和环境变量 下载buf的可执行文件: 访问buf官方的GitHub releases页面。 没梯子的就用csdn下载吧 https://download.csdn.net/download/qq_27229113/89638643 找到最新版本的buf。 在Assets部分,下载适合Windows的二进制文件,一…

如何利用宝塔给WordPress网站搬家?详细分步教程

对于使用WordPress建站的站长来说,网站搬家是一项必备技能。无论是重装系统、升级配置还是服务器迁移,掌握网站搬家的技巧可以让你在选择服务器时更加灵活。本文将详细介绍如何使用宝塔面板来搬迁WordPress网站。 1. 备份数据库 记住数据库用户名和密码…

Python 批量读取西门子PLC

需要安装 pip install python-snap7 import snap7 from snap7.util import * import struct # PLC的IP地址, Rack和Slot plc snap7.client.Client() plc.connect(127.0.0.1, 0, 1) # IP, Rack, Slot # 读取DB1中的10个字节,起始于0位置 db_number …

企业多样化需求一键满足:可道云teamOS,助力定制专属企业网盘

在这个飞速发展的数字化时代,企业的运营需求越来越多样化,如何高效地管理数据、实现安全协作,成为摆在我们面前的重要课题。 幸运的是,我遇到了可道云teamOS。 首先,可道云teamOS的自定义用户权限功能让我印象深刻。…

Bug定义及生命周期(七)

BUG 定义 软件的bug,软件程序的漏洞或缺陷 – 常见,首先发现 软件可改进的细节,或与需求文档存在差异的功能实现等 测试工程师:发现bug,定位bug,提交bug,回归bug 类型 确定bug类型&#xff…

Android-->产物收集(含apk文件重命名, aab文件重命名)

以前写过修改apk生成路径和文件名的文章, 如下: AS–›Gradle 7.0.0/4.1.0/4.0/3.3/3.0 修改APK生成路径和文件名(附AAR修改方式以及分析过程)_com.android.build.gradle.internal.api.libraryvaria-CSDN博客 这种方法入侵了gradle,破坏了原有的gradle环境, 经常会导致如下问…

2024年8月中国数据库排行榜:OceanBase攀升再夺冠,达梦跃入三甲关

在这个炽热的季节,随着巴黎奥运会的盛大开幕,全球将目光聚集在了体育的无限魅力和竞技的巅峰对决上。如同奥运赛场上的激烈角逐,中国数据库界也上演着一场技术与创新的较量,各个数据库产品正在中国乃至全球舞台上展示着它们的实力…

mitmproxy 抓包工具的使用

motmproxy 是一个支持 HTTP/HTTPS 协议的抓包程序, 和 Fiddler, Charles 有些类似的功能,只不过它以控制台的形式操作 mitmproxy 还有两个关联组件。 一个是 mitmdump , 这是 mitmproxy 的命令接口, 利用它我们可以对接 Python …

企业用的文件加密软件有哪些?2024年最好用的十款文件加密软件

随着数字化转型的深入,企业数据安全成为了一个日益重要的议题。文件作为企业日常运营和知识管理的核心载体,其安全性直接关系到企业的商业机密和知识产权保护。为了应对日益严峻的数据安全挑战,市场上出现了多款功能强大、操作简便的文件加密…

从0开始搭建vue + flask 旅游景点数据分析系统(十):Element-UI消息插件封装

上一期我们使用过了elementui的Message来弹出消息提示框,但是上期的写法每次都要在vue文件中引入Message,并且要写不少重复代码,这一期就以插件方式将message封装到Vue的实例中。 创建plugins/message.js 这边加了判断的作用是,…

备忘录内容可以隐藏内容吗 备忘录内容在哪隐藏

在现代忙碌的生活中,备忘录成为了我们不可或缺的助手。它帮助我们记录重要的事项、想法和灵感,确保我们不会错过任何关键信息。然而,随着备忘录里积累的内容越来越多,很多人开始担心这些私密信息的安全。毕竟,如果备忘…

光影漫游者:品牌推广与产品发布的理想展示空间—轻空间

在竞争日益激烈的市场环境中,品牌推广和产品发布会不仅要传递信息,更要留下深刻印象。而光影漫游者作为创新展示空间的典范,以其现代感十足的外观设计与高科技内饰配置,为企业提供了一个完美的展示平台,最大限度地吸引…

Steinberg SpectraLayers Pro for Mac:专业音频频谱编辑的巅峰之作

Steinberg SpectraLayers Pro for Mac是一款专为音频专业人士设计的专业音频频谱编辑器,它以其强大的频谱编辑功能和直观的操作界面,在音频处理领域树立了新的标杆。该软件不仅为音频编辑工作带来了前所未有的精确度和灵活性,还极大地提升了音…

map/set和unordered_map/unordered_set的区别及使用情况

map/set和unordered_map/unordered_set的区别 容器底层数据结构是否有序实现版本复杂度迭代器map/set红黑树有序C98O(logN)双向迭代器unordered_map/unordered_set哈希表/散列表无序C11O(1)单向迭代器 unordered_set无序的(VS下) void uno…

文件长度超出芯片容量, 超出部份将被忽略!ch341a编程器报错解决方法

出现这个错误提示,说明你正在刷的是华硕主板的cap格式BIOS文件。 编程器不支持这种文件,需要转换成编程器专用版本BIOS文件。 华硕cap格式BIOS转编程器bios文件,转换工具下载地址:https://download.csdn.net/download/baiseled/88…

CentOS 7设置静态IP地址的详细指南

CentOS 7设置静态IP地址的详细指南 配置静态IP地址是服务器或虚拟机管理的重要步骤之一,特别是在需要稳定、可预测的网络环境时。本文将详细介绍如何在CentOS 7上设置静态IP地址,帮助确保你的系统网络配置符合需求。 1. 查看当前网络配置 在进行任何更…

【SpringMVC】详细了解SpringMVC中WEB-INF 目录资源,视图解析器和静态资源放行的使用。

目录 1. 回顾SpringMVC请求转发和重定向 2. WEB-INF资源目录 3. 视图解析器 4. 静态资源放行 1. 回顾SpringMVC请求转发和重定向 概念:在一个项目中功能非常多,也就意味着有非常多的Servlet,不同的Servlet的职不 同 ,而用户发起…