TDengine的多节点容器化部署方案

部署环境

节点数:3

操作系统:ubuntu2204

tdengine版本:3.1.1.0

部署目标

在三个节点上使用docker部署tdengine,并使其组成一个集群共同工作

前置条件

请在部署前检查各节点是否满足如下条件:

  1. 已安装docker和docker-compose
  2. /etc/hosts文件中添加了其余节点的hostname解析
  3. 可以访问互联网
  4. 配置了可用的docker镜像仓库(国内环境下)
  5. DNS解析正常

部署流程

1. 创建yaml文件和配置文件taos.cfg

根据下方提供的文件信息创建docker-compose.yaml文件和taos.cfg文件,并将其传到各节点的同一目录下。

docker-compose.yaml文件如下所示

version: '3'
services:
  tdengine:
    image: tdengine/tdengine:3.1.1.0
    container_name: tdengine
    network_mode: host
    volumes:
      - /etc/localtime:/etc/localtime:ro
      - /etc/timezone:/etc/timezone:ro
      - ./data:/var/lib/taos
      - ./log:/var/log/taos
      - ./taos.cfg:/etc/taos/taos.cfg
    restart: always

yaml文件重要字段解释:
(1) network_mode字段设置为host,表示在宿主机网络上启动,只有以此方式启动各tdengine节点才可以通过宿主机网络建立通信。
(2) volumes字段中以只读权限映射了宿主机的localtime和timezone,这是为了确保各tdengine节点的时间时区一致,若不一致则无法建立集群。
(3) volumes字段中还加入了taos.cfg的映射,taos.cfg是tdengine的配置文件,建立映射是为了在启动容器前对配置文件进行编辑,这样启动容器时tdengine将会采用设置好的配置文件,如果不提前准备好配置文件,直接启动容器后,容器内默认是不会有这个文件的。

taos.cfg文件如下所示

########################################################
#                                                      #
#                  Configuration                       #
#                                                      #
########################################################

######### 0. Client only configurations #############

# The interval for CLI to send heartbeat to mnode
# shellActivityTimer        3


############### 1. Cluster End point ############################

# The end point of the first dnode in the cluster to be connected to when this dnode or the CLI utility is started
# firstEp                   hostname:6030

# The end point of the second dnode to be connected to if the firstEp is not available
# secondEp


############### 2. Configuration Parameters of current dnode #####

# The FQDN of the host on which this dnode will be started. It can be IP address
# fqdn                      hostname

# The port for external access after this dnode is started
# serverPort                6030

# The maximum number of connections a dnode can accept
# maxShellConns             5000

# The directory for writing log files, if you are using Windows platform please change to Windows path
# logDir                    /var/log/taos

# All data files are stored in this directory, if you are using Windows platform please change to Windows path
# dataDir                   /var/lib/taos

# temporary file's directory, if you are using Windows platform please change to Windows path
# tempDir                   /tmp/

# Switch for allowing to collect and report service usage information
# telemetryReporting        1

# Switch for allowing to collect and report crash information
# crashReporting            1

# The maximum number of vnodes supported by this dnode
# supportVnodes             0

# The interval of this dnode reporting status to mnode, [1..10] seconds
# statusInterval            1

# The minimum sliding window time, milli-second
# minSlidingTime            10

# The minimum time window, milli-second
# minIntervalTime           10

# The maximum allowed query buffer size in MB during query processing for each data node
# -1 no limit (default)
# 0  no query allowed, queries are disabled
# queryBufferSize           -1

# The compressed rpc message, option:
#  -1 (no compression)
#   0 (all message compressed),
# > 0 (rpc message body which larger than this value will be compressed)
# compressMsgSize           -1

# query retrieved column data compression option:
#  -1 (no compression)
#   0 (all retrieved column data compressed),
# > 0 (any retrieved column size greater than this value all data will be compressed.)
# compressColData           -1

# system time zone
# timezone                  UTC-8

# system time zone (for windows 10)
# timezone              Asia/Shanghai (CST, +0800)

# system locale
# locale                    en_US.UTF-8

# system charset
# charset                   UTF-8

# stop writing logs when the disk size of the log folder is less than this value
# minimalLogDirGB           1.0

# stop writing temporary files when the disk size of the tmp folder is less than this value
# minimalTmpDirGB           1.0

