TDengine installation and use

introduction

Recently, I heard about the time-series database TDengine, and my curiosity came out again. Isn’t InfluxDB, which is also a time-series database, also very good? Through some online information and some simple practical operations, I came to the conclusion that:

  • InfluxDB performs better when the amount of data is small

  • When the amount of data becomes larger and larger, TDengine is more suitable for you to use

Introduction

This article will give a brief introduction to TGengine. Of course, I am also using it for the first time. This document is only a preliminary learning record. If anyone has used TGengine in practice and thinks there is any problem with this article, please leave a message below. I will modify the article according to the actual situation, this is also to prevent others from leaving pits

  1. A brief introduction to TGengine (excerpted from official documents)

  2. The process of installing the TGengine server

  3. TDengine data modeling

  4. How DataGrip Views Data

  5. REST connection test using java language

In addition, the server on my side is TDengine-server-2.6.0.30-Linux-x64.tar.gzinstalled using

introduce

Note: The content of this paragraph is taken from the official document

TDengine is a high-performance, distributed, and SQL-supporting time-series database (Database). Its core code, including cluster functions, is all open source (open source protocol, AGPL v3.0). TDengine can be widely used in the Internet of Things, Industrial Internet, Internet of Vehicles, IT operation and maintenance, finance and other fields. In addition to the core time series database (Database) function, TDengine also provides a series of functions required by big data platforms such as caching, data subscription, and streaming computing, minimizing the complexity of R&D and operation and maintenance.

complain

In the process of comparison, I found that the official documentation of TDengine is not very good. How to say it, although the changes are mentioned, but it needs to read a lot of content before it can be completely resolved. This is not very good. For example, installation, although it is included in the immediate start, but the detailed installation and uninstallation is placed in the operation and maintenance guide. According to our habits, from top to bottom, from left to right, you may see the installation and uninstallation at the end , but before that, there are a lot of practical documents mixed in the middle.

Install the server

Currently version 2.X server taosd and taosAdapter can only be installed and run on Linux system, application driver taosc and TDengine CLI can be installed and run on Windows or Linux. In addition, there is no taosAdapter in versions before 2.4, and the RESTful interface is provided by the built-in HTTP service of taosd.

  1. Download the installation package TDengine-server-2.6.0.30-Linux-x64.tar.gz (45 M) and upload it to the server

    Link: https://pan.baidu.com/s/1-w7O2xUuq0iaF1glh36bow?pwd=ansm Extraction code: ansm

  2. Enter the directory where the installation package is located, unzip the file

    # 解压命令
    tar -zxvf TDengine-server-2.6.0.30-Linux-x64.tar.gz
    
  3. Enter the decompression directory and execute the install.sh installation script in it

    # 进入解压目录命令(目录根据自己的解决自行更改)
    cd /app/TDengine-server-2.6.0.30
    # 执行安装命令
    ./install.sh
    

Note: Enter twice in the middle, just press Enter, you don’t need to enter anything

2022-11-24-16-07-50-image.png

  1. Start taosd and confirm the status

    # 启动命令
    systemctl start taosd
    # 确认状态
    systemctl status taosd
    

  1. Start taosAdapter and confirm the status

    Note: TDengine contains an independent component taosAdapter after version 2.4. You need to use the systemctl command to manage the start and stop of the taosAdapter service. If it does not meet the requirements, skip this step

    ```shell
    # 启动命令
    systemctl start taosadapter
    # 确认状态
    systemctl status taosadapter
    
    
    

  1. Enter taos, confirm the installation is successful,

    # 启动命令(默认密码taosdata)
    taos -p
    

TDengine data modeling

  1. create database

    # 创建数据库命令
    CREATE DATABASE power;
    # 切换数据库
    USE power;
    

  1. create table

    # 创建表
    create table t (ts timestamp, speed int);
    # 插入2条数据(建议插入两条记录时隔几秒)
    insert into t values (now, 10);
    insert into t values (now, 20);
    

  1. query table data

    # 查询表 t
    select * from t;
    

DataGripView data

  1. compile jar

    Clone the source code of the JDBC connector from the GitHub repository, git clone https://github.com/taosdata/taos-connector-jdbc.git -b 2.0.40(here -b is recommended to specify the released Tags version)

    After cloning the source code, if compiling versions 2.0.40 and below, change the scope value of the commons-logging dependency package from test to compile

    Execute in the directory:mvn clean package -D maven.test.skip=true

  1. self built driver

    Use Driver and Data Source, build your own driver, pay attention to the content in the red box, the jar package is compiled and generated before

  1. Create database connection

    The first red box Driver selects the self-built before, and the second red box URL writesjdbc:TAOS-RS://IP:6041/数据库名

java for REST connection test

Create a new Springboot project, and maven imports the jar package

<dependency>
    <groupId>com.taosdata.jdbc</groupId>
    <artifactId>taos-jdbcdriver</artifactId>
    <version>2.0.40</version>
</dependency>

main method:

public static void main(String[] args) throws SQLException {
    
    
    String jdbcUrl = "jdbc:TAOS-RS://IP:6041/数据库名?user=用户名&password=密码";
    Connection conn = DriverManager.getConnection(jdbcUrl);
    System.out.println("Connected");
    conn.close();
}

Test Results:

Guess you like

Origin blog.csdn.net/huangge1199/article/details/128036885