Using IoTDB from Scratch
IoTDB is a data management engine that integrates collection, storage, and analysis of time series data. It features lightweight, high performance, and ease of use. It perfectly interconnects with the Hadoop and Spark ecosystems and meets the requirements of high-speed write and complex analysis and query on massive time series data in industrial IoT applications.
Background
Assume that a group has three production lines with five devices on each. Sensors collect indicators (such as temperature, speed, and running status) of these devices in real time, as shown in Figure 1. The service process of storing and managing data using IoTDB is as follows:
- Create a database named root.Group name to represent the group.
- Create time series to store the device indicators.
- Simulate sensors and record indicators.
- Run SQL statements to query indicators.
- After the service is complete, delete the stored data.
Procedure
- Log in to the client.
- Log in to the node where the client is installed as the client installation user and run the following command to switch to the client installation directory, for example, /opt/client.
cd /opt/client
- Run the following command to configure environment variables:
- If this is your first time logging in to the IoTDB client, perform the following steps to generate an SSL certificate:
- Run the following command to generate a client SSL certificate:
keytool -noprompt -import -alias myservercert -file ca.crt -keystore truststore.jks
You are required to set a password.
- Copy the generated truststore.jks file to the Client installation directory/IoTDB/iotdb/conf directory.
cp truststore.jks Client installation directory/IoTDB/iotdb/conf
- Run the following command to generate a client SSL certificate:
- If Kerberos authentication is enabled for the current cluster, run the following command to authenticate the current user. The current user must have the permission to create IoTDB tables. For details, see IoTDB Permission Management. If Kerberos authentication is disabled for the current cluster, skip this step.
kinit MRS cluster user
Example:
kinit iotdbuser
- Log in to the node where the client is installed as the client installation user and run the following command to switch to the client installation directory, for example, /opt/client.
- Run the following command to switch to the directory where the script for running IoTDB client is stored:
cd /opt/client/IoTDB/iotdb/sbin
- If Kerberos authentication is disabled for the cluster (the cluster is in normal mode), invoke the alter-cli-password.sh script to change the default password of the default user root.
sh alter-cli-password.sh IP address of the IoTDBServer instance RPC port number
- The default RPC port number of IoTDBServer is 22260, which can be configured in the IOTDB_SERVER_RPC_PORT parameter.
- Obtain the default password of user root from the system administrator.
- Run the following command to log in to the client:
./start-cli.sh -h IP address of the IoTDBServer instance node -p IoTDBServer RPC port
The default RPC port number of IoTDBServer is 22260, which can be configured in the IOTDB_SERVER_RPC_PORT parameter.
After running this command, specify the service username as needed (user root is used for login when Kerberos authentication is disabled for the cluster (the cluster is in normal mode)).
- To specify the service username, enter yes and enter the service username and password as prompted.
- If you will not specify the service username, enter no. In this case, you will perform subsequent operations as the user in 1.d.
- If you enter other information, you will log out.
- To specify the service username, enter yes and enter the service username and password as prompted.
- Create the root.company database based on the Figure 1 file.
create database root.company;
- Create corresponding time series for sensors of the devices on the production line.
create timeseries root.company.line1.device1.spin WITH DATATYPE=FLOAT, ENCODING=RLE;
create timeseries root.company.line1.device1.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN;
create timeseries root.company.line1.device2.temperature WITH DATATYPE=FLOAT, ENCODING=RLE;
create timeseries root.company.line1.device2.power WITH DATATYPE=FLOAT, ENCODING=RLE;
create timeseries root.company.line2.device1.temperature WITH DATATYPE=FLOAT, ENCODING=RLE;
create timeseries root.company.line2.device1.speed WITH DATATYPE=FLOAT, ENCODING=RLE;
create timeseries root.company.line2.device2.speed WITH DATATYPE=FLOAT, ENCODING=RLE;
create timeseries root.company.line2.device2.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN;
- Adds data to time series.
insert into root.company.line1.device1(timestamp, spin) values (now(), 6684.0);
insert into root.company.line1.device1(timestamp, status) values (now(), false);
insert into root.company.line1.device2(timestamp, temperature) values (now(), 66.7);
insert into root.company.line1.device2(timestamp, power) values (now(), 996.4);
insert into root.company.line2.device1(timestamp, temperature) values (now(), 2684.0);
insert into root.company.line2.device1(timestamp, speed) values (now(), 120.23);
insert into root.company.line2.device2(timestamp, speed) values (now(), 130.56);
insert into root.company.line2.device2(timestamp, status) values (now(), false);
- Query indicators of all devices on the production line 1.
select * from root.company.line1.**;
+-----------------------------+-------------------------------+---------------------------------+--------------------------------------+--------------------------------+ | Time|root.company.line1.device1.spin|root.company.line1.device1.status|root.company.line1.device2.temperature|root.company.line1.device2.power| +-----------------------------+-------------------------------+---------------------------------+--------------------------------------+--------------------------------+ |2021-06-17T11:29:08.131+08:00| 6684.0| null| null| null| |2021-06-17T11:29:08.220+08:00| null| false| null| null| |2021-06-17T11:29:08.249+08:00| null| null| 66.7| null| |2021-06-17T11:29:08.282+08:00| null| null| null| 996.4| +-----------------------------+-------------------------------+---------------------------------+--------------------------------------+--------------------------------+
- Delete all device indicators on the production line 2.
delete timeseries root.company.line2.**;
Query the indicator data on production line 2. The result shows no indicator data exists.
select * from root.company.line2.**;
+----+ |Time| +----+ +----+ Empty set.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot