Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and basic usage of InfluxDB

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the installation and basic use of InfluxDB". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "the installation and basic use of InfluxDB".

A brief introduction to InfluxDB

InfluxDB is an open source distributed database of timing, events and metrics written in the Goto language without external dependency.

Functional features

Based on time series, support time-related functions (such as maximum, minimum, summation, etc.)

Measurability: you can calculate large amounts of data in real time

Event-based: it supports arbitrary event data: it supports arbitrary event data

Note: the built-in management interface will no longer be available after version 1.2.

Oint attributes the concept in the traditional database time (timestamp) each data recording time, is the main index in the database (automatically generated) fields (fields, data) various record values (non-indexed attributes), that is, recorded values: temperature, humidity tags (label) various indexed attributes: area, altitude attention

In influxdb, a field must exist. Because the field has no index. If you use a field as a query condition, all field values that meet the query criteria are scanned, and the performance is not as good as tag. By analogy, fields is equivalent to SQL's column without an index. Tags is optional, but it is strongly recommended that you use it because tag is indexed and tags is equivalent to indexed columns in SQL. Tag value can only be of type string. Series is equivalent to a collection of data in InfluxDB. In the same database, the identical data of retention policy, measurement and tag sets belong to the same series, and the data of the same series are physically stored in chronological order.

Select * from students name: students time score stuid value

1542848518465067760 89 s123 1542850528630385278 79 s123 1542850533581732431 69 s123 1542850536266169940 39 s123 1542850676477097687 99 s123 1542874869654197110 s124 100 1542874898710687064 s125 60

Show series from students key

Students,stuid=s123 students,stuid=s124 students,stuid=s125 123,4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17 shard shard were associated with retention policy. There are many shard under each storage policy, and each shard stores data within a specified period of time and does not repeat; for example, data from 7: 00 to 8: 00 falls into shard0, and data from 8: 00 to 9: 00 falls into shard1. Each shard corresponds to an underlying tsm storage engine with independent cache, wal, and tsm file.

The component TSM storage engine is mainly composed of several parts: cache, wal, tsm file, compactor.

Cache:cache is the equivalent of memtabl in LSM Tree. When you insert data, you actually write data to both cache and wal, and you can think of cache as the in-memory cache of the data in the wal file. When InfluxDB starts, it traverses all the wal files and reconstructs the cache, so that even if the system fails, it does not result in data loss. The data in cache is not growing indefinitely, and there is a maxSize parameter that controls how much memory the data in cache takes up will be written to the tsm file. If it is not configured, the default upper limit is 25MB. Every time the data in the cache reaches the threshold, the current cache will be snapped, then the contents of the current cache will be cleared, and a new wal file will be created for writing. The remaining wal file will eventually be deleted, and the data in the snapshot will be sorted and written to a new tsm file.

The content of the WAL:wal file is the same as the cache in memory, and its purpose is to persist the data. When the system crashes, you can recover the data that has not been written to the tsm file through the wal file. TSM File: the maximum size of a single tsm file, 2GB, is used to store data. The Compactor:compactor component runs continuously in the background, checking every 1 second to see if there is a need to compress the merged data. There are two main operations: one is to take a snapshot after the data size in cache reaches the threshold, and then transfer it to a new tsm file. The other is to merge the current tsm files, merging multiple small tsm files into one, so that each file can reach the maximum size of a single file as far as possible, reducing the number of files, and some data deletion operations are also completed at this time.

Installation environment: CentOS7.0_x64 InfluxDB version: 1.7.0

Installation of basic environment yum install go 1 InfluxDB wget https://dl.influxdata.com/influxdb/releases/influxdb-1.7.0.x86_64.rpm rpm-ivh influxdb-1.2.0.x86_64.rpm 1 2 explanation of InfluxDB related files generated after installation / file name file resolution under usr/bin influxd influxdb server influx influxdb command line client influx_inspect viewing tool influx_stress stress test tool influx_tsm Database conversion tool (convert database from b1 or bz1 format to tsm1 format) / var/lib/influxdb folder folder parsing data stores the final stored data The file ends with * * .tsm * * meta stores database metadata wal stores pre-written log files / file files under etc/influxdb parses influxdb.conf influxdb database configuration files parameters detailed description: InfluxDB influxdbc.conf configuration files

Related commands to start the service operation service service startup command

