物联网数据库 IoTDB —— 从条约到数据
发布时间:2021-06-07 13:30:42 所属栏目:交互 来源:互联网
导读:iotdb in docker 首先,做一个测试环境,我现在越发喜欢docker 和 WSL 了,除了吃点硬盘,内存和CPU资源以外,没有什么缺点了...... run in docker 直接把该开的端口都打开,只是测试环境,我就没再挂目录。 docker run -d -p 6667:6667 -p 31999:31999 -p 8
iotdb in docker
首先,做一个测试环境,我现在越发喜欢docker 和 WSL 了,除了吃点硬盘,内存和CPU资源以外,没有什么缺点了......
run in docker
直接把该开的端口都打开,只是测试环境,我就没再挂目录。
docker run -d -p 6667:6667 -p 31999:31999 -p 8181:8181 -p 5555:5555 -p 1883:1883 apache/iotdb
等待一会,执行 docker ps 查看是否成功了
➜ ~ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ad9b18f8bff3 apache/iotdb "/iotdb/sbin/start-s…" 2 hours ago Up 2 hours 0.0.0.0:1883->1883/tcp, :::1883->1883/tcp, 0.0.0.0:5555->5555/tcp, :::5555->5555/tcp, 0.0.0.0:6667->6667/tcp, :::6667->6667/tcp, 0.0.0.0:8181->8181/tcp, :::
初步的iotdb in docker 环境,我们就搞好了。接下来,开启mqtt服务。
开启 Mqtt 服务
进入iotdb的docker docker exec -it ad9b18f8bff3 /bin/bash
编辑配置文件vi iotdb/conf/iotdb-engine.properties
开启服务,根据自己的需要,配置ip和端口等。
####################
### MQTT Broker Configuration
####################
# whether to enable the mqtt service.
enable_mqtt_service=false # 修改成 true , 代表开启 mqtt服务
# the mqtt service binding host.
mqtt_host=0.0.0.0 # ip
# the mqtt service binding port.
mqtt_port=1883 # 端口
# the handler pool size for handing the mqtt messages.
mqtt_handler_pool_size=1
# the mqtt message payload formatter.
mqtt_payload_formatter=json # 数据格式
# max length of mqtt message in byte
mqtt_max_message_size=1048576
重启服务,如果不会,就重启docker镜像。
iotdb 基础操作
启动服务: sbin/start-client.sh
root@ad9b18f8bff3:/iotdb/sbin# ./start-cli.sh
---------------------
Starting IoTDB Cli
---------------------
_____ _________ ______ ______
|_ _| | _ _ ||_ _ `.|_ _
| | .--.|_/ | | _| | | `. | |_) |
| | / .'` | | | | | | | __'.
_| |_| __. | _| |_ _| |_.' /_| |__) |
|_____|'.__.' |_____| |______.'|_______/ version 0.11.1
IoTDB> login successfully
退出CLI: quit 或 exit
停止服务:$sbin/stop-server.sh
设置一个存储组到IOTDB,名为root : IoTDB> SET STORAGE GROUP TO root
查看当前IOTDB的存储组 : IoTDB> SHOW STORAGE GROUP
IoTDB> SHOW STORAGE GROUP
+-------------+
|storage group|
+-------------+
| root.test|
+-------------+
Total line number = 1
It costs 0.127s
查看系统中存在的所有时间序列 :IoTDB> SHOW TIMESERIES
IoTDB> show timeseries
+-------------------------------+-----+-------------+--------+--------+-----------+----+----------+
| timeseries|alias|storage group|dataType|encoding|compression|tags|attributes|
+-------------------------------+-----+-------------+--------+--------+-----------+----+----------+
|root.test.wf01.wt01.temperature| null| root.test| FLOAT| GORILLA| SNAPPY|null| null|
| root.test.wf01.wt01.status| null| root.test| BOOLEAN| RLE| SNAPPY|null| null|
| root.test.wf01.wt01.hardware| null| root.test| TEXT| PLAIN| SNAPPY|null| null|
+-------------------------------+-----+-------------+--------+--------+-----------+----+----------+
Total line number = 3
It costs 0.009s
查看系统中存在的特定时间序列: SHOW TIMESERIES root.test.wf01.wt01.status
IoTDB> SHOW TIMESERIES root.test.wf01.wt01.status
+--------------------------+-----+-------------+--------+--------+-----------+----+----------+
| timeseries|alias|storage group|dataType|encoding|compression|tags|attributes|
+--------------------------+-----+-------------+--------+--------+-----------+----+----------+
|root.test.wf01.wt01.status| null| root.test| BOOLEAN| RLE| SNAPPY|null| null|
+--------------------------+-----+-------------+--------+--------+-----------+----+----------+
Total line number = 1
It costs 0.003s
插入数据 INSERT INTO root.test.wf01.wt01(timestamp,status,temperature) values(200,false,20.71)
IoTDB> INSERT INTO root.test.wf01.wt01(timestamp,status,temperature) values(200,false,20.71)
Msg: The statement is executed successfully.
查看数据: select * from root.test;
IoTDB> select * from root.test;
+------------------------+-------------------------------+--------------------------+----------------------------+
| Time|root.test.wf01.wt01.temperature|root.test.wf01.wt01.status|root.test.wf01.wt01.hardware|
+------------------------+-------------------------------+--------------------------+----------------------------+
|2021-01-20T02:00:00.000Z| 21.2| true| hello|
+------------------------+-------------------------------+--------------------------+----------------------------+
Total line number = 1
It costs 0.077s
查看设备:show devices
IoTDB> show devices
+-------------------+
| devices|
+-------------------+
|root.test.wf01.wt01|
+-------------------+
Total line number = 1
It costs 0.002s
mqtt to iotdb
代码
(编辑:西双版纳站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |