2021/02/07

InfluxDBの導入(Windows編)


背景


InfluxDB開発のため、WindowsにInfluxDBを導入する方法について調査した。

記事の目的


InfluxDBをWindowsに導入する

InfluxDB


ここではInfluxDBについて記載する。

時系列データベース

InfluxDBは時刻情報を主キーとしたデータを扱う時系列データベースの一つである。IoTデバイスのセンサーデータやソフトウェアのログデータなどの時刻情報を付随したデータを扱うことが可能である。

ツール類のサポート

InfluxDBには、PythonやJavascript、Grafanaとの連携がサポートされている。そのため、時系列データの解析や可視化が可能である。

Windowsへの導入法

WindowsへのInfluxDB導入方法について記載する。
  1. InfluxDBのダウンロード
  2. 公式ホームページからInfluxDBをダウンロードする
  3. InfluxDBの解凍
  4. ダウンロードしたZIP形式のファイルを
    C:\Program Files
    に展開する
  5. influxdbのデータ保存先を作成する
    • metadataとraftデータベースの保存先を作成する
    • C:\Program Files\influxdb-X.X.X-X
      にmetaディレクトリを作成
    • TSMファイルの保存先を作成する
    • C:\Program Files\influxdb-X.X.X-X
      にdataディレクトリを作成
    • WALファイルの保存先を作成する
    • C:\Program Files\influxdb-X.X.X-X
      にwalディレクトリを作成
  6. influxdb.confの変更
  7. 設定ファイル(influxdb.conf)を変更する。
    • metadataとraftデータベースの保存先を変更する
    • 変更前
      [meta]
        # Where the metadata/raft database is stored
        dir = "/var/lib/influxdb/meta"
      変更後
      [meta]
        # Where the metadata/raft database is stored
        dir = "C:\Program Files\influxdb-X.X.X-X\meta"
    • TSMファイルとWALファイルの保存先を変更する
    • 変更前
      [data]
        # The directory where the TSM storage engine stores TSM files.
        dir = "/var/lib/influxdb/data"
        # The directory where the TSM storage engine stores WAL files.
        wal-dir = "/var/lib/influxdb/wal"
      変更後
      [data]
        # The directory where the TSM storage engine stores TSM files.
        dir = "C:\Program Files\influxdb-X.X.X-X\data"
        # The directory where the TSM storage engine stores WAL files.
        wal-dir = "C:\Program Files\influxdb-X.X.X-X\wal"
    • http通信の設定確認
    • 下記の通り設定されているか確認
      [http]
        # Determines whether HTTP endpoint is enabled.
        enabled = true
      
        # Determines whether the Flux query endpoint is enabled.
        # flux-enabled = false
      
        # Determines whether the Flux query logging is enabled.
        # flux-log-enabled = false
      
        # The bind address used by the HTTP service.
        bind-address = "localhost:8086"
      
        # Determines whether user authentication is enabled over HTTP/HTTPS.
        auth-enabled = false
      
        # The default realm sent back when issuing a basic auth challenge.
        # realm = "InfluxDB"
      
        # Determines whether HTTP request logging is enabled.
        log-enabled = true
  8. InfluxDBの起動
  9. powershellでInfluxDBを起動する
    PS > cd C:\Program Files\influxdb-X.X.X-X
    PS C:\Program Files\influxdb-X.X.X-X > ./influxd.exe -config influxdb.conf
    
  10. InfluxDBに動作確認
    • influxにアクセス
    • 時刻はrfc3339形式を使用する
      PS > cd C:\Program Files\influxdb-X.X.X-X
      PS C:\Program Files\influxdb-X.X.X-X > ./influx.exe -precision rfc3339
    • DBを作成する
    • > create database sample_database
    • 作成したDBの確認する
    • > show databases
    • 操作するDBを設定する
    • > use sample_database
    • 作成したDBにデータをinsertする
    • > insert sample,tag1=A,tag2=B field1="a",field2="b"
      > insert sample,tag1=C field1="c",field2="d"
      > insert sample,tag1=D,tag2=E field2="e"
      sampleというmeasurement(postgresqlのtable)にtag1, tag2の2つのtag、field1, field2の2つのfieldを挿入した。なお、tag(postgresqlのindex)やfieldは複数指定可能であり、tagやfieldが無い場合はnullとしてinsertされる。
    • 作成したDBにデータをselectする
    • > select * from sample
      name: sample
      time                         field1 field2 tag1 tag2
      ----                         ------ ------ ---- ----
      2021-02-07T09:52:50.0723845Z a      b      A    B
      2021-02-07T10:02:01.4085273Z c      d      C
      2021-02-07T10:02:14.4877153Z        e      D    E
      


データ型

InfluxDBのデータ型は下記の通りである。
データ型 説明
Float 64ビット浮動小数点数。デフォルトの数値型 。
Integer符号付き64ビット整数(-9223372036854775808から9223372036854775807)。数値の末尾にiを付けて整数を指定する。例:1i
String 文字列。Measurements, tag keys, tag values, field keys, field values で使用できる。最大 64KB。
Boolean真偽値。真は [t、T、true、True、TRUE]。 偽は [f、F、false、False、FALSE] で表現する。
Timestamp Unixナノ秒タイムスタンプ。


まとめ


  • WundowsへのInfluxDB導入方法について調査記載した

参考文献




変更履歴


  1. 2021/02/07: 新規作成

0 件のコメント:

コメントを投稿

MQTTの導入

背景 IoTデバイスの接続環境構築のため、MQTT(mosquitto)の導入を行った。 記事の目的 MQTT(mosquitto)をUbuntuに導入する mosquitto ここではmosquittoについて記載する。 MQTT MQTT(Message Qu...