debian10 時系列DB「InfluxDB」をインストールする

debian10 時系列DB「InfluxDB」をインストールする

電力消費データやCPU使用率等時系列の扱いに特化した時系列DBである「InfluxDB」をdebian10にインストールする手順を記述してます。

環境

  • OS debian10

リポジトリ追加

まずはリポジトリを追加します。

## アップデート
sudo apt update

## 必要パッケージのインストール
sudo apt install -y gnupg2 curl wget

## リポジトリ追加
wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -
echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

influxdbインストール

下記のコマンドでinfluxdbをインストールします。

## アップデート
sudo apt update

## インストール
sudo apt install -y influxdb

起動と自動起動設定を行います。

sudo systemctl enable --now influxdb

InfluxDB http認証設定

http認証を有効します。

sudo vim /etc/influxdb/influxdb.conf

## 編集箇所
[http]
 # auth-enabled = false
 auth-enabled = true

認証ユーザーとパスワードを設定します。

※ここでは
user : mebbe
password : password
で設定してます。

curl -XPOST "http://localhost:8086/query" --data-urlencode "q=CREATE USER mebee WITH PASSWORD 'password' WITH ALL PRIV
ILEGES"

InfluxDBログイン

ログインしてDBを作成してみます。

ログインします。

influx -username 'mebee' -password 'password'

DBを作成して、サンプルデータをinsertして、確認してみます。

InfluxDB shell version: 1.7.10
> create database testdb

> show databases
name: databases
name
----
_internal
testdb

> use testdb
Using database testdb

> insert sampledb,server=test,log=error count=1

> select * from sampledb
name: sampledb
time                count log   server
----                ----- ---   ------
1586747506145317052 1     error test

selectした結果のtimeがunixtimeで表示されているので、これを変更します

> precision rfc3339

> select * from sampledb
name: sampledb
time                           count log   server
----                           ----- ---   ------
2020-04-13T03:11:46.145317052Z 1     error test