Yang, Tong 48706b7552 MRS COMP-LTS 320-lts.1 version
Reviewed-by: Kacur, Michal <michal.kacur@t-systems.com>
Co-authored-by: Yang, Tong <yangtong2@huawei.com>
Co-committed-by: Yang, Tong <yangtong2@huawei.com>
2024-04-12 12:51:10 +00:00

67 lines
12 KiB
HTML

<a name="mrs_01_24157"></a><a name="mrs_01_24157"></a>
<h1 class="topictitle1">Using IoTDB from Scratch</h1>
<div id="body0000001532631112"><p id="mrs_01_24157__p198487251857">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.</p>
<div class="section" id="mrs_01_24157__section209393118466"><h4 class="sectiontitle">Background</h4><p id="mrs_01_24157__p1182161835317">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 <a href="#mrs_01_24157__fig129001748528">Figure 1</a>. The service process of storing and managing data using IoTDB is as follows:</p>
<ol id="mrs_01_24157__ol1070103335211"><li id="mrs_01_24157__li1170193315213">Create a storage group named <strong id="mrs_01_24157__b28461257182010">root.</strong><em id="mrs_01_24157__i0105186162115">Group name</em> to represent the group.</li><li id="mrs_01_24157__li970173365214">Create time series to store the device indicators.</li><li id="mrs_01_24157__li1370213318529">Simulate sensors and record indicators.</li><li id="mrs_01_24157__li9702433125211">Run SQL statements to query indicators.</li><li id="mrs_01_24157__li167021733185215">After the service is complete, delete the stored data.</li></ol>
<div class="fignone" id="mrs_01_24157__fig129001748528"><a name="mrs_01_24157__fig129001748528"></a><a name="fig129001748528"></a><span class="figcap"><b>Figure 1 </b>Data structure</span><br><span><img id="mrs_01_24157__image1190011420528" src="en-us_image_0000001532951892.png"></span></div>
</div>
<div class="section" id="mrs_01_24157__section146177231595"><h4 class="sectiontitle">Procedure</h4><ol id="mrs_01_24157__ol13946132419319"><li id="mrs_01_24157__li172969120454"><span>Log in to the client.</span><p><ol type="a" id="mrs_01_24157__ol126151428115513"><li id="mrs_01_24157__li196151828185515">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, <strong id="mrs_01_24157__b475122717343"><span id="mrs_01_24157__ph381512063917">/opt/client</span></strong>.<p id="mrs_01_24157__p28161562126"><strong id="mrs_01_24157__b128165661213">cd <span id="mrs_01_24157__ph56881859451">/opt/client</span></strong></p>
</li><li id="mrs_01_24157__li189224715516">Run the following command to configure environment variables:<p id="mrs_01_24157__p781713618126"><a name="mrs_01_24157__li189224715516"></a><a name="li189224715516"></a><strong id="mrs_01_24157__b1781712614124">source bigdata_env</strong></p>
</li><li id="mrs_01_24157__li10203101511564"><a name="mrs_01_24157__li10203101511564"></a><a name="li10203101511564"></a>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 <a href="mrs_01_24140.html">IoTDB Permission Management</a>. If Kerberos authentication is disabled for the current cluster, skip this step.<p id="mrs_01_24157__p1666420381557"><strong id="mrs_01_24157__b848515990101135">kinit</strong> <em id="mrs_01_24157__i1460261756101135">MRS cluster user</em></p>
<p id="mrs_01_24157__p156457281278">Example:</p>
<p id="mrs_01_24157__p1866410381553"><strong id="mrs_01_24157__b1866403811559">kinit iotdb</strong><strong id="mrs_01_24157__b16321010184813">user</strong></p>
</li></ol>
</p></li><li id="mrs_01_24157__li1835102265710"><span>Run the following command to switch to the directory where the script for running IoTDB client is stored:</span><p><p id="mrs_01_24157__p3858122265717"><strong id="mrs_01_24157__b10858132219574">cd <span id="mrs_01_24157__ph3972191574516">/opt/client</span>/IoTDB/iotdb/sbin</strong></p>
</p></li><li id="mrs_01_24157__li956011426573"><span>Run the following command to log in to the client:</span><p><p id="mrs_01_24157__p85137329418"><strong id="mrs_01_24157__b1278615511331">./start-cli.sh -h</strong> <em id="mrs_01_24157__i1551401953414">IP address of the IoTDBServer instance node</em> <strong id="mrs_01_24157__b18383641113420">-p</strong> <em id="mrs_01_24157__i45991572341">IoTDBServer RPC port</em></p>
<p id="mrs_01_24157__p1157764275716">The default IoTDBServer RPC port number is <strong id="mrs_01_24157__b985823944312">22260</strong>, which can be configured in the <strong id="mrs_01_24157__b3347421134418">rpc_port</strong> parameter.</p>
<p id="mrs_01_24157__p13656269549">After you run this command, specify the service username as required.</p>
<ul id="mrs_01_24157__ul9773644154020"><li id="mrs_01_24157__li980113119919">To specify the service username, enter <strong id="mrs_01_24157__b17261183017620">yes</strong> and enter the service username and password as prompted.<p id="mrs_01_24157__p11250017105315"><span><img id="mrs_01_24157__image49705115425" src="en-us_image_0000001583391869.png"></span></p>
</li></ul>
<ul id="mrs_01_24157__ul5801011910"><li id="mrs_01_24157__li2080141392">If you will not specify the service username, enter <strong id="mrs_01_24157__b17865320201915">no</strong>. In this case, you will perform subsequent operations as the user in <a href="#mrs_01_24157__li10203101511564">1.c</a>.<p id="mrs_01_24157__p6762125425314"><span><img id="mrs_01_24157__image165962644411" src="en-us_image_0000001582952105.png"></span></p>
</li><li id="mrs_01_24157__li280281796">If you enter other information, you will log out.<p id="mrs_01_24157__p980261593"><a name="mrs_01_24157__li280281796"></a><a name="li280281796"></a><span><img id="mrs_01_24157__image1824155773715" src="en-us_image_0000001532632212.png"></span></p>
</li></ul>
</p></li><li id="mrs_01_24157__li331903313619"><span>Create a storage group named <strong id="mrs_01_24157__b119345561982750">root.company</strong> based on <a href="#mrs_01_24157__fig129001748528">Figure 1</a>.</span><p><p id="mrs_01_24157__p1021333517611"><strong id="mrs_01_24157__b9801155119571">set storage group to root.company;</strong></p>
</p></li><li id="mrs_01_24157__li10692184716611"><span>Create corresponding time series for sensors of the devices on the production line.</span><p><p id="mrs_01_24157__p67107477613"><strong id="mrs_01_24157__b11710104710610">create timeseries root.company.line1.device1.spin WITH DATATYPE=FLOAT, ENCODING=RLE;</strong></p>
<p id="mrs_01_24157__p1971114719610"><strong id="mrs_01_24157__b17711174719616">create timeseries root.company.line1.device1.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN;</strong></p>
<p id="mrs_01_24157__p071116471167"><strong id="mrs_01_24157__b57112471765">create timeseries root.company.line1.device2.temperature WITH DATATYPE=FLOAT, ENCODING=RLE;</strong></p>
<p id="mrs_01_24157__p67111471616"><strong id="mrs_01_24157__b14711847163">create timeseries root.company.line1.device2.power WITH DATATYPE=FLOAT, ENCODING=RLE;</strong></p>
<p id="mrs_01_24157__p1471194719616"><strong id="mrs_01_24157__b5711134714615">create timeseries root.company.line2.device1.temperature WITH DATATYPE=FLOAT, ENCODING=RLE;</strong></p>
<p id="mrs_01_24157__p207111647366"><strong id="mrs_01_24157__b1711124714611">create timeseries root.company.line2.device1.speed WITH DATATYPE=FLOAT, ENCODING=RLE;</strong></p>
<p id="mrs_01_24157__p187119471060"><strong id="mrs_01_24157__b7711147666">create timeseries root.company.line2.device2.speed WITH DATATYPE=FLOAT, ENCODING=RLE;</strong></p>
<p id="mrs_01_24157__p97111471169"><strong id="mrs_01_24157__b107116471264">create timeseries root.company.line2.device2.status WITH DATATYPE=BOOLEAN, ENCODING=PLAIN;</strong></p>
</p></li><li id="mrs_01_24157__li114224318105"><span>Adds data to time series.</span><p><p id="mrs_01_24157__p209662497105"><strong id="mrs_01_24157__b4931131811468">insert into root.company.line1.device1(timestamp, spin) values (now(), 6684.0);</strong></p>
<p id="mrs_01_24157__p119668494107"><strong id="mrs_01_24157__b1094511183467">insert into root.company.line1.device1(timestamp, status) values (now(), false);</strong></p>
<p id="mrs_01_24157__p1396644915108"><strong id="mrs_01_24157__b49661818154617">insert into root.company.line1.device2(timestamp, temperature) values (now(), 66.7);</strong></p>
<p id="mrs_01_24157__p18967104910106"><strong id="mrs_01_24157__b17967161894616">insert into root.company.line1.device2(timestamp, power) values (now(), 996.4);</strong></p>
<p id="mrs_01_24157__p59671449181016"><strong id="mrs_01_24157__b1896821804619">insert into root.company.line2.device1(timestamp, temperature) values (now(), 2684.0);</strong></p>
<p id="mrs_01_24157__p1696734981019"><strong id="mrs_01_24157__b11968101810463">insert into root.company.line2.device1(timestamp, speed) values (now(), 120.23);</strong></p>
<p id="mrs_01_24157__p1496734913101"><strong id="mrs_01_24157__b209699189462">insert into root.company.line2.device2(timestamp, speed) values (now(), 130.56);</strong></p>
<p id="mrs_01_24157__p19671949191016"><strong id="mrs_01_24157__b18970201817464">insert into root.company.line2.device2(timestamp, status) values (now(), false);</strong></p>
</p></li><li id="mrs_01_24157__li179842141419"><span>Query indicators of all devices on the production line 1.</span><p><p id="mrs_01_24157__p982017611212"><strong id="mrs_01_24157__b11650451154715">select * from root.company.line1.**;</strong></p>
<pre class="screen" id="mrs_01_24157__screen214815615324">+-----------------------------+-------------------------------+---------------------------------+--------------------------------------+--------------------------------+
| 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|
+-----------------------------+-------------------------------+---------------------------------+--------------------------------------+--------------------------------+</pre>
</p></li><li id="mrs_01_24157__li6389219201416"><span>Delete all device indicators on the production line 2.</span><p><p id="mrs_01_24157__p143981019111419"><strong id="mrs_01_24157__b7411296142">delete timeseries root.company.line2.*;</strong></p>
<p id="mrs_01_24157__p12760181210332">Query the indicator data on production line 2. The result shows no indicator data exists.</p>
<p id="mrs_01_24157__p1657623643515"><strong id="mrs_01_24157__b1680220245415">select * from root.company.line2.**;</strong></p>
<pre class="screen" id="mrs_01_24157__screen197381483352">+----+
|Time|
+----+
+----+
Empty set.</pre>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="mrs_01_24144.html">Using IoTDB</a></div>
</div>
</div>