1 准备环境
1.1 设置主机名
[root@localhost ~]# hostnamectl set-hostname pyrk-taos
[root@localhost ~]# hostname
pyrk-taos
1.2 安装组件
[root@pyrk-taos ~]# yum -y install gcc gcc-c++
[root@pyrk-taos ~]#yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel
[root@pyrk-taos ~]yum -y install wget
1.3 安装PYTHON
1.3.1 下载
https://www.python.org/downloads/source/
[root@pyrk_taos ~]# mkdir /usr/local/python3
[root@pyrk_taos ~]# cd /usr/local/python3/
直接从网站下载或者使用wget下载均可
[root@pyrk_taos python3]# wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz
[root@pyrk_taos python3]# ll
total 22144
-rw-r--r-- 1 root root 22673115 Oct 3 2017 Python-3.6.3.tgz
1.3.2 编译、安装
解压缩
[root@pyrk_taos python3]# tar -xvf Python-3.6.3.tgz
编译、安装
[root@pyrk_taos python3]# cd Python-3.6.3
[root@pyrk_taos Python-3.6.3]# ./configure --prefix=/usr/local/python3
[root@pyrk_taos Python-3.6.3]# make
[root@pyrk_taos Python-3.6.3]# make install
安装目录的BIN命令下有PYTHON3.6和PIP
[root@pyrk_taos Python-3.6.3]# ll /usr/local/python3/bin
total 24744
lrwxrwxrwx 1 root root 8 Sep 7 17:04 2to3 -> 2to3-3.6
-rwxr-xr-x 1 root root 109 Sep 7 17:04 2to3-3.6
-rwxr-xr-x 1 root root 250 Sep 7 17:04 easy_install-3.6
lrwxrwxrwx 1 root root 7 Sep 7 17:04 idle3 -> idle3.6
-rwxr-xr-x 1 root root 107 Sep 7 17:04 idle3.6
-rwxr-xr-x 1 root root 222 Sep 7 17:04 pip3
-rwxr-xr-x 1 root root 222 Sep 7 17:04 pip3.6
lrwxrwxrwx 1 root root 8 Sep 7 17:04 pydoc3 -> pydoc3.6
-rwxr-xr-x 1 root root 92 Sep 7 17:04 pydoc3.6
lrwxrwxrwx 1 root root 9 Sep 7 17:04 python3 -> python3.6
-rwxr-xr-x 2 root root 12650336 Sep 7 17:04 python3.6
lrwxrwxrwx 1 root root 17 Sep 7 17:04 python3.6-config -> python3.6m-config
-rwxr-xr-x 2 root root 12650336 Sep 7 17:04 python3.6m
-rwxr-xr-x 1 root root 3105 Sep 7 17:04 python3.6m-config
lrwxrwxrwx 1 root root 16 Sep 7 17:04 python3-config -> python3.6-config
lrwxrwxrwx 1 root root 10 Sep 7 17:04 pyvenv -> pyvenv-3.6
-rwxr-xr-x 1 root root 449 Sep 7 17:04 pyvenv-3.6
创建连接,此处如果直接连接到PYTHON的话,需要修改一些配置,参考:
http://tjei-tju.club/index.php/2020/07/02/python_install_centos/
[root@pyrk_taos Python-3.6.3]# ln -s /usr/local/python3/bin/python3.6 /usr/bin/python3
[root@pyrk_taos Python-3.6.3]# python -V
Python 2.7.5
[root@pyrk_taos Python-3.6.3]# python3 -V
Python 3.6.3
1.4 安装PIP
python3 中自带有pip3,因此只需要添加pip3的软链接即可
[root@pyrk_taos Python-3.6.3]# ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
[root@pyrk_taos Python-3.6.3]# pip3 -V
pip 9.0.1 from /usr/local/python3/lib/python3.6/site-packages (python 3.6)
2 安装
https://www.taosdata.com/cn/getting-started/
[root@pyrk-taos ~]# ll
total 42324
-rw-------. 1 root root 1259 May 21 01:39 anaconda-ks.cfg
-rw-r--r-- 1 root root 25755357 Sep 7 00:14 Python-3.9.7.tgz
-rw-r--r-- 1 root root 8327463 Sep 6 22:57 TDengine-client-2.0.20.13-Linux-x64.tar.gz
-rw-r--r-- 1 root root 9246235 Sep 6 22:57 TDengine-server-2.0.20.13-Linux-x64.rpm
2.1 安装服务端
2.1.1 安装
[root@pyrk-taos ~]# rpm -ivh TDengine-server-2.0.20.13-Linux-x64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:tdengine-2.0.20.13-3 ################################# [100%]
Start to install TDengine...
Created symlink from /etc/systemd/system/multi-user.target.wants/taosd.service to /etc/systemd/system/taosd.service.
System hostname is: pyrk-taos
Enter FQDN:port (like h1.taosdata.com:6030) of an existing TDengine cluster node to join
OR leave it blank to build one:
Enter your email address for priority support or enter empty to skip:
To configure TDengine : edit /etc/taos/taos.cfg
To start TDengine : sudo systemctl start taosd
To access TDengine : taos -h pyrk-taos to login into TDengine server
TDengine is installed successfully!
2.1.2 重启、自启动
[root@pyrk-taos ~]# systemctl status taosd
● taosd.service - TDengine server service
Loaded: loaded (/etc/systemd/system/taosd.service; enabled; vendor preset: disabled)
Active: inactive (dead)
[root@pyrk-taos ~]# systemctl start taosd
[root@pyrk-taos ~]# systemctl status taosd
● taosd.service - TDengine server service
Loaded: loaded (/etc/systemd/system/taosd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-09-07 00:41:04 CST; 5s ago
Process: 14403 ExecStartPre=/usr/local/taos/bin/startPre.sh (code=exited, status=0/SUCCESS)
Main PID: 14411 (taosd)
CGroup: /system.slice/taosd.service
└─14411 /usr/bin/taosd
Sep 07 00:41:04 pyrk-taos systemd[1]: Starting TDengine server service...
Sep 07 00:41:04 pyrk-taos systemd[1]: Started TDengine server service.
Sep 07 00:41:04 pyrk-taos TDengine:[14411]: Starting TDengine service...
Sep 07 00:41:04 pyrk-taos TDengine:[14411]: Started TDengine service successfully.
2.2 安装连接器
https://www.taosdata.com/cn/documentation/connector
2.2.1 安装驱动
2.2.1.1 执行安装脚本
[root@pyrk-taos ~]# tar -xzvf TDengine-client-2.0.20.13-Linux-x64.tar.gz
[root@pyrk-taos TDengine-client-2.0.20.13]# ll
total 620
drwxrwxr-x 6 1000 1000 104 Aug 16 19:06 connector
drwxrwxr-x 2 1000 1000 34 Aug 16 19:06 driver
drwxrwxr-x 10 1000 1000 98 Aug 16 19:06 examples
-rwxrwxr-x 1 1000 1000 10079 Aug 16 19:06 install_client.sh
-rw-rw-r-- 1 1000 1000 619646 Aug 16 19:06 taos.tar.gz
[root@pyrk-taos TDengine-client-2.0.20.13]# sh install_client.sh
There are already installed TDengine server, so don't need install client!
2.2.1.2 配置
配置主机名
[root@pyrk_taos TDengine-client-2.0.20.13]# vi /etc/taos/taos.cfg
[root@pyrk_taos TDengine-client-2.0.20.13]# cat /etc/taos/taos.cfg
########################################################
# #
# TDengine Configuration #
# Any questions, please email support@taosdata.com #
# #
########################################################
# first fully qualified domain name (FQDN) for TDengine system
firstEp pyrk_taos:6030
# local fully qualified domain name (FQDN)
fqdn pyrk_taos
2.2.2 安装连接器
[root@pyrk_taos TDengine-client-2.0.20.13]# pip3 install /root/TDengine-client-2.0.20.13/connector/python/
注意,当连接器和服务端不在一台服务器上时,需要配置hosts
[root@pyrk_taos_c python]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.0.64 pyrk_taos
3 测试
3.1 测试数据
安装超级测试表,执行这条命令大概需要几分钟,最后共插入 1 亿条记录。
[root@pyrk_taos TDengine-client-2.0.20.13]# taosdemo
taosdemo is simulating data generated by power equipments monitoring...
host: 127.0.0.1:6030
user: root
password: taosdata
configDir:
resultFile: ./output.txt
thread num of insert data: 10
thread num of create table: 10
top insert interval: 0
number of records per req: 30000
max sql length: 1048576
database count: 1
database[0]:
database[0] name: test
drop: yes
replica: 1
precision: ms
super table count: 1
super table[0]:
stbName: meters
autoCreateTable: no
childTblExists: no
childTblCount: 10000
childTblPrefix: d
dataSource: rand
iface: taosc
insertRows: 10000
interlaceRows: 0
disorderRange: 1000
disorderRatio: 0
maxSqlLen: 1048576
timeStampStep: 1
startTimestamp: 2017-07-14 10:40:00.000
sampleFormat:
sampleFile:
tagsFile:
columnCount: 3
column[0]:FLOAT column[1]:INT column[2]:FLOAT
tagCount: 2
tag[0]:INT tag[1]:BINARY(16)
Press enter key to continue or Ctrl-C to stop
create database test success!
Spent 3.4730 seconds to create 10000 tables with 10 thread(s)
thread[1] has currently inserted rows: 3960000, affected rows: 3960000
thread[3] has currently inserted rows: 4020000, affected rows: 4020000
thread[0] has currently inserted rows: 4110000, affected rows: 4110000
thread[2] has currently inserted rows: 3990000, affected rows: 3990000
thread[4] has currently inserted rows: 4000000, affected rows: 4000000
thread[6] has currently inserted rows: 4160000, affected rows: 4160000
thread[9] has currently inserted rows: 4190000, affected rows: 4190000
thread[7] has currently inserted rows: 4180000, affected rows: 4180000
thread[5] has currently inserted rows: 3970000, affected rows: 3970000
thread[8] has currently inserted rows: 4230000, affected rows: 4230000
thread[1] has currently inserted rows: 8390000, affected rows: 8390000
thread[3] has currently inserted rows: 8250000, affected rows: 8250000
thread[0] has currently inserted rows: 8450000, affected rows: 8450000
thread[6] has currently inserted rows: 8360000, affected rows: 8360000
thread[4] has currently inserted rows: 8340000, affected rows: 8340000
thread[9] has currently inserted rows: 8610000, affected rows: 8610000
thread[5] has currently inserted rows: 8220000, affected rows: 8220000
thread[2] has currently inserted rows: 8310000, affected rows: 8310000
thread[7] has currently inserted rows: 8580000, affected rows: 8580000
thread[8] has currently inserted rows: 8590000, affected rows: 8590000
====thread[9] completed total inserted rows: 10000000, total affected rows: 10000000. 154229.77 records/second====
====thread[7] completed total inserted rows: 10000000, total affected rows: 10000000. 153557.38 records/second====
====thread[8] completed total inserted rows: 10000000, total affected rows: 10000000. 152720.12 records/second====
====thread[0] completed total inserted rows: 10000000, total affected rows: 10000000. 152510.76 records/second====
====thread[1] completed total inserted rows: 10000000, total affected rows: 10000000. 150841.90 records/second====
====thread[6] completed total inserted rows: 10000000, total affected rows: 10000000. 150684.99 records/second====
====thread[2] completed total inserted rows: 10000000, total affected rows: 10000000. 150558.56 records/second====
====thread[4] completed total inserted rows: 10000000, total affected rows: 10000000. 150434.65 records/second====
====thread[3] completed total inserted rows: 10000000, total affected rows: 10000000. 150422.04 records/second====
====thread[5] completed total inserted rows: 10000000, total affected rows: 10000000. 150085.13 records/second====
Spent 71.70 seconds to insert rows: 100000000, affected rows: 100000000 with 10 thread(s) into test.meters. 1394700.14 records/second
insert delay, avg: 65.97ms, max: 362.39ms, min: 11.73ms
3.2 命令行:测试
[root@pyrk_taos TDengine-client-2.0.20.13]# taos
Welcome to the TDengine shell from Linux, Client Version:2.0.20.13
Copyright (c) 2020 by TAOS Data, Inc. All rights reserved.
taos> select count(*) from test.meters;
count(*) |
========================
100000000 |
Query OK, 1 row(s) in set (0.267098s)
taos> select avg(current), max(voltage), min(phase) from test.meters;
avg(current) | max(voltage) | min(phase) |
==================================================================
9.981330951 | 224 | 0.31944 |
Query OK, 1 row(s) in set (0.197638s)
taos> select count(*) from test.meters where location="beijing";
count(*) |
========================
50000000 |
Query OK, 1 row(s) in set (0.059210s)
taos> select avg(current), max(voltage), min(phase) from test.meters where groupId=10;
Query OK, 0 row(s) in set (0.001007s)
taos> select avg(current), max(voltage), min(phase) from test.d10 interval(10s);
ts | avg(current) | max(voltage) | min(phase) |
============================================================================================
2017-07-14 10:40:00.000 | 9.981338157 | 224 | 0.31944 |
Query OK, 1 row(s) in set (0.001360s)
3.3 文件
3.3.1 测试文件
[root@pyrk_taos python]# pwd
/root/TDengine-client-2.0.20.13/examples/python
[root@pyrk_taos python]# ll
total 4
drwxrwxr-x 2 1000 1000 30 Aug 16 19:06 PYTHONConnectorChecker
-rw-rw-r-- 1 1000 1000 2454 Aug 16 19:06 read_example.py
drwxrwxr-x 2 1000 1000 66 Aug 16 19:06 taosdemo
3.3.2 PYTHON文件
"""
This is the sample code for TDengine python2 client.
"""
import taos
import sys
import datetime
import random
def exitProgram(conn):
conn.close()
sys.exit()
if __name__ == '__main__':
start_time = datetime.datetime(2019, 7, 1)
time_interval = datetime.timedelta(seconds=60)
# Connect to TDengine server.
#
# parameters:
# @host : TDengine server IP address
# @user : Username used to connect to TDengine server
# @password : Password
# @database : Database to use when connecting to TDengine server
# @config : Configuration directory
if len(sys.argv)>1:
hostname=sys.argv[1]
conn = taos.connect(host=hostname, user="root", password="taosdata", config="/etc/taos")
else:
conn = taos.connect(host="127.0.0.1", user="root", password="taosdata", config="/etc/taos")
# Generate a cursor object to run SQL commands
c1 = conn.cursor()
# Create a database named db
try:
c1.execute('create database if not exists db ')
except Exception as err:
conn.close()
raise(err)
# use database
try:
c1.execute('use db')
except Exception as err:
conn.close()
raise(err)
# create table
try:
c1.execute('create table if not exists t (ts timestamp, a int, b float, c binary(20))')
except Exception as err:
conn.close()
raise(err)
# insert data
for i in range(10):
try:
value = c1.execute("insert into t values ('%s', %d, %f, '%s')" % (start_time, random.randint(1,10), random.randint(1,10)/10.0, 'hello'))
#if insert, value is the affected rows
print(value)
except Exception as err:
conn.close()
raise(err)
start_time += time_interval
# query data and return data in the form of list
try:
c1.execute('select * from db.t')
except Exception as err:
conn.close()
raise(err)
# Column names are in c1.description list
cols = c1.description
# Use fetchall to fetch data in a list
data = c1.fetchall()
for col in data:
print(col)
print('Another query method ')
try:
c1.execute('select * from db.t')
except Exception as err:
conn.close()
raise(err)
# Use iterator to go through the retreived data
for col in c1:
print(col)
conn.close()
3.3.3 执行PYTHON文件
[root@pyrk_taos python]# python3 read_example.py
1
1
1
1
1
1
1
1
1
1
(datetime.datetime(2019, 7, 1, 0, 0), 10, 0.4000000059604645, 'hello')
(datetime.datetime(2019, 7, 1, 0, 1), 7, 0.4000000059604645, 'hello')
(datetime.datetime(2019, 7, 1, 0, 2), 5, 0.5, 'hello')
(datetime.datetime(2019, 7, 1, 0, 3), 9, 0.8999999761581421, 'hello')
(datetime.datetime(2019, 7, 1, 0, 4), 1, 0.10000000149011612, 'hello')
(datetime.datetime(2019, 7, 1, 0, 5), 1, 0.8999999761581421, 'hello')
(datetime.datetime(2019, 7, 1, 0, 6), 8, 0.800000011920929, 'hello')
(datetime.datetime(2019, 7, 1, 0, 7), 10, 0.30000001192092896, 'hello')
(datetime.datetime(2019, 7, 1, 0, 8), 8, 0.800000011920929, 'hello')
(datetime.datetime(2019, 7, 1, 0, 9), 3, 0.5, 'hello')
Another query method
(datetime.datetime(2019, 7, 1, 0, 0), 10, 0.4000000059604645, 'hello')
(datetime.datetime(2019, 7, 1, 0, 1), 7, 0.4000000059604645, 'hello')
(datetime.datetime(2019, 7, 1, 0, 2), 5, 0.5, 'hello')
(datetime.datetime(2019, 7, 1, 0, 3), 9, 0.8999999761581421, 'hello')
(datetime.datetime(2019, 7, 1, 0, 4), 1, 0.10000000149011612, 'hello')
(datetime.datetime(2019, 7, 1, 0, 5), 1, 0.8999999761581421, 'hello')
(datetime.datetime(2019, 7, 1, 0, 6), 8, 0.800000011920929, 'hello')
(datetime.datetime(2019, 7, 1, 0, 7), 10, 0.30000001192092896, 'hello')
(datetime.datetime(2019, 7, 1, 0, 8), 8, 0.800000011920929, 'hello')
(datetime.datetime(2019, 7, 1, 0, 9), 3, 0.5, 'hello')