Other service influxdb start 1 service commands stop service service influxdb stop 1 restart service service influxdb restart 1 attempt to restart service service influxdb try-restart 1 reload service service influxdb reload 1 force reload service service influxdb force-reload 1 view service status service influxdb status 1 starts in a non-service mode

Cd / usr/bin. / influxd 12 service starts to check whether it is working properly by viewing the corresponding process of the service.

[root@localhost influxdb] # ps aux | grep influx influxdb 7293 0.3 2.4 635640 46516? Ssl 18:43 0:01 / usr/bin/influxd-config / etc/influxdb/influxdb.conf root 7412 0.0 112656 964 pts/0 S+ 18:49 grep-- color=auto influx 12 3 check the service status through the service influxdb status command

[root@localhost influxdb] # service influxdb status Redirecting to / bin/systemctl status influxdb.service ● influxdb.service-InfluxDB is an open-source, distributed, time series database Loaded: loaded (/ usr/lib/systemd/system/influxdb.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2018-11-21 18:43:06 PST 1h 1min ago Docs: https://docs.influxdata.com/influxdb/ Main PID: 7293 (influxd) CGroup: / system.slice/influxdb.service └─ 7293 / usr/bin/influxd-config / etc/influxdb/influxdb.conf

Nov 21 19:32:48 localhost.localdomain influxd [7293]: [httpd]:: 1-[21/Nov/2018:19:32:48-0800] "POST / query?chunked=true&db=&epoch=ns&q=usr+testdn HTTP/1.1" 400148-"" InfluxDBS...29d6319a 172Nov 21 19:32:50 localhost.localdomain influxd [7293]: [httpd]:: 1-[21/Nov/2018:19:32:50-0800] "POST / Query?chunked=true&db=&epoch=ns&q=usr+testdb HTTP/1.1 "400148"-"InfluxDBS...29d6319a 119 Nov 21 19:33:00 localhost.localdomain influxd [7293]: ts=2018-11-22T03:33:00.628996Z lvl=info msg=" Executing query "log_id=0BvKdN2W000 service=query query=" SHOW DATABASES "Nov 21 19:33:00 localhost.localdomain influxd [7293]: [httpd]:: 1-[21/Nov/2018:19:33:00-0800]" POST / query?db=&epoch=ns & q=SHOW+DATABASES HTTP/1.1 "200 116"-"InfluxDBShell/1.7....29d6319a 608 Nov 21 19:33:10 localhost.localdomain influxd [7293]: ts=2018-11-22T03:33:10.917329Z lvl=info msg=" Executing query "log_id=0BvKdN2W000 service=query query=" SHOW MEASUREMENTS ON testdb "Nov 21 19:33:10 localhost.localdomain influxd [7293]: [httpd]:: 1-[21/Nov/2018:19:33:10-0800]" POST / query?chunked=true&db=testdb & epoch=ns&q=show+measurements HTTP/1.1 "200108"... 29d6319a 939 Nov 21 19:43:07 localhost.localdomain influxd [7293]: ts=2018-11-22T03:43:07.447858Z lvl=info msg= "Retention policy deletion check (start)" log_id=0BvKdN2W000 service=retention trace_..._event=start Nov 21 19:43:07 localhost.localdomain influxd [7293]: ts=2018-11-22T03:43:07.448965Z lvl=info msg= "Retention policy deletion check (end)" log_id=0BvKdN2W000 service=retention trace_id...psed=1.161ms Nov 21 19: 43:49 localhost.localdomain influxd [7293]: [httpd]:: 1-- [21/Nov/2018:19:43:49-0800] "POST / query?chunked=true&db=testdb&epoch=ns&q=qiut HTTP/1.1" 400149 "-"InfluxDBS...29d6319a 189 Nov 21 19:43:58 localhost.localdomain influxd [7293]: [httpd]:: 1-[21/Nov/2018:19:43:58-0800]" POST / query?chunked=true& Db=testdb&epoch=ns&q=quir HTTP/1.1 "400149"-"InfluxDBS...c29d6319a 95 Hint: Some lines were ellipsized Use-l to show in full. 12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 Port 8088 of related port 8086:HTTP API after service startup: used for backup recovery, default is 8088 InfluxDB client command line operation InfluxDB database operation

Client-side command line operation

[root@localhost influxdb] # influx Connected to http://localhost:8086 version 1.7.0 InfluxDB shell version: 1.7.0 Enter an InfluxQL query

