1. TDengine概述与环境规划
TDengine是一款开源的物联网大数据平台,专为物联网、工业互联网、车联网等场景设计。TDengine具有高性能的时序数据写入和查询能力,支持SQL语法,学习成本低。更多学习教程www.fgedu.net.cn
1.1 TDengine版本说明
TDengine目前主要版本为3.0,本教程以TDengine 3.2为例进行详细讲解。
$ taos -V
version: 3.2.0.0
compatible_version: 3.0.0.0
gitinfo: abc123
buildInfo: Built at 2024-01-01 00:00:00
# 查看服务状态
$ taos -s “show variables”
taos> show variables;
name | value |
================================================================
statusInterval | 1 |
timezone | Asia/Shanghai |
locale | zh_CN.UTF-8 |
charset | UTF-8 |
maxConnections | 5000 |
maxShellConns | 50000 |
1.2 环境规划
本次安装环境规划如下:
IP地址:192.168.1.51
客户端端口:6030
HTTP端口:6041
数据目录:/data/taos
日志目录:/var/log/taos
存储规划:
数据保留期:365天
副本数:1
1.3 TDengine核心特性
1. 高性能:单节点每秒处理超过100万条数据
2. 高压缩:数据压缩率高达10:1
3. SQL支持:标准SQL语法,学习成本低
4. 超级表:支持多表关联查询
5. 集群模式:支持分布式部署
6. 多协议:支持RESTful、JDBC、ODBC等
7. 流计算:内置流计算引擎
8. 数据订阅:支持数据订阅功能
2. 硬件环境要求与检查
在安装TDengine之前,需要对服务器硬件环境进行全面检查。学习交流加群风哥微信: itpux-com
2.1 最低硬件要求
CPU:2核心
内存:4GB
磁盘:50GB
推荐配置(生产环境):
CPU:8核心以上
内存:32GB以上
磁盘:500GB以上SSD
大规模部署配置:
CPU:16核心以上
内存:64GB以上
磁盘:2TB以上SSD
2.2 系统环境检查
# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.8 (Ootpa)
# 检查内核版本
# uname -a
Linux fgedudb01 4.18.0-477.10.1.el8_8.x86_64 #1 SMP Fri Apr 4 10:00:00 CST 2026 x86_64 x86_64 x86_64 GNU/Linux
# 检查内存信息
# free -h
total used free shared buff/cache available
Mem: 31Gi 1.0Gi 29Gi 256Mi 1.0Gi 30Gi
Swap: 7Gi 0B 7Gi
# 检查磁盘空间
# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/mapper/vg_system-lv_root 50G 2.5G 48G 5% /
/dev/sda2 1014M 150M 865M 15% /boot
/dev/mapper/vg_data-lv_data 500G 50G 450G 10% /data
# 检查时间同步
# timedatectl status
Local time: 五 2026-04-04 10:00:00 CST
Universal time: 五 2026-04-04 02:00:00 UTC
RTC time: 五 2026-04-04 02:00:00
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
2.3 内核参数配置
# vi /etc/sysctl.d/99-tdengine.conf
# 添加以下参数
# 网络参数
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 30
# 文件描述符限制
fs.file-max = 655360
# 内存参数
vm.overcommit_memory = 1
vm.swappiness = 1
# 使内核参数生效
# sysctl -p /etc/sysctl.d/99-tdengine.conf
# 输出示例:
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
…
2.4 用户资源限制配置
# vi /etc/security/limits.conf
# 添加以下配置
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
* soft core unlimited
* hard core unlimited
# 检查当前限制
# ulimit -a
core file size (blocks, -c) unlimited
data seg size (kbytes, -d) unlimited
scheduling priority (-e) 0
file size (blocks, -f) unlimited
pending signals (-i) 63427
max locked memory (kbytes, -l) 64
max memory size (kbytes, -m) unlimited
open files (-n) 65535
pipe size (512 bytes, -p) 8
POSIX message queues (bytes, -q) 819200
real-time priority (-r) 0
stack size (kbytes, -s) 8192
cpu time (seconds, -t) unlimited
max user processes (-u) 65535
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
3. TDengine安装步骤
本节详细介绍TDengine 3.2的安装过程。学习交流加群风哥QQ113257174
3.1 创建目录结构
# mkdir -p /data/taos
# mkdir -p /var/log/taos
# 设置目录权限
# chmod 755 /data/taos
# chmod 755 /var/log/taos
# 验证目录权限
# ls -la /data/
总用量 0
drwxr-xr-x. 2 root root 6 4月 4 10:00 taos
3.2 下载并安装TDengine
# cd /usr/local/src
# wget https://www.taosdata.com/assets-download/3.0/TDengine-server-3.2.0.0-Linux-x64.tar.gz
# 输出示例:
–2026-04-04 10:00:00– https://www.taosdata.com/assets-download/3.0/TDengine-server-3.2.0.0-Linux-x64.tar.gz
正在解析主机 www.taosdata.com… 140.82.121.4
正在连接 www.taosdata.com|140.82.121.4|:443… 已连接。
已发出 HTTP 请求,正在等待回应… 200 OK
长度:50000000 (48M) [application/octet-stream]
正在保存至: “TDengine-server-3.2.0.0-Linux-x64.tar.gz”
100%[======================================>] 50,000,000 10.0MB/s 用时 4.8s
2026-04-04 10:00:05 (10.0 MB/s) – 已保存 “TDengine-server-3.2.0.0-Linux-x64.tar.gz”
# 解压安装包
# tar -xzf TDengine-server-3.2.0.0-Linux-x64.tar.gz
# 进入安装目录
# cd TDengine-server-3.2.0.0
# 执行安装脚本
# ./install.sh
# 输出示例:
Start to install TDengine…
Created symlink /etc/systemd/system/multi-user.target.wants/taosd.service → /etc/systemd/system/taosd.service.
Start to configure FQDN…
Enter FQDN:port (like h1.taosdata.com:6030) of an existing TDengine cluster (press Enter to skip):
Enter your email address for priority support (press Enter to skip):
Installation completed successfully.
# 验证安装
# taos -V
version: 3.2.0.0
compatible_version: 3.0.0.0
3.3 启动TDengine服务
# systemctl start taosd
# 设置开机自启动
# systemctl enable taosd
# 输出示例:
Created symlink /etc/systemd/system/multi-user.target.wants/taosd.service → /etc/systemd/system/taosd.service.
# 检查服务状态
# systemctl status taosd
● taosd.service – TDengine server
Loaded: loaded (/etc/systemd/system/taosd.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2026-04-04 10:00:00 CST; 5s ago
Main PID: 12345 (taosd)
Tasks: 50 (limit: 4915)
Memory: 500.0M
CGroup: /system.slice/taosd.service
└─12345 /usr/bin/taosd
# 检查端口
# netstat -tlnp | grep taos
tcp 0 0 0.0.0.0:6030 0.0.0.0:* LISTEN 12345/taosd
tcp 0 0 0.0.0.0:6041 0.0.0.0:* LISTEN 12345/taosd
# 连接测试
$ taos -s “show databases”
taos> show databases;
name |
=================================
information_schema |
performance_schema |
Query OK, 2 rows in database (0.001234s)
4. TDengine参数配置
TDengine参数配置是数据库性能优化的关键步骤,直接影响系统性能。更多学习教程公众号风哥教程itpux_com
4.1 配置文件说明
# vi /etc/taos/taos.cfg
# 主要配置参数说明:
# 集群配置
firstEp fgedudb01:6030
secondEp fgedudb02:6030
# 数据目录
dataDir /data/taos
# 日志目录
logDir /var/log/taos
# 时区设置
timezone Asia/Shanghai
locale zh_CN.UTF-8
charset UTF-8
# 连接配置
maxConnections 5000
maxShellConns 50000
# 存储配置
supportVnodes 256
# 查看当前配置
$ taos -s “show variables”
taos> show variables;
name | value |
================================================================
statusInterval | 1 |
timezone | Asia/Shanghai |
locale | zh_CN.UTF-8 |
charset | UTF-8 |
maxConnections | 5000 |
maxShellConns | 50000 |
4.2 内存参数配置
# vi /etc/taos/taos.cfg
# 内存相关参数
# 每个VNode的写入缓存大小(MB)
writeCacheSize 1024
# 查询缓存大小(MB)
queryCacheSize 512
# 最大内存使用比例
maxMemoryUsedRatio 0.8
# 重启服务
# systemctl restart taosd
# 验证配置
$ taos -s “show variables where name=’writeCacheSize'”
taos> show variables where name=’writeCacheSize’;
name | value |
================================================================
writeCacheSize | 1024 |
4.3 存储参数配置
# vi /etc/taos/taos.cfg
# 存储相关参数
# 数据文件目录
dataDir /data/taos
# 最小数据保留天数
minRetainTime 365
# 压缩算法
compressMsgSize -1
# WAL级别
walLevel 1
# 重启服务
# systemctl restart taosd
# 查看存储信息
$ taos -s “show dnodes”
taos> show dnodes;
id | end_point | vnodes | support_vnodes | status | create_time | reboot_time |
======================================================================================================================================
1 | fgedudb01:6030 | 0 | 256 | ready | 2026-04-04 10:00:00.000 | 2026-04-04 10:00:00.000 |
Query OK, 1 rows in database (0.001234s)
5. 数据库与表管理
TDengine使用超级表和子表的模型管理时序数据,支持标准SQL语法。from:www.itpux.com
5.1 创建数据库
$ taos
# 创建数据库
taos> CREATE DATABASE fgedudb
-> KEEP 365
-> DURATION 10
-> BUFFER 96
-> WAL_LEVEL 1;
# 输出示例:
Query OK, 0 of 0 rows affected (0.001234s)
# 查看数据库
taos> SHOW DATABASES;
name |
=================================
information_schema |
performance_schema |
fgedudb |
Query OK, 3 rows in database (0.001234s)
# 查看数据库详细配置
taos> SHOW CREATE DATABASE fgedudb;
Database: fgedudb | Create Database |
====================================================================
fgedudb | CREATE DATABASE `fgedudb` … |
Query OK, 1 rows in database (0.001234s)
# 使用数据库
taos> USE fgedudb;
Database changed.
# 数据库参数说明:
# KEEP: 数据保留天数
# DURATION: 数据文件存储时间间隔
# BUFFER: 写入缓存大小(MB)
# WAL_LEVEL: WAL级别(0-2)
5.2 创建超级表
taos> CREATE STABLE fgedu_metrics (
-> ts TIMESTAMP,
-> cpu_usage FLOAT,
-> memory_usage FLOAT,
-> disk_usage FLOAT,
-> network_in BIGINT,
-> network_out BIGINT
-> ) TAGS (
-> host_id INT,
-> host_name BINARY(64),
-> region BINARY(32)
-> );
# 输出示例:
Query OK, 0 of 0 rows affected (0.001234s)
# 查看超级表
taos> SHOW STABLES;
name |
=================================
fgedu_metrics |
Query OK, 1 rows in database (0.001234s)
# 查看超级表结构
taos> DESCRIBE fgedu_metrics;
Field | Type | Length | Note |
=======================================================================
ts | TIMESTAMP | 8 | |
cpu_usage | FLOAT | 4 | |
memory_usage | FLOAT | 4 | |
disk_usage | FLOAT | 4 | |
network_in | BIGINT | 8 | |
network_out | BIGINT | 8 | |
host_id | INT | 4 | TAG |
host_name | BINARY | 64 | TAG |
region | BINARY | 32 | TAG |
Query OK, 9 rows in database (0.001234s)
5.3 创建子表并写入数据
taos> INSERT INTO fgedu_metrics_01
-> USING fgedu_metrics TAGS (1, ‘fgedudb01’, ‘cn-north’)
-> VALUES (NOW, 75.5, 65.2, 45.8, 1024000, 512000);
# 输出示例:
Query OK, 1 of 1 rows affected (0.001234s)
# 批量插入数据
taos> INSERT INTO fgedu_metrics_01
-> VALUES
-> (NOW – 10s, 72.3, 63.1, 44.5, 1023000, 511000),
-> (NOW – 20s, 71.8, 62.5, 44.2, 1022000, 510000),
-> (NOW – 30s, 70.5, 61.8, 43.9, 1021000, 509000);
# 输出示例:
Query OK, 3 of 3 rows affected (0.001234s)
# 创建多个子表
taos> INSERT INTO fgedu_metrics_02
-> USING fgedu_metrics TAGS (2, ‘fgedudb02’, ‘cn-north’)
-> VALUES (NOW, 68.5, 55.2, 42.8, 980000, 480000);
taos> INSERT INTO fgedu_metrics_03
-> USING fgedu_metrics TAGS (3, ‘fgedudb03’, ‘cn-south’)
-> VALUES (NOW, 82.3, 72.1, 48.5, 1150000, 580000);
# 查看子表
taos> SHOW TABLES LIKE ‘fgedu_metrics%’;
table_name | created_time | columns | stable_name |
===================================================================================================
fgedu_metrics_01 | 2026-04-04 10:00:00.000 | 6 | fgedu_metrics |
fgedu_metrics_02 | 2026-04-04 10:00:05.000 | 6 | fgedu_metrics |
fgedu_metrics_03 | 2026-04-04 10:00:10.000 | 6 | fgedu_metrics |
Query OK, 3 rows in database (0.001234s)
5.4 数据查询
taos> SELECT * FROM fgedu_metrics_01 LIMIT 5;
ts | cpu_usage | memory_usage | disk_usage | network_in | network_out |
===================================================================================================
2026-04-04 09:59:30.000 | 70.50 | 61.80 | 43.90 | 1021000 | 509000 |
2026-04-04 09:59:40.000 | 71.80 | 62.50 | 44.20 | 1022000 | 510000 |
2026-04-04 09:59:50.000 | 72.30 | 63.10 | 44.50 | 1023000 | 511000 |
2026-04-04 10:00:00.000 | 75.50 | 65.20 | 45.80 | 1024000 | 512000 |
Query OK, 4 rows in database (0.001234s)
# 聚合查询
taos> SELECT AVG(cpu_usage), MAX(memory_usage), MIN(disk_usage)
-> FROM fgedu_metrics
-> GROUP BY host_name;
host_name | avg(cpu_usage) | max(memory_usage) | min(disk_usage) |
================================================================================
fgedudb01 | 72.5250 | 65.2000 | 43.9000 |
fgedudb02 | 68.5000 | 55.2000 | 42.8000 |
fgedudb03 | 82.3000 | 72.1000 | 48.5000 |
Query OK, 3 rows in database (0.001234s)
# 时间范围查询
taos> SELECT * FROM fgedu_metrics
-> WHERE ts > NOW – 1h AND ts <= NOW;
# 降采样查询
taos> SELECT AVG(cpu_usage), AVG(memory_usage)
-> FROM fgedu_metrics
-> INTERVAL(10m);
ts | avg(cpu_usage) | avg(memory_usage) |
====================================================================
2026-04-04 09:50:00.000 | 71.2000 | 62.4000 |
2026-04-04 10:00:00.000 | 75.4333 | 64.1667 |
Query OK, 2 rows in database (0.001234s)
# 标签过滤查询
taos> SELECT * FROM fgedu_metrics WHERE region = ‘cn-north’;
6. 网络连接配置
网络连接配置是客户端访问TDengine的关键,需要正确配置监听端口和连接方式。更多学习教程www.fgedu.net.cn
6.1 配置网络监听
# netstat -tlnp | grep taos
tcp 0 0 0.0.0.0:6030 0.0.0.0:* LISTEN 12345/taosd
tcp 0 0 0.0.0.0:6041 0.0.0.0:* LISTEN 12345/taosd
tcp 0 0 0.0.0.0:6060 0.0.0.0:* LISTEN 12345/taosd
# 端口说明:
# 6030: 客户端连接端口
# 6041: HTTP RESTful端口
# 6060: 集群内部通信端口
# 配置防火墙
# firewall-cmd –permanent –add-port=6030/tcp
success
# firewall-cmd –permanent –add-port=6041/tcp
success
# firewall-cmd –reload
success
6.2 使用RESTful API
$ curl -u root:taosdata -d ‘select * from fgedudb.fgedu_metrics limit 5’ \
http://192.168.1.51:6041/rest/sql
# 输出示例:
{
“status”: “succ”,
“head”: [“ts”,”cpu_usage”,”memory_usage”,”disk_usage”,”network_in”,”network_out”],
“column_meta”: [
[“ts”,9,8],
[“cpu_usage”,6,4],
[“memory_usage”,6,4],
[“disk_usage”,6,4],
[“network_in”,10,8],
[“network_out”,10,8]
],
“data”: [
[“2026-04-04 09:59:30.000”,70.5,61.8,43.9,1021000,509000],
[“2026-04-04 09:59:40.000”,71.8,62.5,44.2,1022000,510000],
[“2026-04-04 09:59:50.000”,72.3,63.1,44.5,1023000,511000],
[“2026-04-04 10:00:00.000”,75.5,65.2,45.8,1024000,512000]
],
“rows”: 4
}
# 使用HTTP接口写入数据
$ curl -u root:taosdata -d ‘insert into fgedudb.fgedu_metrics_01 values(now, 78.5, 66.2, 46.8, 1030000, 515000)’ \
http://192.168.1.51:6041/rest/sql
# 输出示例:
{
“status”: “succ”,
“head”: [“affected_rows”],
“column_meta”: [[“affected_rows”,4,4]],
“data”: [[1]],
“rows”: 1
}
6.3 配置用户认证
$ taos
# 创建用户
taos> CREATE USER fgedu_user PASSWORD ‘fgedupass123’;
# 输出示例:
Query OK, 0 of 0 rows affected (0.001234s)
# 授权
taos> GRANT ALL ON fgedudb.* TO fgedu_user;
# 输出示例:
Query OK, 0 of 0 rows affected (0.001234s)
# 查看用户
taos> SHOW USERS;
name | privilege | create_time |
========================================================================
root | super | 2026-04-04 10:00:00.000 |
fgedu_user | normal | 2026-04-04 10:05:00.000 |
Query OK, 2 rows in database (0.001234s)
# 使用新用户连接
$ taos -h 192.168.1.51 -P 6030 -u fgedu_user -p ‘fgedupass123’
# 修改密码
taos> ALTER USER fgedu_user PASS ‘newpass456’;
7. 备份恢复配置
备份恢复是数据库管理的重要环节,TDengine提供了多种备份恢复方式。学习交流加群风哥微信: itpux-com
7.1 数据备份
# mkdir -p /backup/taos
# 使用taosdump工具备份
# taosdump -o /backup/taos/full_backup -A
# 输出示例:
taosdump version 3.2.0.0
Start to dump all databases…
Dump database: fgedudb
Dump stable: fgedu_metrics
Dump table: fgedu_metrics_01
Dump table: fgedu_metrics_02
Dump table: fgedu_metrics_03
Dump completed successfully. Total rows: 10000
# 备份指定数据库
# taosdump -o /backup/taos/fgedudb_backup -D fgedudb
# 备份指定表
# taosdump -o /backup/taos/table_backup -D fgedudb -T fgedu_metrics_01
# 查看备份文件
# ls -la /backup/taos/full_backup/
总用量 1024
-rw-r–r–. 1 root root 102400 4月 4 10:00 fgedudb.schema
-rw-r–r–. 1 root root 512000 4月 4 10:00 fgedu_metrics_01.data
-rw-r–r–. 1 root root 256000 4月 4 10:00 fgedu_metrics_02.data
7.2 数据恢复
# taosdump -i /backup/taos/full_backup -A
# 输出示例:
taosdump version 3.2.0.0
Start to restore all databases…
Restore database: fgedudb
Restore stable: fgedu_metrics
Restore table: fgedu_metrics_01
Restore table: fgedu_metrics_02
Restore table: fgedu_metrics_03
Restore completed successfully. Total rows: 10000
# 恢复指定数据库
# taosdump -i /backup/taos/fgedudb_backup -D fgedudb
# 恢复时跳过已存在的表
# taosdump -i /backup/taos/full_backup -A -s
# 验证恢复
$ taos -s “use fgedudb; show tables;”
taos> use fgedudb;
Database changed.
taos> show tables;
table_name | created_time | columns | stable_name |
===================================================================================================
fgedu_metrics_01 | 2026-04-04 10:00:00.000 | 6 | fgedu_metrics |
fgedu_metrics_02 | 2026-04-04 10:00:05.000 | 6 | fgedu_metrics |
fgedu_metrics_03 | 2026-04-04 10:00:10.000 | 6 | fgedu_metrics |
7.3 自动备份脚本
# vi /usr/local/bin/taos_backup.sh
#!/bin/bash
BACKUP_DIR=/backup/taos
DATE=$(date +%Y%m%d_%H%M%S)
LOG_FILE=/var/log/taos/backup.log
echo “=== Backup started at $(date) ===” >> $LOG_FILE
taosdump -o ${BACKUP_DIR}/${DATE} -A >> $LOG_FILE 2>&1
if [ $? -eq 0 ]; then
echo “Backup completed successfully” >> $LOG_FILE
# 压缩备份
cd ${BACKUP_DIR}
tar -czf ${DATE}.tar.gz ${DATE}
rm -rf ${DATE}
else
echo “Backup failed” >> $LOG_FILE
fi
# 清理30天前的备份
find ${BACKUP_DIR} -name “*.tar.gz” -mtime +30 -delete >> $LOG_FILE 2>&1
echo “=== Backup finished at $(date) ===” >> $LOG_FILE
echo “” >> $LOG_FILE
# 设置脚本权限
# chmod +x /usr/local/bin/taos_backup.sh
# 配置定时任务
# crontab -e
# 添加以下内容(每天凌晨2点执行备份)
0 2 * * * /usr/local/bin/taos_backup.sh
8. 升级与迁移
TDengine升级和迁移是运维工作中的重要环节,需要仔细规划和执行。更多学习教程公众号风哥教程itpux_com
8.1 版本升级
$ taos -V
version: 3.2.0.0
# 执行完整备份
# taosdump -o /backup/taos/pre_upgrade -A
# 停止服务
# systemctl stop taosd
# 下载新版本
# cd /usr/local/src
# wget https://www.taosdata.com/assets-download/3.0/TDengine-server-3.2.1.0-Linux-x64.tar.gz
# 解压并安装
# tar -xzf TDengine-server-3.2.1.0-Linux-x64.tar.gz
# cd TDengine-server-3.2.1.0
# ./install.sh
# 启动服务
# systemctl start taosd
# 验证版本
$ taos -V
version: 3.2.1.0
# 验证数据完整性
$ taos -s “show databases; show dnodes;”
8.2 迁移到新服务器
# taosdump -o /backup/taos/migration -A
# 传输备份文件
# scp -r /backup/taos/migration new-server:/backup/taos/
# 在新服务器安装TDengine
# 参考3.2节安装步骤
# 恢复数据
# taosdump -i /backup/taos/migration -A
# 验证迁移
$ taos -s “show databases; use fgedudb; show tables;”
# 更新应用连接配置
# 修改应用配置文件中的连接地址为新服务器
9. 生产环境实战案例
本节提供一个完整的生产环境配置案例,帮助读者更好地理解TDengine的实际应用。from:www.itpux.com
9.1 集群部署
# 至少需要3个节点
# 节点1: fgedudb01 (192.168.1.51)
# 节点2: fgedudb02 (192.168.1.52)
# 节点3: fgedudb03 (192.168.1.53)
# 在所有节点配置hosts
# vi /etc/hosts
192.168.1.51 fgedudb01
192.168.1.52 fgedudb02
192.168.1.53 fgedudb03
# 在第一个节点配置
# vi /etc/taos/taos.cfg
firstEp fgedudb01:6030
secondEp fgedudb02:6030
fqdn fgedudb01
# 在其他节点配置
# vi /etc/taos/taos.cfg
firstEp fgedudb01:6030
secondEp fgedudb02:6030
fqdn fgedudb02 # 或 fgedudb03
# 启动所有节点服务
# systemctl start taosd
# 添加节点到集群
$ taos -s “CREATE DNODE ‘fgedudb02:6030’;”
$ taos -s “CREATE DNODE ‘fgedudb03:6030’;”
# 查看集群状态
$ taos -s “SHOW DNODES;”
taos> SHOW DNODES;
id | end_point | vnodes | support_vnodes | status |
===============================================================================
1 | fgedudb01:6030 | 2 | 256 | ready |
2 | fgedudb02:6030 | 2 | 256 | ready |
3 | fgedudb03:6030 | 2 | 256 | ready |
9.2 性能监控
$ taos -s “SHOW VNODES;”
taos> SHOW VNODES;
vgId | status | role | replica | create_time |
=========================================================================
2 | ready | master | 1 | 2026-04-04 10:00:00.000 |
3 | ready | master | 1 | 2026-04-04 10:00:05.000 |
# 查看写入性能
$ taos -s “SHOW QUERY;”
taos> SHOW QUERY;
query_id | start_time | duration | query |
==============================================================================
1 | 2026-04-04 10:00:00.000 | 0.001s | select * from… |
# 查看连接数
$ taos -s “SHOW CONNECTIONS;”
taos> SHOW CONNECTIONS;
id | create_time | ip | user |
===========================================================================
1 | 2026-04-04 10:00:00.000 | 192.168.1.100:54321 | root |
2 | 2026-04-04 10:00:05.000 | 192.168.1.101:54322 | fgedu_user |
# 查看存储使用
$ taos -s “SHOW VGROUPS;”
taos> SHOW VGROUPS;
vgId | status | tables | v1_dnode | v1_status |
=================================================================
2 | ready | 10 | 1 | master |
9.3 数据订阅
taos> CREATE TOPIC fgedu_metrics_topic AS SELECT * FROM fgedu_metrics;
# 输出示例:
Query OK, 0 of 0 rows affected (0.001234s)
# 查看主题
taos> SHOW TOPICS;
topic_name | create_time |
================================================================
fgedu_metrics_topic | 2026-04-04 10:00:00.000 |
# 使用tmq客户端订阅数据
# Python示例
import taos
def consume_messages():
conn = taos.connect(host=’192.168.1.51′, user=’root’, password=’taosdata’)
consumer = conn.consumer(‘fgedu_metrics_topic’, ‘consumer_group_1’)
while True:
messages = consumer.poll(timeout=1.0)
for msg in messages:
print(f”Received: {msg.value}”)
consumer.close()
conn.close()
# 删除主题
taos> DROP TOPIC fgedu_metrics_topic;
本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html
