Debian10安装 TDengine2.4.30安装过程、远程连接、Java连接和问题总结--一站式

Debian10安装 TDengine2.4.30安装过程、远程连接、Java连接和问题总结--一站式

下载地址:https://github.com/taosdata/TDengine/releases 找到适用的版本,我是用的是2.4.30

点击下载tar.gz文件

将文件通过MobaXterm等终端管理工具软件,连接到linux系统,将文件传输到Linux系统 运行

安装过程

 tar zxvf TDengine-server-2.4.0.30-Linux-x64.tar.gz #解压
 cd ./TDengine-server-2.4.0.30 #进入到安装目录
 ./install.sh  # 安装
 vim /etc/taos/taos.cfg #打开TDengine的配置文件 找到logDir和dataDir 修改日志存储位置和数据存储位置,其余配置可根据需要自行配置  记得要在指定的目录下创建好文件目录
 
 #Debian10 系统执行
 service taosd stare #启动
 service taosd status# 查看状态
 service taosd stop # 停止
 
 #Centos& 系统执行
 systemctl stare taosd #启动
 systemctl status taosd# 查看状态
 systemctl stop taosd # 停止
 
 --------------------------------------------------------
 
 

TDengine自带测试工具的使用

taosBenchmark
  在无参数运行时,taosBenchmark 默认连接 /etc/taos 下指定的 TDengine 集群,并在 TDengine 中创建一个名为 test 的数据库,test 数据库下创建名为 meters 的一张超级表,超级表下创建 10000 张表,每张表中写入 10000 条记录。注意,如果已有 test 数据库,这个命令会先删除该数据库后建立一个全新的 test 数据库。

taosBenchmark -I stmt -n 200 -t 100
  上面的命令 taosBenchmark 将创建一个名为test的数据库,在其中建立一张超级表meters,在该超级表中建立 100 张子表并使用参数绑定的方式为每张子表插入 200 条记录。
  
taosBenchmark 安装包中提供了配置文件的示例,位于 <install_directory>/examples/taosbenchmark-json 下
使用如下命令行即可运行 taosBenchmark 并通过配置文件控制其行为。

taosBenchmark -f <json file>
下面是几个配置文件的示例:

插入场景 JSON 配置文件示例
insert.json
	{
    "filetype": "insert",
    "cfgdir": "/etc/taos",
    "host": "127.0.0.1",
    "port": 6030,
    "user": "root",
    "password": "taosdata",
    "connection_pool_size": 8,
    "thread_count": 4,
    "create_table_thread_count": 7,
    "result_file": "./insert_res.txt",
    "confirm_parameter_prompt": "no",
    "insert_interval": 0,
    "interlace_rows": 100,
    "num_of_records_per_req": 100,
    "prepared_rand": 10000,
    "chinese": "no",
    "databases": [
        {
            "dbinfo": {
                "name": "test",
                "drop": "yes",
                "replica": 1,
                "precision": "ms",
                "keep": 3650,
                "minRows": 100,
                "maxRows": 4096,
                "comp": 2
            },
            "super_tables": [
                {
                    "name": "meters",
                    "child_table_exists": "no",
                    "childtable_count": 10000,
                    "childtable_prefix": "d",
                    "escape_character": "yes",
                    "auto_create_table": "no",
                    "batch_create_tbl_num": 5,
                    "data_source": "rand",
                    "insert_mode": "taosc",
                    "non_stop_mode": "no",
                    "line_protocol": "line",
                    "insert_rows": 10000,
                    "childtable_limit": 10,
                    "childtable_offset": 100,
                    "interlace_rows": 0,
                    "insert_interval": 0,
                    "partial_col_num": 0,
                    "disorder_ratio": 0,
                    "disorder_range": 1000,
                    "timestamp_step": 10,
                    "start_timestamp": "2020-10-01 00:00:00.000",
                    "sample_format": "csv",
                    "sample_file": "./sample.csv",
                    "use_sample_ts": "no",
                    "tags_file": "",
                    "columns": [
                        {
                            "type": "FLOAT",
                            "name": "current",
                            "count": 1,
                            "max": 12,
                            "min": 8
                        },
                        { "type": "INT", "name": "voltage", "max": 225, "min": 215 },
                        { "type": "FLOAT", "name": "phase", "max": 1, "min": 0 }
                    ],
                    "tags": [
                        {
                            "type": "TINYINT",
                            "name": "groupid",
                            "max": 10,
                            "min": 1
                        },
                        {
                            "name": "location",
                            "type": "BINARY",
                            "len": 16,
                            "values": ["San Francisco", "Los Angles", "San Diego",
                                "San Jose", "Palo Alto", "Campbell", "Mountain View",
                                "Sunnyvale", "Santa Clara", "Cupertino"]
                        }
                    ]
                }
            ]
        }
    ]
}

