(10) Use the influx command line tool

The following content comes from Shang Silicon Valley. I wrote this series of articles mainly to facilitate my own subsequent viewing. I don’t have to carry around a PDF to find it, which is too troublesome!

Chapter 10 Using the influx command line tool

1. Starting from InfluxDB version 2.1, the influx command line and the InfluxDB database service program are packaged separately, so installing InfluxDB does not come with the influx command line tool. Users must install the influx command line tool separately.

2. The influx command line tool contains many commands for managing influxDB. Includes buckets, organizations, users, tasks, etc. Starting from version 2.1, installing InfluxDB will not come with the influx command line tool. Now the influx tool and InfluxDB have been maintained separately in source code. You need to pay attention to the correct version when downloading.

10.1 Install the influx command line tool

1. This time, we took a different approach. Instead of looking at the official documentation for installation, we downloaded and installed it from github.

10.1.1 How to find the distribution version of an open source project

10.1.1.1 What is a distribution

1. For details about this part, please refer to Gitee official documentation https://gitee.com/help/articles/4328#article-header0

2. The so-called release means that the open source project has progressed to a certain extent, and various features and functions have become perfect and stable, and it is time to release a phased version.
Generally speaking, the source code of a project is posted on github or gitee, but the source code needs to be compiled before it can be run. So when the author feels that the current development progress of his project is about the same, it should be fine. When he gets stuck, he can create a distribution by himself. At this time, the author needs to upload some attachments, such as the compiled program of v1.0.0, the documentation and source code of v1.0.0, etc.

3. The standardized release information should also include information such as changelog (modification record) to tell users what new features this version has added and what bugs have been fixed compared to the previous version.

10.1.1.2 How to find the release version of a project

1. First, you can visit the official website. Generally speaking, an open source project should usually have its own official website. On its official website, you should be able to find its historical versions. However, some official websites remove the download resources of the old version after the new version is released, such as InfluxDB. In addition, open source projects usually maintain a version timeline on github or gitee. Open the homepage of the open source project you are interested in, as shown in the figure is the InfluxDB project homepage.

Insert image description here

2. Click Release in the lower right corner.

Insert image description here

3. You can see all releases of this framework from the beginning of Pangu to the present. Usually, at the bottom of a version record, there will be the compiled executable program and source code corresponding to this version. You can download it and use it.

Insert image description here

10.1.2 Find open source projects for the influx command line tool

1. Most of the time, you will find the project you care about by searching the project name on github. But if the project itself is not very popular, it may not appear on the first page of search results. You end up scrolling backwards for a long time to find your project.

2. The current popularity of InfluxDB is quite good, but the popularity of the corresponding tools around it is not necessarily high. At this time, you can focus on all projects under a single company.

Insert image description here

3. Find the influx-cli project and open it. https://github.com/influxdata/influx-cli

Insert image description here

10.1.3 Download and install the release version

1. Click the Releases link to see the latest version.

Insert image description here
2. Look down the page and find linux-amd64.tar.gz
Insert image description here
3. Download to /opt/software/

Insert image description here

4. Unzip to /opt/module/

tar -zxvf influxdb2-client-2.4.0-linux-amd64.tar.gz -C /opt/module/

10.2 Configure influx-cli

10.2.1 Create configuration

1. The influx command line tool calls a command every time you perform an operation. It does not start a persistent session. In fact, the bottom layer of influx still encapsulates http requests to the InfluxDB service process. That is to say, it still needs to configure Token or something to obtain authorization.

2. Therefore, in order to avoid writing the token in the command line every time you make a request in the future. We should get a configuration file first. Use the following command to create the influx command line configuration.

./influx config create --config-name influx.conf  \
--host-url http://localhost:8086 \
--org atguigu  \
--token
ZA8uWTSRFflhKhFvNW4TcZwwvd2NHFW1YIVlcj9Am5iJ4ueHawWh49_jszoKybEymHqgR5mAWg4XMv4tb9TP3w==
--active

3. This command will actually create a configs file in the ~/.influxdbv2/ directory. This file contains the configurations written in our command line. as the picture shows:

Insert image description here

10.2.2 Change configuration

1. If you make a configuration error midway and use the above command again, it will say that the configuration already exists.

Insert image description here

2. In other words, in the /home/dengziqi/.influxdbv2/configs file, the ["name"] configuration cannot be repeated and must be globally unique. If you want to adjust the configuration at this time, you should replace create with update. That is

./influx config update --config-name influx.conf xxxxxxxx

10.2.3 Switching between multiple configurations

1. We now use the following command to create another configuration, directly copy the contents in influx.conf, and change the name to influx2.conf

./influx config create --config-name influx2.conf  \
--host-url http://localhost:8086 \
--org atguigu  \
--token
ZA8uWTSRFflhKhFvNW4TcZwwvd2NHFW1YIVlcj9Am5iJ4ueHawWh49_jszoKybEymHqgR5mAWg4XMv4tb9TP3w==
--active

3. After the command is successfully executed, open the ~/.influxdbv2/configs file again. You can see that the file content in configs has changed, there is an additional configuration block named ["influx2.conf"], and the old ["influx.conf"] has changed from active="true" to previous= "true", and there is a key-value pair of active="true" in ["influx2.conf"]. Note that if you use influx-cli to perform operations now, the contents in the influx2.conf configuration block will be used directly.

Insert image description here
4. You can also use the following command to switch the configuration currently in use.

influx config influx.conf

Insert image description here
5. Check the ~/.influxdbv2/configs file again

vim ~/.influxdbv2/configs

Insert image description here

10.2.4 Delete a configuration

1. influx2.conf is now redundant for us. Now, we will delete it. Use the command below to delete influx2.conf.

./influx config remove influx2.conf

Insert image description here
2. After execution, check the ~/.influxdbv2/config file again and you can see that ["influx2.conf"] has disappeared. Moreover, our influx.conf automatically changed to active=true.

Insert image description here

10.3 influx-cli command list

1. We already know that influx-cli encapsulates requests to the InfluxDB HTTP API. So how many functions influx-cli has basically depends on how many commands it encapsulates. This article will not introduce all the functions of influx-cli. Through the following table, you can explore the functions of influx-cli. For details, please refer to: https://docs.influxdata.com/influxdb/v2.4/reference/cli/influx/

Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/qq_38263083/article/details/131921990