Skip to content

Time-Series Database ​

Prerequisites ​

  • Docker is installed, and the bridge network for inter-container communication exists: docker network create -d bridge fastbee-bridge
  • You have chosen one time-series storage based on data volume: MySQL works for small volumes; for large volumes choose one of TDengine, InfluxDB, or IoTDB — they cannot be enabled at the same time.
  • You have recorded the connection address, port, account, and password of the chosen database; they are required in the enablement configuration.
  • For TDengine, the server, client, and client driver versions must match.

Enabling a Time-Series Database ​

The system currently supports four time-series data storage methods: mysql, tdengine, influxdb, and iotdb. Small data volumes can be stored in mysql; for large volumes, choose one of tdengine, influxdb, or iotdb as needed — they cannot be enabled at the same time. The application-sql configuration file contains configuration examples for the three time-series databases. In the development or production environment, copy the configuration of the corresponding time-series database from the application-sql file into application-dev or application-prod, and change enable to true to enable it. The corresponding time-series database must be installed before enabling; see the installation steps for each database below.

Time-series database configuration example screenshotTime-series database configuration example screenshot

Installing on an Operating System ​

There are plenty of similar tutorials and documents, and Windows and Linux have different installation methods, so they are not covered in detail here. The Docker-based installation is mainly introduced below.

Docker Installation ​

提示

Before running the container, if there is no bridge network, create one first for inter-container communication: docker network create -d bridge fastbee-bridge

1. TDengine Installation ​

Run the following command to install TDengine; the hostname is set for client connections.

shell
docker run -d \
--name tdengine \
--hostname="fastbee" \
--volume /var/data/taos/log:/var/log/taos \
--volume /var/data/taos/data:/var/lib/taos \
--publish 6030-6049:6030-6049 \
--publish 6030-6049:6030-6049/udp \
--restart unless-stopped \
--volume /etc/localtime:/etc/localtime \
--env "TZ=Asia/Shanghai" \
tdengine/tdengine:3.3.2.0

About TDengine ​

警告

  • The server, client, and client driver versions must match.
  • The system uses MySQL by default to store device-reported data; for large data volumes, TDengine storage can be enabled.

The TDengine Community Edition is an open-source version under the AGPL license, and it is a platform for processing small and medium-scale IoT data. It provides all the capabilities needed to process IoT data efficiently, including:

  • A SQL-like query language to insert or query data
  • Development interfaces such as C/C++, Java (JDBC), Python, Go, RESTful, and Node.JS
  • Ad hoc query and analysis through the TDengine Shell or Python/R/Matlab
  • Stream computing based on sliding windows through continuous queries
  • Super tables, which make data aggregation across devices simple and flexible through tags
  • A built-in message queue, so applications can subscribe to the latest data
  • A built-in caching mechanism, so the latest state or record of each device is quickly available
  • No distinction between historical and real-time data — transparent and identical to applications
  • A distributed architecture with linear scalability, so any data volume can be handled
  • Multi-replica support with no single point of failure, ensuring high availability and reliability

Enabling TDengine in the System ​

提示

  • If TDengine is installed on a server while the project runs locally, the client driver must be installed first. View details
  • After installing TDengine, FQDN must be configured for remote client connections. Reference document
  • JDBCDriver cannot find the dynamic link library on Windows. Solution
  1. Modify the configuration file, located at: springboot/fastbee-admin/src/main/resources/application-dev.yml; for production, use application-prod.yml
yml
        taos:                                # Configure the taos data source
          enabled: false                     # TDengine is disabled by default; true=enabled, false=disabled
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.taosdata.jdbc.TSDBDriver
          url: jdbc:TAOS://fastbee:6030/fastbee_log?timezone=UTC-8&charset=utf-8
          username: root
          password: taosdata
          dbName: fastbee_log
  1. Start the project. If TDengine is connected correctly, the fastbee_log database and the device_log super table are created automatically; after devices report data, subtables named device_<device-number> are created automatically.

Connecting to TDengine Remotely with Client Tools ​

提示

  • hostname — the host name; in a LAN, the host name can also be resolved to an IP (server-side setting)
  • hosts — the local DNS system; domain queries check this file first and only query the DNS server when no match is found (client-side setting)

TDengine uses an FQDN (usually the hostname) as the node ID. To ensure normal operation, configure the FQDN on the server running taosd, and configure DNS or the hosts file on the machine running the TDengine CLI or the application, so the FQDN can be resolved. An FQDN (fully qualified domain name) is the complete domain name of a computer or host, consisting of the host name and the domain name. DNS translates FQDNs into IPs and is the addressing method used by the vast majority of Internet applications.

  1. Linux server and client setup
  • Change the content of the /etc/hostname file to fastbee; a restart is required for this to take effect, or run the hostname fastbee command
  • Edit the /etc/hosts file and append 10.211.55.14 fastbee at the end; fill in the IP according to your own server
  1. Windows currently only supports deploying the client
  • Edit the hosts file in the C:\Windows\System32\drivers\etc directory and append 10.211.55.14 fastbee at the end; fill in the IP according to your own server
  1. Client tool download: TDengineGUI

2. InfluxDB Installation ​

Run the following command to install InfluxDB; the bridge network must be created first: docker network create -d bridge fastbee-bridge

shell
docker run -d \
  --name influxdb \
  -p 8086:8086 \
  -v /var/data/influxdb2:/var/lib/influxdb2 \
  -e DOCKER_INFLUXDB_INIT_MODE="setup" \
  -e DOCKER_INFLUXDB_INIT_USERNAME="admin" \
  -e DOCKER_INFLUXDB_INIT_PASSWORD="admin123" \
  -e DOCKER_INFLUXDB_INIT_ORG="fastbee" \
  -e DOCKER_INFLUXDB_INIT_BUCKET="device_log" \
  -e DOCKER_INFLUXDB_INIT_ADMIN_TOKEN="inX0k-IPfSgKg6AIfoZm6Mv0DQyQOKCkfvs5ZF3a836Yzx2Ew9QgxsHev40_2gztuMn6tofwyS6nfbT4cD-SeA==" \
  --network fastbee-bridge \
  influxdb:2.7.5

InfluxDB 2.x comes with a built-in visualization tool. The command above automatically creates the login account admin with password admin123, ORG fastbee, the bucket (equivalent to a table) device_log, and an access TOKEN. Access the InfluxDB console via ip:8086: InfluxDB console access page screenshot

Log in with admin / admin123 to see the following page: InfluxDB post-login page screenshot

3. IoTDB Installation ​

Run the following command to install IoTDB; the bridge network must be created first: docker network create -d bridge fastbee-bridge

shell
docker run -d \
  --name iotdb \
  --restart always \
  -p 6667:6667 \
  -p 5555:5555 \
  -p 8070:8070 \
  -p 9003:9003 \
  --privileged \
  -v /var/data/iotdb/data:/iotdb/data \
  -v /var/data/iotdb/logs:/iotdb/logs \
  -v /var/data/iotdb/conf:/iotdb/conf \
  -e TZ=Asia/Shanghai \
  --network fastbee-bridge \
  apache/iotdb:1.3.3-standalone

After IoTDB is installed, the SQL that creates the time-series fields must be executed before it can be enabled. The steps are as follows:

1. Configure the IoTDB Database Connection Driver in the IDEA Development Tool (or Another Tool) ​

The driver location is as follows: IoTDB driver location screenshot The configuration is as follows: IoTDB driver configuration screenshotIoTDB driver configuration screenshot

Configure the data source: IoTDB data source configuration screenshot

After configuration, right-click to create a new query console. IoTDB new query console screenshot Find the IoTDB initialization SQL and copy the SQL that creates the time series into the console to execute it. IoTDB initialization SQL screenshot Once execution succeeds, the IoTDB time-series database can be enabled. IoTDB execution success screenshot

Verifying the Enablement ​

  1. After modifying the configuration and restarting the backend, the startup log contains no data source connection errors.
  2. TDengine: once connected correctly, the fastbee_log database and the device_log super table are created automatically; after devices report data, subtables named device_<device-number> are created automatically.
  3. InfluxDB: log in to the console at ip:8086 and confirm new data is written to the device_log bucket after devices report data.
  4. IoTDB: confirm the initialization SQL has been executed successfully, and time-series data can be queried after devices report data.
  5. Query device history data on the platform pages and confirm it displays correctly.

Troubleshooting ​

IssuePossible CauseSolution
Backend startup reports TDengine connection failureFQDN not resolved or client driver not installedConfigure FQDN/hosts as described above, and install the client driver matching the server version
JDBCDriver cannot find the dynamic link library on WindowsClient driver not installedInstall the TDengine client driver using the link above
Cannot log in to the InfluxDB consoleWrong initialization account or TOKENCheck the initialization account, password, and TOKEN in the container environment variables
IoTDB write errors after enablementThe initialization SQL that creates the time-series fields was not executedExecute the initialization SQL in the query console first, then enable
Enablement has no effectThe wrong environment configuration file was modifiedConfirm you modified application-dev.yml or application-prod.yml matching the current environment
Multiple time-series databases enabled at onceConfiguration conflictKeep enabled set to true for only one time-series storage