查询场景 JSON 配置文件示例
query.json
	{
    "filetype": "query",
    "cfgdir": "/etc/taos",
    "host": "127.0.0.1",
    "port": 6030,
    "user": "root",
    "password": "taosdata",
    "confirm_parameter_prompt": "no",
    "databases": "test",
    "query_times": 2,
    "query_mode": "taosc",
    "specified_table_query": {
        "query_interval": 1,
        "concurrent": 3,
        "sqls": [
            {
                "sql": "select last_row(*) from meters",
                "result": "./query_res0.txt"
            },
            {
                "sql": "select count(*) from d0",
                "result": "./query_res1.txt"
            }
        ]
    },
    "super_table_query": {
        "stblname": "meters",
        "query_interval": 1,
        "threads": 3,
        "sqls": [
            {
                "sql": "select last_row(ts) from xxxx",
                "result": "./query_res2.txt"
            }
        ]
    }
}

订阅场景 JSON 配置文件示例
subscribe.json
	{
    "filetype": "subscribe",
    "cfgdir": "/etc/taos",
    "host": "127.0.0.1",
    "port": 6030,
    "user": "root",
    "password": "taosdata",
    "databases": "test",
    "specified_table_query": {
        "concurrent": 1,
        "mode": "sync",
        "interval": 1000,
        "restart": "yes",
        "keepProgress": "yes",
        "resubAfterConsume": 10,
        "sqls": [
            {
                "sql": "select avg(current) from meters where location = 'beijing';",
                "result": "./subscribe_res0.txt"
            }
        ]
    },
    "super_table_query": {
        "stblname": "meters",
        "threads": 1,
        "mode": "sync",
        "interval": 1000,
        "restart": "yes",
        "keepProgress": "yes",
        "sqls": [
            {
                "sql": "select phase from xxxx where groupid > 3;",
                "result": "./subscribe_res1.txt"
            }
        ]
    }
}

其他请参考官方文档

官方文档:https://docs.taosdata.com/2.4/reference/taosbenchmark/

远程连接

服务端(Debian10系统)配置

修改hostname

先决条件

要更改系统主机名,您需要以root用户或具有sudo权限的用户登录。

查看当前主机名

在使用systemd的Debian 10和所有其他Linux发行版中,您可以更改和使用hostnamectl命令指定系统的主机名。。要查看当前系统的主机名,请键入hostnamectl,不带任何选项:

hostnamectl

输出将显示当前系统主机名,在本教程中为debian

Static hostname: debian        
Icon name: computer-vm            
Chassis: vm         
Machine ID: 70a3f06298014fd9ac42e5dc1de1034a            
Boot ID: 1dc8b9af89a4426b99cb348f6d483757     
Virtualization: oracle   
Operating System: Debian GNU/Linux 10 (buster)             
Kernel: Linux 4.19.0-5-amd64       
Architecture: x86-64

更改系统主机名

主机名是用于标识网络上计算机的标签。您不应该在同一网络中的两台不同计算机上设置相同的主机名。建议使用全限定域名FQDN,作为系统主机名。

在Debian 10上更改系统主机名时涉及两个步骤。首先,使用hostnamectl set-hostname命令设置新主机名,然后输入所需的主机名,然后使用新主机名更新/etc/hosts文件。

例如,要将系统主机名更改为myDebian.com,请执行以下步骤。首先通过运行以下命令来设置新的主机名:

 hostnamectl set-hostname arya.example.com

hostnamectl命令不会产生输出。成功时,返回0,否则返回非零失败代码。

其次,使用你喜欢的编辑器打开/etc/hosts文件,并将旧主机名替换为新主机名。在本教程中我们将使用vim打开/etc/hosts文件

 vim  /etc/hosts

复制粘帖127.0.0.1 myDebian.com行到你的/etc/hosts文件文件中:

127.0.0.1   localhost
127.0.0.1   arya.example.com ##添加新修改的主机名与IP的映射

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

然后保存并推出vim编辑器

验证更改

要验证主机名是否已成功更改,请再次使用hostnamectl命令:

hostnamectl

新的系统主机名将打印在命令行上。

   Static hostname: myDebian.com
         Icon name: computer-vm
           Chassis: vm
        Machine ID: 70a3f06298014fd9ac42e5dc1de1034a
           Boot ID: 1dc8b9af89a4426b99cb348f6d483757
    Virtualization: oracle
  Operating System: Debian GNU/Linux 10 (buster)
            Kernel: Linux 4.19.0-5-amd64
      Architecture: x86-64

修改host文件

vim /etc/hosts

i切换为insert模式,将hostname修改成刚设置好的主机名,并 添加上IP和主机名 用于外界访问修改完成后,按Esc键退出insert模式,按Shift + : 在屏幕左下角会出现: 再输入wq 保存并退出文件

修改taos.cfg

进入目录 /etc/taos vim /etc/taos/taos.cfg ,修改TDengine数据库服务器的taos.cfg文件

# first fully qualified domain name (FQDN) for TDengine system

 firsEp                myDebian.com:6030

# local fully qualified domain name (FQDN)

 fqdn                     myDebian.com
"/etc/taos/taos.cfg" 285L, 8138C

Debian10还需要打开端口访问

iptables -I INPUT -p TCP --dport 6030 -j ACCEPT
iptables -I INPUT -p UDP --dport 6030 -j ACCEPT

至此服务端FQDN相关配置已完成,启动服务验证即可

[root@myDebian ~]# systemctl start taosd
[root@myDebian ~]# systemctl status taosd
● taosd.service - TDengine server service
   Loaded: loaded (/etc/systemd/system/taosd.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2021-09-30 09:16:46 CST; 3s ago
  Process: 2301 ExecStartPre=/usr/local/taos/bin/startPre.sh (code=exited, status=0/SUCCESS)
 Main PID: 2307 (taosd)
   CGroup: /system.slice/taosd.service
           └─2307 /usr/bin/taosd

Sep 30 09:16:46 myDebian systemd[1]: Starting TDengine server service...
Sep 30 09:16:46 myDebian systemd[1]: Started TDengine server service.
Sep 30 09:16:46 myDebian TDengine:[2307]: Starting TDengine service...
Sep 30 09:16:46 myDebian TDengine:[2307]: Started TDengine service successfully.

PS:
如果不是初次启动,那么很不幸,这里启动将失败,需要额外修改dnodeEps.json里面的fqdn信息

若不知道文件的位置可以通过 find / -name dnodeEps.json文件来定位

[root@myDebian ~]# vim /var/lib/taos/dnode/dnodeEps.json 
{
  "dnodeNum": 1,
  "dnodeInfos": [{
    "dnodeId": 1,
    "dnodeFqdn": "myDebian.com",
    "dnodePort": 6030
  }]
}
~                                                                                                                                                                                              
~
"/var/lib/taos/dnode/dnodeEps.json" 8L, 122C   

客户端(Windows)配置

下载安装

首先要下载和服务端版本一致的客户端---下载地址

下载完毕后,打开C:\TDengine\cfg\taos.cfg文件 配置firstEp、fqdn

# first fully qualified domain name (FQDN) for TDengine system

 firstEp                   myDebian.com:6030

# local fully qualified domain name (FQDN)

 fqdn                      myDebian.com

用记事本打开C:\Windows\System32\drivers\etc\hosts文件,添加服务器IP和hostname修改客户段的hostname

#例子:
192.168.19.138 myDebian.com

至此客户端的配置全部完成,可以打开下载的Taos Shell输入taos就可连接服务端的TDEngine了

JAVA连接TDEngine

官方文档地址

maven

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

版本支持

TDengine 版本更新往往会增加新的功能特性,列表中的连接器版本为连接器最佳适配版本。

TDengine 版本 Java Python Go C# Node.js Rust
2.4.0.14 及以上 2.0.38 当前版本 develop 分支 1.0.2 - 1.0.6 2.0.10 - 2.0.12 当前版本
2.4.0.6 及以上 2.0.37 当前版本 develop 分支 1.0.2 - 1.0.6 2.0.10 - 2.0.12 当前版本
2.4.0.4 - 2.4.0.5 2.0.37 当前版本 develop 分支 1.0.2 - 1.0.6 2.0.10 - 2.0.12 当前版本
2.2.x.x 2.0.36 当前版本 master 分支 n/a 2.0.7 - 2.0.9 当前版本
2.0.x.x 2.0.34 当前版本 master 分支 n/a 2.0.1 - 2.0.6 当前版本

连接例子

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class Demo {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Class.forName("com.taosdata.jdbc.TSDBDriver");
        String jdbcUrl = "jdbc:TAOS://xuhxDebian.com:6030/?user=root&password=taosdata";
        Connection conn = DriverManager.getConnection(jdbcUrl);

        System.out.println("Connected");
        conn.close();
    }
}

若控制台出现Connected则标识连接成功

posted @ 2022-08-25 16:10  Demo4  阅读(489)  评论(0编辑  收藏  举报