# if free disk space is less than this value, this dnode will fail to start
# minimalDataDirGB          2.0

# enable/disable system monitor
# monitor                   1

# The following parameter is used to limit the maximum number of lines in log files.
# max number of lines per log filters
# numOfLogLines             10000000

# write log in async way: 1 - async, 0 - sync
# asyncLog                  1

# time period of keeping log files, in days
# logKeepDays               0

# unit Hour. Latency of data migration
# keepTimeOffset            0


############ 3. Debug Flag and levels #############################################

# The following parameters are used for debug purpose only by this dnode.
# debugFlag is a 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR
# Available debug levels are:
# 131: output warning and error
# 135: output debug, warning and error
# 143: output trace, debug, warning and error to log
# 199: output debug, warning and error to both screen and file
# 207: output trace, debug, warning and error to both screen and file

# debug flag for all log type, take effect when non-zero value
# debugFlag                 0

# debug flag for timer
# tmrDebugFlag              131

# debug flag for util
# uDebugFlag                131

# debug flag for rpc
# rpcDebugFlag              131

# debug flag for jni
# jniDebugFlag              131

# debug flag for query
# qDebugFlag                131

# debug flag for client driver
# cDebugFlag                131

# debug flag for dnode messages
# dDebugFlag                135

# debug flag for vnode
# vDebugFlag                131

# debug flag for meta management messages
# mDebugFlag                135

# debug flag for wal
# wDebugFlag                135

# debug flag for sync module
# sDebugFlag                135

# debug flag for tsdb
# tsdbDebugFlag             131

# debug flag for tq
# tqDebugFlag               131

# debug flag for fs
# fsDebugFlag               131

# debug flag for udf
# udfDebugFlag              131

# debug flag for sma
# smaDebugFlag              131

# debug flag for index
# idxDebugFlag              131

# debug flag for tdb
# tdbDebugFlag              131

# debug flag for meta
# metaDebugFlag             131

# generate core file when service crash
# enableCoreFile            1

2. 编辑配置文件taos.cfg

在每个节点上对taos.cfg进行编辑

通常情况下需要编辑的只有firstEp和fqdn两个字段:
# firstEp hostname:6030
# fqdn hostname

将firstEp字段编辑为主节点的fqdn,一般就是主节点宿主机的hostname,例如:
firstEp tdengine1:6030

将fqdn字段编辑为本节点的fqdn,一般就是本阶段宿主机的hostname,例如:
fqdn tdengine3

关于FQDN概念的简介,可以参阅《一篇文章说清楚TDengine的FQDN》

编辑字段时注意删除注释符“#”

3. 启动容器

对各节点配置文件taos.cfg完成修改后,在各节点执行docker-compose启动命令:
docker-compose up -d

执行后,可以使用如下指令查看各节点上的tdengine容器是否已启动
docker ps | grep tdengine

4. 建立集群

在主节点上执行以下命令进入tdengine容器:
docker exec -it tdengine taos

进入容器后,可以执行以下命令查看当前节点情况:
taos> SHOW DNODES;

此时应该只显示主节点信息

执行如下命令将其他节点加入集群:
taos> CREATE DNODE "tdengine2:6030";
taos> CREATE DNODE "tdengine3:6030";

执行完后,可以再次查看当前节点情况,此时应该显示3个节点,且status栏均为ready,若如此则证明成功完成部署。

常见问题

建立集群时使用 CREATE DNODE 增加新节点后,新节点始终显示 offline 状态?

  1. 首先要检查增加的新节点上的 taosd 服务是否已经正常启动

  2. 如果已经启动,再检查到新节点的网络是否通畅,可以使用 ping fqdn 验证下

  3. 如果前面两步都没有问题,这一步要检查新节点做为独立集群在运行了,可以使用 taos -h fqdn 连接上后,show dnodes; 命令查看.如果显示的列表与你主节点上显示的不一致,说明此节点自己单独成立了一个集群,解决的方法是停止新节点上的服务,然后清空新节点上taos.cfg 中配置的 dataDir 目录下的所有文件,重新启动新节点服务即可解决.

参考文章

TDengine官方文档7.1
TDengine官方文档7.2

posted @ 2025-04-23 17:46  Guard1an  阅读(126)  评论(0)    收藏  举报