docker 部署 Tdengine集群 本文共有13967个字,关键词: 设置主机时区: ```bash timedatectl set-timezone Asia/Shanghai ``` 安装docker-compose ```bash #https://github.com/docker/compose/releases curl -L https://get.daocloud.io/docker/compose/releases/download/v2.12.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose sudo chmod +x /usr/local/bin/docker-compose # 添加可执行权限 sudo chmod +x /usr/local/bin/docker-compose # 查看docker-compose版本 docker-compose -v ``` ```bash docker network create --driver bridge --subnet 172.10.0.0/16 --gateway 172.10.0.1 my_tdengine_net docker network ls #可查看网卡列表 docker network inspect my_tdengine_net #网卡名称 可查看网卡具体信息 ``` 1、创建路径 ```bash mkdir -p /home/docker-compose/tdengine; cd /home/docker-compose/tdengine mkdir etc ``` 2、创建taos.cfg ```bash cd /home/docker-compose/tdengine/etc mkdir node1etc node2etc node3etc ``` 在node1etc node2etc node3etc中分别创建一个taos.cfg,然后分别设置其firstEp、secondEp、fqdn和serverPort属性: node1etc: firstEp=taosnode1:6030,secondEp=taosnode1:6030,fqdn=taosnode1,serverPort=6030; node2etc: firstEp=taosnode1:6030,secondEp=taosnode2:7030,fqdn=taosnode2, serverPort=7030; node3etc: firstEp=taosnode1:6030,secondEp=taosnode2:7030,fqdn=taosnode3, serverPort=8030; 注意:taosnode1为物理节点的hostname,如果hostname变了,这也要变。 ```bash ############################################################## ######################################################## # # # TDengine Configuration # # Any questions, please email support@taosdata.com # # # ######################################################## # first fully qualified domain name (FQDN) for TDengine system # taosd启动时,主动连接的集群中第一个dnode的end point, 默认值为localhost:6030。 # firstEp hostname1:6030 # second fully qualified domain name (FQDN) for TDengine system, for cluster only # taosd启动时,如果first连接不上,尝试连接集群中第二个dnode的end point, 默认值为空。 # secondEp cluster_hostname2:6030 # local fully qualified domain name (FQDN) # 数据节点的FQDN,缺省为操作系统配置的第一个hostname。如果习惯IP地址访问,可设置为该节点的IP地址。 # fqdn hostname # first port number for the connection (12 continuous UDP/TCP port number are used) # taosd启动后,对外服务的端口号,默认值为6030。 # serverPort 6030 # log file's directory # 日志文件目录,客户端和服务器的运行日志文件将写入该目录。默认值:/var/log/taos # logDir /var/log/taos # data file's directory # 数据文件目录,所有的数据文件都将写入该目录。默认值:/var/lib/taos。 # dataDir /var/lib/taos # the arbitrator's fully qualified domain name (FQDN) for TDengine system, for cluster only # 系统中裁决器的end point, 缺省值为空。 # arbitrator arbitrator_hostname:6030 # number of threads per CPU core # numOfThreadsPerCore 1.0 # number of management nodes in the system # 系统中管理节点个数。默认值:3。 # numOfMnodes 3 # enable/disable backuping vnode directory when removing dnode # vnodeBak 1 # enable/disable load balancing # 是否启动负载均衡。0:否,1:是。默认值:1。 # balance 1 # role for dnode. 0 - any, 1 - mnode, 2 - dnode # dnode的可选角色。0-any; 既可作为mnode,也可分配vnode;1-mgmt;只能作为mnode,不能分配vnode;2-dnode;不能作为mnode,只能分配vnode # role 0 # max timer control blocks # maxTmrCtrl 512 # time interval of system monitor, seconds # monitorInterval 30 # number of seconds allowed for a dnode to be offline, for cluster only # dnode离线阈值,超过该时间将导致该dnode从集群中删除。单位为秒,默认值:86400*10(即10天)。 # offlineThreshold 8640000 # RPC re-try timer, millisecond # rpcTimer 300 # RPC maximum time for ack, seconds. # rpcMaxTime 600 # time interval of dnode status reporting to mnode, seconds, for cluster only # statusInterval 1 # time interval of heart beat from shell to dnode, seconds # shellActivityTimer 3 # time of keeping table meta data in cache, seconds # tableMetaKeepTimer 7200 # minimum sliding window time, milli-second # minSlidingTime 10 # minimum time window, milli-second # minIntervalTime 10 # maximum delay before launching a stream compution, milli-second # maxStreamCompDelay 20000 # maximum delay before launching a stream computation for the first time, milli-second # maxFirstStreamCompDelay 10000 # retry delay when a stream computation fails, milli-second # retryStreamCompDelay 10 # the delayed time for launching a stream computation, from 0.1(default, 10% of whole computing time window) to 0.9 # streamCompDelayRatio 0.1 # max number of vgroups per db, 0 means configured automatically # 每个数据库中能够使用的最大vnode个数。 # maxVgroupsPerDb 0 # max number of tables per vnode # 每个vnode中能够创建的最大表个数。默认值:1000000。 # maxTablesPerVnode 1000000 # step size of increasing table number in a vnode # tableIncStepPerVnode 1000 # cache block size (Mbyte) # cache 16 # number of cache blocks per vnode # blocks 6 # number of days per DB file # 一个数据文件存储数据的时间跨度,单位为天,默认值:10。 # days 10 # number of days to keep DB file # 数据库中数据保留的天数,单位为天,默认值:3650。 # keep 3650 # minimum rows of records in file block # 文件块中记录的最小条数,单位为条,默认值:100。 # minRows 100 # maximum rows of records in file block # 文件块中记录的最大条数,单位为条,默认值:4096。 # maxRows 4096 # enable/disable compression # 文件压缩标志位,0:关闭,1:一阶段压缩,2:两阶段压缩。默认值:2。 # comp 2 # write ahead log (WAL) level, 0: no wal; 1: write wal, but no fysnc; 2: write wal, and call fsync # WAL级别。1:写wal, 但不执行fsync; 2:写wal, 而且执行fsync。默认值:1。 # walLevel 1 # if walLevel is set to 2, the cycle of fsync being executed, if set to 0, fsync is called right away # 当wal设置为2时,执行fsync的周期。设置为0,表示每次写入,立即执行fsync。单位为毫秒,默认值:3000 # fsync 3000 # number of replications, for cluster only # 副本个数,取值范围:1-3。单位为个,默认值:1 # replica 1 # mqtt uri # mqttBrokerAddress mqtt://username:password@hostname:1883/taos/ # mqtt client name # mqttBrokerClientId taos_mqtt # 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 # max length of an SQL # # # 设置sql语句的最大长度,默认值:65380字节。最大值为1048576或者1M。 maxSQLLength 1048576 # the maximum number of records allowed for super table time sorting # maxNumOfOrderedRes 100000 # system time zone # 默认值:从系统中动态获取当前的时区设置 # timezone Asia/Shanghai (CST, +0800) # system locale # 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置 # locale en_US.UTF-8 # default system charset # 默认值:系统中动态获取,如果自动获取失败,需要用户在配置文件设置或通过API设置 # charset UTF-8 # max number of connections allowed in dnode # maxShellConns 5000 # max numerber of connections allowed in client # maxConnections 5000 # stop writing logs when the disk size of the log folder is less than this value # minimalLogDirGB 0.1 # stop writing temporary files when the disk size of the log folder is less than this value # minimalTmpDirGB 0.1 # stop writing data when the disk size of the log folder is less than this value # minimalDataDirGB 0.1 # enbale/disable http service # http 1 # enable/disable muqq service # mqtt 0 # enable/disable system monitor # monitor 1 # enable/disable recording the SQL statements via restful interface # httpEnableRecordSql 0 # number of threads used to process http requests # httpMaxThreads 2 # maximum number of rows returned by the restful interface # restful返回数据行数限制 restfulRowLimit 1024000 # The following parameter is used to limit the maximum number of lines in log files. # max number of rows per log filters # 单个日志文件允许的最大行数。默认值:10,000,000行。 # numOfLogLines 10000000 # enable/disable async log # asyncLog 1 # The following parameters are used for debug purpose only. # debugFlag 8 bits mask: FILE-SCREEN-UNUSED-HeartBeat-DUMP-TRACE_WARN-ERROR # 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 135 # debug flag for meta management messages # mDebugFlag 135 # debug flag for dnode messages # dDebugFlag 135 # debug flag for sync module # sDebugFlag 135 # debug flag for WAL # wDebugFlag 135 # debug flag for SDB # sdbDebugFlag 135 # debug flag for RPC # rpcDebugFlag 131 # debug flag for TAOS TIMER # tmrDebugFlag 131 # debug flag for TDengine client # cDebugFlag 131 # debug flag for JNI # jniDebugflag 131 # debug flag for ODBC # odbcDebugflag 131 # debug flag for storage # uDebugflag 131 # debug flag for http server # httpDebugFlag 131 # debug flag for mqtt # mqttDebugFlag 131 # debug flag for monitor # monitorDebugFlag 131 # debug flag for query # qDebugflag 131 # debug flag for vnode # vDebugflag 131 # debug flag for http server # tsdbDebugFlag 131 # enable/disable recording the SQL in taos client # tscEnableRecordSql 0 # generate core file when service crash # enableCoreFile 1 # maximum display width of binary and nchar fields in the shell. The parts exceeding this limit will be hidden # shell中二进制和nchar字段的最大显示宽度。超过此限制的部分将被隐藏 # maxBinaryDisplayWidth 30 ############################################################## ``` 3、创建docker-compose.yml ```bash cd /home/docker-compose/tdengine touch docker-compose.yml ``` ```bash version: "3" # 没有自定义网络就不配 networks: my_tdengine_net: external: true services: taosnode1: #开机自启 restart: always #指定镜像 image: tdengine/tdengine:latest #指定容器hostname hostname: taosnode1 #容器名称 container_name: taosnode1 #创建容器后默认执行的命令 privileged: true #容器的映射端口 ports: - 6020:6020 - 6030-6042:6030-6042/tcp - 6030-6042:6030-6042/udp #定义挂载点 volumes: - /etc/localtime:/etc/localtime:ro #同步主机时区到容器 - ./data/node1data:/var/lib/taos - ./etc/node1etc:/etc/taos - ./log/node1log:/var/log/taos # 没有自定义网络就不配(下面还有两个节点) networks: my_tdengine_net: ipv4_address: 172.10.0.101 taosnode2: restart: always image: tdengine/tdengine:latest hostname: taosnode2 container_name: taosnode2 privileged: true ports: - 7020:7020 - 7030-7042:7030-7042/tcp - 7030-7042:7030-7042/udp volumes: - /etc/localtime:/etc/localtime:ro #同步主机时区到容器 - ./data/node2data:/var/lib/taos - ./etc/node2etc:/etc/taos - ./log/node2log:/var/log/taos networks: my_tdengine_net: ipv4_address: 172.10.0.102 taosnode3: restart: always image: tdengine/tdengine:latest hostname: taosnode3 container_name: taosnode3 privileged: true ports: - 8020:8020 - 8030-8042:8030-8042/tcp - 8030-8042:8030-8042/udp volumes: - /etc/localtime:/etc/localtime:ro #同步主机时区到容器 - ./data/node3data:/var/lib/taos - ./etc/node3etc:/etc/taos - ./log/node3log:/var/log/taos networks: my_tdengine_net: ipv4_address: 172.10.0.103 ``` 4、拉取镜像 ```bash docker pull tdengine/tdengine ``` 5、启动tdengine (注意当前所在的目录) ```bash cd /home/docker-compose/tdengine docker-compose up -d ``` 6、进去第一个节点测试与其他节点的连接 ```bash docker-compose exec taosnode1 bash 这个taosnode1是service名称不是容器名称 不过我们这里设置的service名称和容器名称一样 apt-get install inetutils-ping -y 安装ping命令 ping taosnode2 ping taosnode3 ``` 7、进去第一个节点添加其他节点 ```bash docker-compose exec taosnode1 bash taos; create dnode "taosnode2:7030" #将节点2加入集群 create dnode "taosnode3:8030" #将节点3加入集群 show dnodes; #查看物理节点 show mnodes; show vgroups; #没有信息的继续往下看 drop dnode #节点id ``` 8、服务端hosts配置 ```bash vim /etc/hosts 添加:虚拟机的IPv4 taosnode1 taosnode2 taosnode3 ``` 9、客户端连接配置 C:\Windows\System32\drivers\etc\hosts 虚拟机的IPv4 taosnode1 taosnode2 taosnode3 客户端下载地址:https://www.taosdata.com/cn/getting-started/#Quick%20Start 客户端下载之后直接安装即可,默认路径C:\TDengine 修改C:\TDengine\cfg\taos.cfg,设置firstEp为taosnode1:6030,secondEp为taosnode2:7030 设置secondEp主要是为了防止taosnode1节点宕机后无法连接集群 C:\TDengine中cmd启动客户端,输入taos连接集群 10、vnode的高可用 create database testdb replica n; 创建数据库并设置副本数,n代表几个副本; 可以配置为1-3,但不能超过节点数; 当一个vnode group里一半或以上的vnode不工作时,不能对外提供服务; 默认replica为1,此时集群不具备vnode高可用,若想高可用,大于等于2; 11、mnode的高可用 mnode的副本数,由系统配置参数numOfMnodes决定,有效范围1-3,且小于等于集群节点数; 当一半或以上mnode不工作时,集群不对外工作; 为保证mnode的高可用性,numOfMnodes必须设置为2或3,默认为3; 12、负载均衡 触发情况:下面这三种情况将自动触发负载均衡,不须人工干预 1、当一个新数据节点添加进集群时; 2、当一个数据节点从集群中移除时; 3、一个数据节点过热(数据量过大); 13、Arbitrator 为什么要用Arbitrator: 如果副本数为偶数,当一个vnode group里一半的vnode不工作时,是无法从中选出master的。 同理,一个mnode组里一半的mnode不工作时,也是无法选出mnode的master的。 因为存在“split brain”的问题; Arbitrator的作用 Arbitrator是一个可执行程序,模拟一个vnode或mnode在工作,但只简单的负责网络连接,不处理任何数据插入或访问。 比如:对于副本数位2的情况,如果一个节点A离线,但另外一个节点B正常,如果没有Arbitrator,那么节点B也不能对外工作, 但如果能连接到Arbitrator,那么节点B就能正常工作 使用docker-compose安装tdengine,切忌使用docker-compose down命令, 否则需要清空data下所有文件才能再次执行docker-compose up -d命令,如果不清空data下所有文件,tdengine服务会一直显示重启中; rm -rf /home/docker-compose/tdengine/data 清空data文件命令,必须保证路径正确 「一键投喂 软糖/蛋糕/布丁/牛奶/冰阔乐!」 赞赏 × 梦白沙 (๑>ڡ<)☆谢谢老板~ 1元 2元 5元 10元 50元 任意金额 2元 使用微信扫描二维码完成支付 版权声明:本文为作者原创,如需转载须联系作者本人同意,未经作者本人同意不得擅自转载。 Docker 2022-10-25 评论 929 次浏览