TDengine in docker

prepare

prepare base image

1
docker image pull centos

prepare source code

1
2
git clone git@github.com:taosdata/TDengine.git
cd TDengine

or download release version package and unpackage

prepare Dockerfile file

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# Compile image
FROM centos as compile

WORKDIR /root

COPY src/ ./src/
COPY deps/ ./deps/
COPY packaging/ ./packaging/
COPY CMakeLists.txt ./

RUN yum update -y

RUN yum group install -y "Development Tools"

Run yum install -y cmake

WORKDIR /root/build
RUN cmake .. && cmake --build .

CMD ["bash"]

# Final image
FROM centos

WORKDIR /root

COPY --from=compile /root/build/build/bin /usr/bin/
COPY --from=compile /root/build/build/lib/libtaos.so /usr/lib/
COPY packaging/cfg/taos.cfg /etc/taos/

RUN echo "charset UTF-8" >> /etc/taos/taos.cfg

ENV LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/usr/lib"
ENV LC_CTYPE="en_US.UTF-8"

# origin blog missing this
ENV LC_ALL="C"

CMD ["taosd"]

create TDengine image

1
docker build -t tdtest .

start service

create volumn

1
2
docker volume create td_log_vol
docker volume create td_data_vol

start

1
docker run -itd --name tdtest_run -v td_log_vol:/var/log/taos -v td_data_vol:/var/lib/taos tdtest

if service start fail then check logs

1
2
docker ps -a
docker logs -f -t --tail 50 tdtest_run

Error info like this

1
2
3
4
5
2019-10-15T00:51:45.614929519Z TDengine:[1]: Starting TDengine service...
2019-10-15T00:51:45.614966105Z 10/15 00:51:45.614216 7f6a24ce1b80 UTL timezone not configured, set to system default: (UTC, +0000)
2019-10-15T00:51:45.614975483Z 10/15 00:51:45.614410 7f6a24ce1b80 ERROR UTL can't get locale from system
2019-10-15T00:51:45.614981522Z 10/15 00:51:45.614486 7f6a24ce1b80 UTL Invalid locale:, please set the valid locale in config file
2019-10-15T00:51:45.770437005Z Invalid locale:, please set the valid locale in config file

the 1th process is not /sbin/init, so systemctl command can’t execute.
for fix this need option --privileged=true and parameter /sbin/init, it’s not right.

1
docker run -itd --name tdtest_run --privileged=true -v td_log_vol:/var/log/taos -v td_data_vol:/var/lib/taos tdtest /sbin/init

I met a problem here, the docker process started, but taosd server process start failed.
At first i thought the datetimectl command can fix this, i try to add
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
in Dockerfile and rebuild image but failed.

Then i try to find the source code where the exception be throw.
It’s in TDengine/src/util/src/tglobalcfg.c , the c function setlocale() read location failed.
I write a simple c file, to valid this problem, then search in internet.
Finally, find a similar problem in other software, the answer is very obviously : caused by environment variable.

When add the variable export LC_ALL=C, the client part taos can start up, the demo c file can printf locale normally.
So, add ENV LC_ALL="C" in Dockerfile and rebuild image, start the container taosd successfully.

1
docker run -itd --name tdtest_run -v td_log_vol:/var/log/taos -v td_data_vol:/var/lib/taos tdtest

https://blog.csdn.net/weixin_34038652/article/details/86236240
http://c.biancheng.net/ref/setlocale.html
https://www.runoob.com/cprogramming/c-function-setlocale.html

check

1
2
3
4
# visit container
docker exec -it tdtest_run /bin/bash
# start tdengine client
taos

Experiment

code prepare

1
2
3
4
5
docker cp test.tar.gz tdtest_run:/root
docker exec -it tdtest_run bash
cd /root
tar -zxvf test.tar.gz
cd test

test.tar.gz

insert

modify config/config.sh, modify table num, table record num

1
./test.sh -F config/config.sh -f config/tdengine.sh

result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
You are testing TDengine...
TEST INFORMATION
======================================
Databse : TDENGINE
Action : Insert
Schema file : /root/test/data/schema.txt
Sample file : /root/test/data/sample.txt
Insert thread : 10
Detectors : 10000
Records per detector : 10000
Start time : 01/01/2015 00:00:00
Time interval : 900000

Config dir : /etc/taos/
Host :
User name : root
Password : taosdata
DB name : meterInfo
Table prefix : meter
STable : meters
DB property : days 30 tblocks 500 tables 5000
Records per request : 200
Insert mode : 0
Real situation : 0
======================================
Starting to test...
days 30 tblocks 500 tables 5000
Creating 10000 tables......
TDengine tables are created. Sleep 2 seconds and starting to insert data...

Inserting data......
ThreadID: 0 start table ID: 0 end table ID: 999
ThreadID: 1 start table ID: 1000 end table ID: 1999
ThreadID: 2 start table ID: 2000 end table ID: 2999
ThreadID: 3 start table ID: 3000 end table ID: 3999
ThreadID: 4 start table ID: 4000 end table ID: 4999
ThreadID: 5 start table ID: 5000 end table ID: 5999
ThreadID: 6 start table ID: 6000 end table ID: 6999
ThreadID: 7 start table ID: 7000 end table ID: 7999
ThreadID: 8 start table ID: 8000 end table ID: 8999
ThreadID: 9 start table ID: 9000 end table ID: 9999
Done! Spent 70.6098 seconds to insert 100000000 records, speed: 1416233.89 R/s
Test done!

query

1
2
docker exec -it tdtest_run bash
taos

result:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Welcome to the TDengine shell from linux, client version:1.6.2.2, server version:1.6.2.2
Copyright (c) 2017 by TAOS Data, Inc. All rights reserved.

taos> select count(*) from meterinfo.meters;
count(*) |
======================
100000000|
Query OK, 1 row(s) in set (0.135594s)

taos> select count(*) from meterinfo.meters group by loc;
count(*) | loc |
===============================================================
40000000| |
20000000| |
10000000| |
30000000| |
Query OK, 4 row(s) in set (0.163399s)

parameter

config/config.sh data config

  • SCHEMA_FILE: schema config file, test/data/schema.txt。
  • SAMPLE_FILE: sample data file, need echo each other with schema.txt, test program will loop write in these data.
  • NDETECTORS: table number
  • INSERT_THREAD: thread number
  • RECORDS_PER_DETECTOR: records number in one table
  • START_TIME: start time
  • TIME_INTERVAL: data collect interval, unit in millisecond.

config/tdengine.sh engine config

  • INSERT_DB_NAME: db name
  • TB_PREFIX: table name = prefix + num
  • STABLE: super table name
  • DB_PROPERTY: database option
  • RECORDS_PER_REQUEST: recored num in one insert command, insert limit in 64K

https://github.com/taosdata/TDengine
https://github.com/taosdata/TDengine/blob/v1.6/src/util/src/tglobalcfg.c
https://blog.csdn.net/qishidiguadan/article/details/96284529
https://blog.csdn.net/u013829518/article/details/99681154
https://blog.csdn.net/u012954706/article/details/82588687