时序数据库
时序数据库(Time Series Database,TSDB) 全称为时间序列数据库。时间序列数据库指主要用于处理带时间标签(按照时间的顺序变化,即时间序列化)的数据,带时间标签的数据也称为时间序列数据
通过 DB-Engines网站排名, 可以看到很多时序数据库
1、时序数据的主要数据属性
(1)每个数据点都包含用于索引、聚合和采样的时间戳。该数据也可以是多维的和相关的;
(2)写多读少,需要支持秒级和毫秒级甚至纳秒级高频写入;查询通常是多维聚合查询,对查询的延迟要求比较高
(3)数据的汇总视图(例如,下采样或聚合视图、趋势线)可能比单个数据点提供更多的洞察力。例如,考虑到网络不可靠性或传感器读数异常,我们可能会在一段时间内的某个平均值超过阈值时设置警报,而不是在单个数据点上这样做;
(4)分析数据通常需要在一段时间内访问它(如,给我过去一周的点击率数据)
2、时序数据库应用场景
时序数据库的应用场景在物联网和互联网APM等场景应用比较多
(1)公共安全:上网记录、通话记录、个体追踪、区间筛选;
(2)电力行业:智能电表、电网、发电设备的集中监测;
(3)互联网:服务器/应用监测、用户访问日志、广告点击日志;
(4)物联网:电梯、锅炉、机械、水表等各种联网设备;
(5)交通行业:实时路况、路口流量监测、卡口数据
(6)金融行业:交易记录、存取记录、ATM、POS机监测
TDengine涛思
其实我也不知道为什么就直接使用了TDengine涛思时序数据库,只能说公司之前有同事使用过,想着刚开始研究时序库,一旦出了问题有人在一起讨论,因此才选择了TDengine。至于TDengine到底性能如何,博主只是看着网上研究资料确实较少,也有不少网友吐槽,但是博主在此无法给出评价,也不发表意见,毕竟使用人家免费的(但是下载server和client安装包时要输入邮箱才能下载,这个,呃,呃,呃......)。
TDengine涛思官网: TDengine | 开源、高性能、分布式、支持 SQL 的时序数据库 | 涛思数据
TDengine涛思是一款开源、高性能、分布式、支持 SQL 的时序数据库
官网文档:产品简介 | TDengine 文档
当然目前更新确实标比较快啊,博主4月中旬查阅文档就和五一之后的官网文档界面不同了(据说半个月更新一次)
一、安装
1、Docker安装
文档: 立即开始 | TDengine 文档
前提确认安装了Docker
执行如下命令
docker run -d -p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp tdengine/tdengine
如果要将使用TDengine时序库的服务发布到Linux系统上,映射taos驱动,并映射hostname,这里博主先声明一下,下面会有遇到的bug再详解
-v /usr/local/taos/driver/libtaos.so.2.1.1.0:/usr/lib/libtaos.so
完整如下
docker run -d \
--name application-name \
--hostname docker-hostname \
-v /usr/local/taos/driver/libtaos.so.2.4.0.5:/usr/lib/libtaos.so \
-v /usr/share/zoneinfo:/usr/share/zoneinfo \
-e TZ=Asia/Shanghai \
-p 6030-6049:6030-6049 -p 6030-6049:6030-6049/udp \
docker-image-name
确定该容器已经启动并且在正常运行
docker ps
进入该容器并执行 bash
docker exec -it
启动taos
安装后,请使用 systemctl 命令来启动 TDengine 的服务进程
systemctl start taosd
检查服务是否正常工作:
systemctl status taosd
2、安装包
文档: 立即开始 | TDengine 文档
从官网下载获得 tar.gz 安装包(安装Linux下,如TDengine-server-2.4.0.5-Linux-x64.tar)
tar xvzf TDengine-enterprise-server-2.4.0.5-Linux-x64.tar.gz -C 安装目录
(1)安装
cd opt/taos/TDengine-server-2.4.0.5
sudo ./install.sh
(2)运行
systemctl start taosd
systemctl status taosd 查看运行状态
3、升级
常见问题及反馈 | TDengine 文档 | 涛思数据
3.0 版在之前版本的基础上,进行了完全的重构,配置文件和数据文件是不兼容的。在升级之前务必进行如下操作:
删除配置文件,执行 sudo rm -rf /etc/taos/taos.cfg删除日志文件,执行 sudo rm -rf /var/log/taos/确保数据已经不再需要的前提下,删除数据文件,执行 sudo rm -rf /var/lib/taos/
注:
提前做好数据导出,备份!!!
4、安装目录说明
TDengine Database成功安装后,主安装目录是/usr/local/taos,目录内容如下:
[root@xx TDengine-server-3.0.1.1]# cd /usr/local/taos
[root@xx taos]# ll
total 0
drwxr-xr-x. 2 root root 269 Sep 21 12:15 bin
drwxr-xr-x. 2 root root 46 Sep 21 12:15 cfg
lrwxrwxrwx. 1 root root 13 Sep 21 12:15 data -> /var/lib/taos
drwxr-xr-x. 2 root root 51 Sep 21 12:15 driver
drwxr-xr-x. 11 root root 124 Sep 21 12:15 examples
drwxr-xr-x. 2 root root 73 Sep 21 12:15 include
lrwxrwxrwx. 1 root root 13 Sep 21 12:15 log -> /var/log/taos
自动生成配置文件目录、数据库目录、日志目录。 配置文件缺省目录:/etc/taos/taos.cfg, 软链接到/usr/local/taos/cfg/taos.cfg; 数据库缺省目录:/var/lib/taos, 软链接到/usr/local/taos/data; 日志缺省目录:/var/log/taos, 软链接到/usr/local/taos/log; /usr/local/taos/bin目录下的可执行文件,会软链接到/usr/bin目录下; /usr/local/taos/driver目录下的动态库文件,会软链接到/usr/lib目录下; /usr/local/taos/include目录下的头文件,会软链接到到/usr/include目录下;
5、卸载和更新文件说明
卸载安装包的时候,将保留配置文件、数据库文件和日志文件,即 /etc/taos/taos.cfg 、 /var/lib/taos 、 /var/log/taos 。如果用户确认后不需保留,可以手工删除,但一定要慎重,因为删除后,数据将永久丢失,不可以恢复!
如果是更新安装,当缺省配置文件( /etc/taos/taos.cfg )存在时,仍然使用已有的配置文件,安装包中携带的配置文件修改为taos.cfg.org保存在 /usr/local/taos/cfg/ 目录,可以作为设置配置参数的参考样例;如果不存在配置文件,就使用安装包中自带的配置文件
6、卸载
TDengine多种安装包的安装和卸载 - TDengine | 涛思数据
[root@ss TDengine-server-2.4.0.5]# rmtaos
TDengine is removed successfully!
二、客户端
下载安装包:所有下载链接 - TDengine | 涛思数据
博主下载的 2.4.0.5版本
注:
客户端与服务端版本号要完全一致,不然会客户端连接时会出现错误“Unable to establish connection”
参考下文
文档 - 涛思数据 | TDengine
常见问题及反馈 | TDengine 文档 | 涛思数据
4. 遇到错误“Unable to establish connection” 怎么办?
客户端遇到连接故障,请按照下面的步骤进行检查:
检查网络环境
云服务器:检查云服务器的安全组是否打开 TCP/UDP 端口 6030/6041 的访问权限本地虚拟机:检查网络能否 ping 通,尽量避免使用localhost 作为 hostname公司服务器:如果为 NAT 网络环境,请务必检查服务器能否将消息返回值客户端
确保客户端与服务端版本号是完全一致的,开源社区版和企业版也不能混用
在服务器,执行 systemctl status taosd 检查taosd运行状态。如果没有运行,启动taosd
确认客户端连接时指定了正确的服务器 FQDN (Fully Qualified Domain Name —— 可在服务器上执行 Linux 命令 hostname -f 获得),FQDN 配置参考:一篇文章说清楚 TDengine 的 FQDN。
ping 服务器 FQDN,如果没有反应,请检查你的网络,DNS 设置,或客户端所在计算机的系统 hosts 文件。如果部署的是 TDengine 集群,客户端需要能 ping 通所有集群节点的 FQDN。
检查防火墙设置(Ubuntu 使用 ufw status,CentOS 使用 firewall-cmd --list-port),确保集群中所有主机在端口 6030/6041 上的 TCP/UDP 协议能够互通。
对于 Linux 上的 JDBC(ODBC, Python, Go 等接口类似)连接, 确保libtaos.so在目录/usr/local/taos/driver里, 并且/usr/local/taos/driver在系统库函数搜索路径LD_LIBRARY_PATH里
对于 Windows 上的 JDBC, ODBC, Python, Go 等连接,确保C:\TDengine\driver\taos.dll在你的系统库函数搜索目录里 (建议taos.dll放在目录 C:\Windows\System32)
如果仍不能排除连接故障
Linux 系统请使用命令行工具 nc 来分别判断指定端口的 TCP 和 UDP 连接是否通畅 检查 UDP 端口连接是否工作:nc -vuz {hostIP} {port} 检查服务器侧 TCP 端口连接是否工作:nc -l {port} 检查客户端侧 TCP 端口连接是否工作:nc {hostIP} {port}
Windows 系统请使用 PowerShell 命令 Test-NetConnection -ComputerName {fqdn} -Port {port} 检测服务段端口是否访问
也可以使用 taos 程序内嵌的网络连通检测功能,来验证服务器和客户端之间指定的端口连接是否通畅:诊断及其他。
1、Windows使用taos客户端
在cmd.exe中,切换到C:\TDengine目录,执行taos.exe连接数据库
通过其他主机的客户端访问TDengine,则需要指定主机名:taos -h ip/hostname
如下:
taos -h 192.168.22.16
或者
// myhostname 指Linux系统上的主机名
taos -h myhostname
在通过taos连接时,并没有指定用户名与密码;TDengine在用户未指定认证信息时,默认为root, taosdata
连接成功
2、设置FQDN
FQDN(fully qualified domain name,完全限定域名)是internet上特定计算机或主机的完整域名。FQDN由两部分组成:主机名和域名。例如,假设邮件服务器的FQDN可能是mail.taosdata.com。主机名是mail,主机位于域名taosdata.com中。
DNS(Domain Name System),负责将FQDN翻译成IP,是互联网绝大多数应用的寻址方式
文档:一篇文章说清楚TDengine的FQDN - TDengine | 涛思数据
Windows系统
由于Windows暂时只支持部署客户端,所以我们只需要配置FQDN的解析即可
以Win10为例,大家需要修改 C:\Windows\System32\drivers\etc 目录下的hosts文件
10.211.55.14 node1
10.211.55.15 node2
10.211.55.16 node3
Linux系统
以node1节点为例,我们需要修改/etc/hostname和/etc/hosts
修改/etc/hostname,修改完成后需要重启才能生效
修改/etc/hosts
vi /etc/hostname
//将文件内容修改为node1
vi /etc/hosts
//添加一下三行
10.211.55.14 node1
10.211.55.15 node2
10.211.55.16 node3
成功提示和Windows上正常pingy一样;失败则提示:
//windows下
C:\Users\pc-01>ping node1
Ping 请求找不到主机 node1。请检查该名称,然后重试。
//Linux下
root@node2:~# ping node1
ping: unknown host node1
3、开放端口
开放 TCP/UDP 端口 6030-6042 的访问权限
可参考:Linux-CentOS开通端口外网访问权限
4、还有遇到客户端和服务端时间不一致导致连接不上的问题
修改时区配置文件
#删除当前默认时区的配置文件,不建议直接删除(出于操作安全考虑),最好是使用mv命令重命名
rm -rf /etc/localtime
#建立软连接文件到配置文件区,替换掉之前删掉或备份的/etc/localtime 文件
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
timedatectl #查看当前时区
#设置当前时区为上海常用:Asia/Hong_Kong
timedatectl set-timezone Asia/Shanghai
同步时间
#安装时间同步应用
yum install -y ntp
#同步上海授时中心时间
ntpdate ntp.api.bz
三、SQL语句
文档:TAOS SQL | TDengine 文档
1、数据库,超级表,表
2、表名合法性
文档 - 涛思数据 | TDengine
TDengine 中的表(列)名命名规则如下: 只能由字母、数字、下划线构成,数字不能在首位,长度不能超过192字节,不区分大小写。这里表名称不包括数据库名的前缀和分隔符
3、表管理
文档 - 涛思数据 | TDengine
表的第一个字段必须是 TIMESTAMP,并且系统自动将其设为主键
4、Taos shell 中 binary 和 nchar 字段的显示宽度上限
文档 - 涛思数据 | TDengine
在 shell 中通过命令 set max_binary_display_width nn 动态修改此选项
set max_binary_display_width 50;
四、连接Java
文档:TDengine Java Connector | TDengine 文档
taos-jdbcdriver 是 TDengine 的官方 Java 语言连接器,Java 开发人员可以通过它开发存取 TDengine 数据库的应用软件。taos-jdbcdriver 实现了 JDBC driver 标准的接口,并提供两种形式的连接器。一种是通过 TDengine 客户端驱动程序(taosc)原生连接 TDengine 实例
taos-jdbcdriver的jar包 maven仓库地址
https://mvnrepository.com/artifact/com.taosdata.jdbc/taos-jdbcdriver
Maven 项目中,在 pom.xml 中添加以下依赖:
public Connection getConn() throws Exception{
Class.forName("com.taosdata.jdbc.TSDBDriver");
String jdbcUrl = "jdbc:TAOS://taosdemo.com:6030/test?user=root&password=taosdata";
Properties connProps = new Properties();
connProps.setProperty(TSDBDriver.PROPERTY_KEY_CHARSET, "UTF-8");
connProps.setProperty(TSDBDriver.PROPERTY_KEY_LOCALE, "en_US.UTF-8");
connProps.setProperty(TSDBDriver.PROPERTY_KEY_TIME_ZONE, "UTC-8");
connProps.setProperty("debugFlag", "135");
connProps.setProperty("maxSQLLength", "1048576");
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
return conn;
}
public Connection getRestConn() throws Exception{
Class.forName("com.taosdata.jdbc.rs.RestfulDriver");
String jdbcUrl = "jdbc:TAOS-RS://taosdemo.com:6041/test?user=root&password=taosdata";
Properties connProps = new Properties();
connProps.setProperty(TSDBDriver.PROPERTY_KEY_BATCH_LOAD, "true");
Connection conn = DriverManager.getConnection(jdbcUrl, connProps);
return conn;
}
与连接池使用
HikariCP
使用示例如下:
public static void main(String[] args) throws SQLException {
HikariConfig config = new HikariConfig();
// jdbc properties
config.setJdbcUrl("jdbc:TAOS://127.0.0.1:6030/log");
config.setUsername("root");
config.setPassword("taosdata");
// connection pool configurations
config.setMinimumIdle(10); //minimum number of idle connection
config.setMaximumPoolSize(10); //maximum number of connection in the pool
config.setConnectionTimeout(30000); //maximum wait milliseconds for get connection from pool
config.setMaxLifetime(0); // maximum life time for each connection
config.setIdleTimeout(0); // max idle time for recycle idle connection
config.setConnectionTestQuery("select server_status()"); //validation query
HikariDataSource ds = new HikariDataSource(config); //create datasource
Connection connection = ds.getConnection(); // get connection
Statement statement = connection.createStatement(); // get statement
//query or insert
// ...
connection.close(); // put back to conneciton pool
}
Druid
使用示例如下:
public static void main(String[] args) throws Exception {
DruidDataSource dataSource = new DruidDataSource();
// jdbc properties
dataSource.setDriverClassName("com.taosdata.jdbc.TSDBDriver");
dataSource.setUrl(url);
dataSource.setUsername("root");
dataSource.setPassword("taosdata");
// pool configurations
dataSource.setInitialSize(10);
dataSource.setMinIdle(10);
dataSource.setMaxActive(10);
dataSource.setMaxWait(30000);
dataSource.setValidationQuery("select server_status()");
Connection connection = dataSource.getConnection(); // get connection
Statement statement = connection.createStatement(); // get statement
//query or insert
// ...
connection.close(); // put back to conneciton pool
}
五、数据导入、导出
1、导出
数据导出 | TDengine 文档 | 涛思数据
select * from
保存在安装路径下
select * from energy_ab.report_five_minutes_report_record >> data_ab.csv;
2、导入
数据导入 | TDengine 文档 | 涛思数据
taos> insert into d1001 file '~/data.csv';
Query OK, 9 row(s) affected (0.004763s)
六、容量,备份
1、容量
容量规划 | TDengine 文档 | 涛思数据
每个 Database 可以创建固定数目的 vgroup,默认与 CPU 核数相同,可通过 maxVgroupsPerDb 配置;vgroup 中的每个副本会是一个 vnode;每个 vnode 会占用固定大小的内存(大小与数据库的配置参数 blocks 和 cache 有关);每个 Table 会占用与标签总长度有关的内存;此外,系统会有一些固定的内存开销。因此,每个 DB 需要的系统内存可通过如下公式计算:
Database Memory Size = maxVgroupsPerDb * replica * (blocks * cache + 10MB) + numOfTables * (tagSizePerTable + 0.5KB)
示例:假设 maxVgroupPerDB 是缺省值 64,cache 是缺省大小 16M, blocks 是缺省值 6,并且一个 DB 中有 10 万张表,单副本,标签总长度是 256 字节,则这个 DB 总的内存需求为:64 * 1 * (16 * 6 + 10) + 100000 * (0.25 + 0.5) / 1000 = 6792M。
taosd 内存总量 = vnode 内存 + mnode 内存 + 查询内存
(1)“vnode 内存”指的是集群中所有的 Database 存储分摊到当前 taosd 节点上所占用的内存资源。可以按上文“Database Memory Size”计算公式估算每个 DB 的内存占用量进行加总,再按集群中总共的 TDengine 节点数做平均(如果设置为多副本,则还需要乘以对应的副本倍数)。
(2)“mnode 内存”指的是集群中管理节点所占用的资源。如果一个 taosd 节点上分布有 mnode 管理节点,则内存消耗还需要增加“0.2KB * 集群中数据表总数”。
(3)“查询内存”指的是服务端处理查询请求时所需要占用的内存。单条查询语句至少会占用“0.2KB * 查询涉及的数据表总数”的内存量。
2、备份
taosdump 是一个支持从运行中的 TDengine 集群备份数据并将备份的数据恢复到相同或另一个运行中的 TDengine 集群中的工具应用程序。
taosdump 可以用数据库、超级表或普通表作为逻辑数据单元进行备份,也可以对数据库、超级 表和普通表中指定时间段内的数据记录进行备份。使用时可以指定数据备份的目录路径,如果 不指定位置,taosdump 默认会将数据备份到当前目录
TDengine 备份与恢复_DBA大董的博客-CSDN博客
taosdump | TDengine 文档 | 涛思数据
备份所有数据库:指定 -A 或 --all-databases 参数
备份多个指定数据库:使用 -D db1,db2,... 参数;
备份指定数据库中的某些超级表或普通表:使用 dbname stbname1 stbname2 tbname1 tbname2 ... 参数,注意这种输入序列第一个参数为数据库名称,且只支持一个数据库,第二个和之后的参数为该数据库中的超级表或普通表名称,中间以空格分隔;
Usage: taosdump [OPTION...] dbname [tbname ...]or: taosdump [OPTION...] --databases db1,db2,...or: taosdump [OPTION...] --all-databasesor: taosdump [OPTION...] -i inpathor: taosdump [OPTION...] -o outpath-h, --host=HOST Server host dumping data from. Default islocalhost.-p, --password User password to connect to server. Default istaosdata.-P, --port=PORT Port to connect-u, --user=USER User name used to connect to server. Default isroot.-c, --config-dir=CONFIG_DIR Configure directory. Default is /etc/taos-i, --inpath=INPATH Input file path.-o, --outpath=OUTPATH Output file path.-r, --resultFile=RESULTFILE DumpOut/In Result file path and name.-a, --allow-sys Allow to dump system database-A, --all-databases Dump all databases.-D, --databases=DATABASES Dump inputted databases. Use comma to separatedatabases' name.-N, --without-property Dump database without its properties.-s, --schemaonly Only dump tables' schema.-y, --answer-yes Input yes for prompt. It will skip data filechecking!-d, --avro-codec=snappy Choose an avro codec among null, deflate, snappy,and lzma.-S, --start-time=START_TIME Start time to dump. Either epoch orISO8601/RFC3339 format is acceptable. ISO8601format example: 2017-10-01T00:00:00.000+0800 or2017-10-0100:00:00:000+0800 or '2017-10-0100:00:00.000+0800'-E, --end-time=END_TIME End time to dump. Either epoch or ISO8601/RFC3339format is acceptable. ISO8601 format example:2017-10-01T00:00:00.000+0800 or2017-10-0100:00:00.000+0800 or '2017-10-0100:00:00.000+0800'-B, --data-batch=DATA_BATCH Number of data per query/insert statement whenbackup/restore. Default value is 16384. If you see'error actual dump .. batch ..' when backup or ifyou see 'WAL size exceeds limit' error whenrestore, please adjust the value to a smaller oneand try. The workable value is related to thelength of the row and type of table schema.-I, --inspect inspect avro file content and print on screen-L, --loose-mode Using loose mode if the table name and column nameuse letter and number only. Default is NOT.-n, --no-escape No escape char '`'. Default is using it.-T, --thread-num=THREAD_NUM Number of thread for dump in file. Default is5.-g, --debug Print debug info.-?, --help Give this help list--usage Give a short usage message-V, --version Print program versionMandatory or optional arguments to long options are also mandatory or optionalfor any corresponding short options.Report bugs to
在 taosTools安装路径下 创建一个文件夹 dumpdata
备份,执行命令
/usr/localhost/taos/taosTools-1.4.3/bin/./taosdump -A
看到如下文件
恢复备份
/usr/localhost/taos/taosTools-1.4.3/bin/./taosdump -i /usr/localhost/taos/taosTools-1.4.3/dumpdata/
七、踩坑
常见问题及反馈
文档 - 涛思数据 | TDengine
github上有一个taos数据库常见问题的汇总
https://github.com/taosdata/tdengine/issues?q=
TDengine/src/connector/jdbc at master · taosdata/TDengine · GitHub
JDBC连接器可能报错的错误码包括3种:JDBC driver本身的报错(错误码在0x2301到0x2350之间),JNI方法的报错(错误码在0x2351到0x2400之间),TDengine其他功能模块的报错。 具体的错误码请参考:
https://github.com/taosdata/TDengine/blob/develop/src/connector/jdbc/src/main/java/com/taosdata/jdbc/TSDBErrorNumbers.java
https://github.com/taosdata/TDengine/blob/develop/src/inc/taoserror.h
1、systemctl start taosd 失败
升级涛思2.4.X版本至3.0.X,启动涛思服务报错
[root@XX TDengine-server-3.0.1.1]# systemctl status taosd
● taosd.service - TDengine server service
Loaded: loaded (/etc/systemd/system/taosd.service; enabled; vendor preset: disabled)
Active: failed (Result: start-limit) since Wed 2022-09-21 12:16:31 CST; 45min ago
Process: 105841 ExecStart=/usr/bin/taosd (code=exited, status=255)
Process: 105834 ExecStartPre=/usr/local/taos/bin/startPre.sh (code=exited, status=0/SUCCESS)
Main PID: 105841 (code=exited, status=255)
Sep 21 12:16:30 ht-energy systemd[1]: Unit taosd.service entered failed state.
Sep 21 12:16:30 ht-energy systemd[1]: taosd.service failed.
Sep 21 12:16:31 ht-energy systemd[1]: taosd.service holdoff time over, scheduling restart.
Sep 21 12:16:31 ht-energy systemd[1]: Stopped TDengine server service.
Sep 21 12:16:31 ht-energy systemd[1]: start request repeated too quickly for taosd.service
Sep 21 12:16:31 ht-energy systemd[1]: Failed to start TDengine server service.
Sep 21 12:16:31 ht-energy systemd[1]: Unit taosd.service entered failed state.
Sep 21 12:16:31 ht-energy systemd[1]: taosd.service failed.
执行/usr/bin/taosd 直接会给出具体错误如下
[root@ht-energy TDengine-server-3.0.1.1]# /usr/bin/taosd
read /etc/localtime error, reason:Invalid argumentThere is not /etc/timezone.
09/21 13:02:28.688021 00108335 UTL fail to load apoll url
09/21 13:02:28.688104 00108335 UTL load from cfg file /etc/taos/taos.cfg success
09/21 13:02:28.688112 00108335 UTL failed to load env file: .env
09/21 13:02:28.688123 00108335 UTL load from env variables cfg success
09/21 13:02:28.688620 00108335 UTL fail to load apoll url
09/21 13:02:28.688685 00108335 UTL load from cfg file /etc/taos/taos.cfg success
09/21 13:02:28.688696 00108335 UTL failed to load env file: .env
09/21 13:02:28.688703 00108335 UTL load from env variables cfg success
09/21 13:02:28.688789 00108335 UTL global config
09/21 13:02:28.688794 00108335 UTL =================================================================
09/21 13:02:28.688797 00108335 UTL cfg_file firstEp ht-energy:6030
09/21 13:02:28.688802 00108335 UTL default secondEp ht-energy:6030
09/21 13:02:28.688805 00108335 UTL default fqdn ht-energy
09/21 13:02:28.688809 00108335 UTL default serverPort 6030
09/21 13:02:28.688812 00108335 UTL default tempDir /tmp
09/21 13:02:28.688816 00108335 UTL default minimalTmpDirGB 1.00
09/21 13:02:28.688831 00108335 UTL default shellActivityTimer 3
09/21 13:02:28.688834 00108335 UTL default compressMsgSize -1
09/21 13:02:28.688837 00108335 UTL default compressColData -1
09/21 13:02:28.688840 00108335 UTL default queryPolicy 1
09/21 13:02:28.688844 00108335 UTL default querySmaOptimize 0
09/21 13:02:28.688847 00108335 UTL default queryPlannerTrace 0
09/21 13:02:28.688850 00108335 UTL default smlChildTableName
09/21 13:02:28.688854 00108335 UTL default smlTagName _tag_null
09/21 13:02:28.688857 00108335 UTL default smlDataFormat 1
09/21 13:02:28.688861 00108335 UTL default numOfTaskQueueThreads 4
09/21 13:02:28.688864 00108335 UTL default dataDir /var/lib/taos
09/21 13:02:28.688867 00108335 UTL default minimalDataDirGB 2.00
09/21 13:02:28.688871 00108335 UTL default supportVnodes 16
09/21 13:02:28.688874 00108335 UTL default maxShellConns 50000
09/21 13:02:28.688892 00108335 UTL default statusInterval 1
09/21 13:02:28.688897 00108335 UTL default minSlidingTime 10
09/21 13:02:28.688901 00108335 UTL default minIntervalTime 1
09/21 13:02:28.688904 00108335 UTL default maxNumOfDistinctRes 10000000
09/21 13:02:28.688908 00108335 UTL default countAlwaysReturnValue 1
09/21 13:02:28.688911 00108335 UTL default queryBufferSize -1
09/21 13:02:28.688914 00108335 UTL default printAuth 0
09/21 13:02:28.688918 00108335 UTL default multiProcess 0
09/21 13:02:28.688921 00108335 UTL default mnodeShmSize 20972544
09/21 13:02:28.688924 00108335 UTL default vnodeShmSize 104858624
09/21 13:02:28.688928 00108335 UTL default qnodeShmSize 41944064
09/21 13:02:28.688931 00108335 UTL default snodeShmSize 41944064
09/21 13:02:28.688934 00108335 UTL default bnodeShmSize 41944064
09/21 13:02:28.688937 00108335 UTL default numOfShmThreads 1
09/21 13:02:28.688941 00108335 UTL default numOfRpcThreads 4
09/21 13:02:28.688944 00108335 UTL default numOfCommitThreads 4
09/21 13:02:28.688947 00108335 UTL default numOfMnodeReadThreads 1
09/21 13:02:28.688950 00108335 UTL default numOfVnodeQueryThreads 16
09/21 13:02:28.688954 00108335 UTL default numOfVnodeStreamThreads 4
09/21 13:02:28.688957 00108335 UTL default numOfVnodeFetchThreads 4
09/21 13:02:28.688960 00108335 UTL default numOfVnodeWriteThreads 8
09/21 13:02:28.688964 00108335 UTL default numOfVnodeSyncThreads 16
09/21 13:02:28.688967 00108335 UTL default numOfVnodeRsmaThreads 8
09/21 13:02:28.688970 00108335 UTL default numOfQnodeQueryThreads 16
09/21 13:02:28.688973 00108335 UTL default numOfSnodeSharedThreads 2
09/21 13:02:28.688976 00108335 UTL default numOfSnodeUniqueThreads 2
09/21 13:02:28.688980 00108335 UTL default rpcQueueMemoryAllowed 3353018777
09/21 13:02:28.688985 00108335 UTL default monitor 1
09/21 13:02:28.688988 00108335 UTL default monitorInterval 30
09/21 13:02:28.688992 00108335 UTL default monitorFqdn
09/21 13:02:28.688995 00108335 UTL default monitorPort 6043
09/21 13:02:28.688998 00108335 UTL default monitorMaxLogs 100
09/21 13:02:28.689001 00108335 UTL default monitorComp 0
09/21 13:02:28.689005 00108335 UTL default telemetryReporting 1
09/21 13:02:28.689008 00108335 UTL default telemetryInterval 43200
09/21 13:02:28.689011 00108335 UTL default telemetryServer telemetry.taosdata.com
09/21 13:02:28.689015 00108335 UTL default telemetryPort 80
09/21 13:02:28.689018 00108335 UTL default transPullupInterval 2
09/21 13:02:28.689021 00108335 UTL default mqRebalanceInterval 2
09/21 13:02:28.689025 00108335 UTL default ttlUnit 86400
09/21 13:02:28.689028 00108335 UTL default ttlPushInterval 86400
09/21 13:02:28.689031 00108335 UTL default uptimeInterval 300
09/21 13:02:28.689034 00108335 UTL default udf 1
09/21 13:02:28.689038 00108335 UTL default configDir /etc/taos
09/21 13:02:28.689041 00108335 UTL default scriptDir /etc/taos
09/21 13:02:28.689044 00108335 UTL default logDir /var/log/taos
09/21 13:02:28.689048 00108335 UTL default minimalLogDirGB 1.00
09/21 13:02:28.689051 00108335 UTL default numOfLogLines 10000000
09/21 13:02:28.689055 00108335 UTL default asyncLog 1
09/21 13:02:28.689058 00108335 UTL default logKeepDays 0
09/21 13:02:28.689061 00108335 UTL default debugFlag 0
09/21 13:02:28.689065 00108335 UTL default simDebugFlag 143
09/21 13:02:28.689068 00108335 UTL default tmrDebugFlag 131
09/21 13:02:28.689071 00108335 UTL default uDebugFlag 131
09/21 13:02:28.689075 00108335 UTL default rpcDebugFlag 131
09/21 13:02:28.689078 00108335 UTL default jniDebugFlag 131
09/21 13:02:28.689081 00108335 UTL default qDebugFlag 131
09/21 13:02:28.689084 00108335 UTL default cDebugFlag 131
09/21 13:02:28.689087 00108335 UTL default dDebugFlag 135
09/21 13:02:28.689090 00108335 UTL default vDebugFlag 135
09/21 13:02:28.689113 00108335 UTL default mDebugFlag 135
09/21 13:02:28.689117 00108335 UTL default wDebugFlag 135
09/21 13:02:28.689120 00108335 UTL default sDebugFlag 135
09/21 13:02:28.689123 00108335 UTL default tsdbDebugFlag 131
09/21 13:02:28.689126 00108335 UTL default tqDebugFlag 135
09/21 13:02:28.689129 00108335 UTL default fsDebugFlag 135
09/21 13:02:28.689132 00108335 UTL default udfDebugFlag 135
09/21 13:02:28.689135 00108335 UTL default smaDebugFlag 131
09/21 13:02:28.689138 00108335 UTL default idxDebugFlag 135
09/21 13:02:28.689141 00108335 UTL default tdbDebugFlag 131
09/21 13:02:28.689144 00108335 UTL default metaDebugFlag 135
09/21 13:02:28.689147 00108335 UTL default timezone
09/21 13:02:28.689150 00108335 UTL default locale en_US.UTF-8
09/21 13:02:28.689154 00108335 UTL default charset UTF-8
09/21 13:02:28.689157 00108335 UTL default enableCoreFile 1
09/21 13:02:28.689160 00108335 UTL default numOfCores 8.00
09/21 13:02:28.689164 00108335 UTL default openMax 1024
09/21 13:02:28.689167 00108335 UTL default streamMax 16
09/21 13:02:28.689170 00108335 UTL default pageSizeKB 4
09/21 13:02:28.689173 00108335 UTL default totalMemoryKB 32744324
09/21 13:02:28.689179 00108335 UTL default os sysname Linux
09/21 13:02:28.689183 00108335 UTL default os nodename hostname
09/21 13:02:28.689186 00108335 UTL default os release 3.10.0-1160.el7.x86_64
09/21 13:02:28.689189 00108335 UTL default os version #1 SMP Mon Oct 19 16:18:59 UTC 2020
09/21 13:02:28.689192 00108335 UTL default os machine x86_64
09/21 13:02:28.689196 00108335 UTL default version 3.0.1.1
09/21 13:02:28.689199 00108335 UTL default compatible_version 3.0.0.0
09/21 13:02:28.689202 00108335 UTL default gitinfo e6bb4c1aead0e3f156b13d4536fd9966373c194b
09/21 13:02:28.689205 00108335 UTL default buildinfo Built at 2022-09-15 21:48
09/21 13:02:28.689208 00108335 UTL =================================================================
09/21 13:02:28.691051 00108335 DND start to init dnode env
09/21 13:02:28.691073 00108335 DND ERROR The default data directory /var/lib/taos contains old data of tdengine 2.x, please clear it before running!
09/21 13:02:28.691251 00108335 DND ERROR failed to init dnode since Config not found
确保数据已经不再需要(或者已经导出,备份好)的前提下
删除数据文件,执行 sudo rm -rf /var/lib/taos/
注:
提前做好数据导出,备份!!!
2、taos驱动
java.lang.NoClassDefFoundError: Could not initialize class com.taosdata.jdbc.TSDBJNIConnector
3、java.lang.UnsatisfiedLinkError: no taos in java.library.path
java.lang.UnsatisfiedLinkError: no taos in java.library.path
java.lang.NoClassDefFoundError: Could not initialize class com.taosdata.jdbc.TSDBJNIConnector · Issue #4238 · taosdata/TDengine · GitHub
https://github.com/taosdata/TDengine/issues/8235
4、java.sql.SQLException: JNI ERROR(2354): Ref is not there
实质就是 JNI connection is NULL
public static final int ERROR_JNI_CONNECTION_NULL = 0x2354; // JNI connection is NULL
12:47:02.779 [threadPoolTaskExecutor-11] INFO c.e.c.taos.TaosUtils - [instance,89] - 驱动 = com.taosdata.jdbc.TSDBDriver url = jdbc:TAOS://zm-dev:6030/tent_test_1?timezone=UTC-8&charset=UTF-8&locale=en_US.UTF-8
Taos get connection starting...
java.sql.SQLException: JNI ERROR (2354): Ref is not there
at com.taosdata.jdbc.TSDBError.createSQLException(TSDBError.java:75)
at com.taosdata.jdbc.TSDBJNIConnector.connect(TSDBJNIConnector.java:80)
at com.taosdata.jdbc.TSDBConnection.connect(TSDBConnection.java:35)
at com.taosdata.jdbc.TSDBConnection.
at com.taosdata.jdbc.TSDBDriver.connect(TSDBDriver.java:133)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:208)
at com.energy.common.taos.TaosUtils.instance(TaosUtils.java:99)
at com.energy.common.taos.TaosUtils.insertIntoBatchResult(TaosUtils.java:186)
at com.energy.jobTask.fiveMinutesTask.FiveMinutesTask.job(FiveMinutesTask.java:211)
at com.energy.startUp.InvokeJobTaskMethodsByPojo.doTask(InvokeJobTaskMethodsByPojo.java:82)
at com.energy.startUp.EnergyTaskStartUp$1$1.run(EnergyTaskStartUp.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
at com.energy.common.taos.TaosUtils.insertIntoBatchResult(TaosUtils.java:189)
at com.energy.jobTask.fiveMinutesTask.FiveMinutesTask.job(FiveMinutesTask.java:211)
at com.energy.startUp.InvokeJobTaskMethodsByPojo.doTask(InvokeJobTaskMethodsByPojo.java:82)
at com.energy.startUp.EnergyTaskStartUp$1$1.run(EnergyTaskStartUp.java:75)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
其实博主的问题都是同一个就是libtaos.so找不到
linux 下需要建立如下软链 ln -s /usr/local/taos/driver/libtaos.so.x.x.x.x /usr/lib/libtaos.so 即可
cd /usr/lib
ln -s libtaos.so.1 libtaos.so.3.0.1.1
1、博主将 2.4.0.14版本下taos安装目录下 /xx/taos/TDengine-server-2.4.0.14/driver/ 下的 的 libtaos.so.2.4.0.14 改名为 libtaos.so,并且 拷贝到 服务jar 包同目录下,如下
2、构建Dockerfile如下
/usr/lib不在 java的PATH中, 测试下将libtaos.so放在/usr/bin目录下
主要代码 : ADD libtaos.so /usr/lib
FROM java:8
MAINTAINER zm
EXPOSE 8104
ADD energy-task.jar energy-task.jar
ADD libtaos.so /usr/lib
# Dockerfile
RUN echo 'Asia/Shanghai' >/etc/timezone
ENTRYPOINT ["java","-jar","energy-task.jar"]
3、博主运行项目 jar包时,需要映射 hostname
-v /etc/hosts:/etc/hosts -v /etc/hostname:/etc/hostname
完整如下:
#!/bin/sh
cd /data1/docker/server/energy/energy-task
docker rm -f energy-task
docker rmi energy-task:latest
# 根据Dockerfile文件 构建镜像;"."代表当前目录,-t参数设置标签;使用当前目录的Dockerfile文件创建镜像并设置标签
docker build -t energy-task .
docker run -d -p 8104:8081 -e "SPRING_PROFILES_ACTIVE=test"
-v /etc/localtime:/etc/localtime -v /data1/logs/energy-task:/logs
-v /data1/files/energy-task:/files
-v /etc/hosts:/etc/hosts -v /etc/hostname:/etc/hostname
--restart=always --privileged=true --name energy-task energy-task:latest