1 2 3 4 5 display database

Show databases name: databases name

_ internal 1 2 3 4 5 New Database

Create database testdb show databases name: databases name

_ internal testdb 1 2 3 4 5 6 7 delete database

Drop database testdb show databases name: databases name

_ internal 1 2 3 4 5 6 using the database

Create database testdb use testdb Using database testdb 123 InfluxDB data tables operate in InfluxDB, and there is no concept of table. Instead, the function of measurement,measurement is the same as that of tables in traditional databases, so we can also call measurement tables in InfluxDB.

Show all tables

The statement to create a table that is not shown in the show measurement 1 new table InfluxDB can only be created through the room of insert data or through the new table. Where disk_free is the table name, hostname is the tag, value=xx is the record value (field), there can be multiple record values, the system has its own additional timestamp.

Insert disk_free,hostname=server01 value=442221834240i select * from disk_free name: disk_free time hostname value

1435362189575692180 server01 442221834240 1 2 34 56 or when adding data, write your own timestamp (write the same timestamp, the same tags, and update the original data)

Insert disk_free,hostname=server01 value=442221834240i 1435362189575692182 select * from disk_free name: disk_free time hostname value

1435362189575692180 server01 442221834240 1435362189575692182 server01 442221834240 1 2 34 56 7 delete table

Drop measurement disk_free 1 data preservation policy (Retention Policies) InfluxDB does not provide a method to delete data records directly, but provides a data preservation policy, which is mainly used to specify the data retention time, and delete this part of the data beyond the specified time.

View the current database Retention Policies

Name: name, the name of this example is default. Duration: duration, 0 means unlimited. The storage time of shardGroupDuration:shardGroup. ShardGroup is a basic storage structure of InfluxDB. Data that should be longer than this time should be less efficient in query. ReplicaN: the full name is replication and the number of copies. Default: whether it is the default policy.

Show retention policies on testdb name duration shardGroupDuration replicaN default

Autogen 0s 168h0m0s 1 true 1 2 3 4 create a new Retention Policies

Rp_name: policy name. Db_name: the specific database name. 3w: save for 3 weeks, the data before 3 weeks will be deleted. Influxdb has various event parameters, and the duration must be at least 1 hour, such as h (hour), d (day), w (week). Replication 1: the number of copies is usually 1. Default: set as the default policy. Create retention policy "rp_name" on "db_name" duration 3w replication 1 default 1 modify Retention Policies

Alter retention policy "rp_name" on "db_name" duration 30d default 1 Delete Retention Policies

Drop retention policy "rp_name" on "db_name" 1 continuous query (Continuous Queries) A continuous query of an InfluxDB is a set of statements that are started automatically and regularly in the database, and the statements must contain the select keyword and the group by time () keyword. InfluxDB places the query results in the specified data table. Objective: the use of continuous query is the best way to reduce the sampling rate. The combination of continuous query and storage strategy will greatly reduce the system usage of InfluxDB. And after using continuous query, the data will be stored in the specified data table, which provides convenience for the future statistics of data with different precision.

Create a new continuous query

CREATE CONTINUOUS QUERY ON [RESAMPLE [EVERY] [FOR]] BEGIN SELECT () [, ()] INTO FROM [WHERE] GROUP BY time () [,] END 1 23 3 45 sample CREATE CONTINUOUS QUERY wj_30m ON testdb BEGIN SELECT mean (connected_clients), MEDIAN (connected_clients), MAX (connected_clients), MIN (connected_clients) INTO redis_clients_30m FROM redis_clients GROUP BY ip,port,time (30m) END 1 created a new continuous query named wj_30m in the testdb library Take the average, median, maximum, and minimum values of the connected_clients field in the redis_clients_30m table every 30 minutes. The data retention policies used are all default. Different database samples: CREATE CONTINUOUS QUERY wj_30m ON testdb_30 BEGIN SELECT mean (connected_clients), MEDIAN (connected_clients), MAX (connected_clients), MIN (connected_clients) INTO testdb_30.autogen.redis_clients_30m FROM testdb.autogen.redis_clients GROUP BY ip,port,time (30m) END 1 shows all existing consecutive queries

Show continuous queries 1 Delete Continuous Queries

At this point, I believe you have a deeper understanding of the "installation and basic use of InfluxDB". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report