[02] docker-compose で influxdb 1.8 + grafana を立ち上げる


docker-compose を使って後述の構成で、
influxdb 1.8 + grafana + fluentd + Chronograf を立ち上げを試みた.

[01] docker-compose で influxdb 2.0 + grafana を立ち上げる

構成

No サービス ホスト側ポート コンテナ側ポート 備考
1 grafana 3000 3000
2 influxdb 8086 8086 WEBブラウザから 8086 にアクセスしても「404」エラーになるので、下記「Chronograf」を使う.
3 Fluentd 44224 44224 本記事の趣旨とは無関係であるが、使用していたので載せているだけである
4 Chronograf 8888 8888 influxdb を GUI で操作するためのソフトの模様. influxdb 2.0 であれば不要なような気がする.

参考にしたサイト

URL
https://www.youtube.com/watch?v=rRKDfU4tmJQ
https://github.com/Coac/fluentd-influxdb-grafana
https://amemo.hatenablog.jp/entry/2018/07/20/212116
https://grafana.com/docs/grafana/latest/installation/docker/#migrate-to-v51-or-later
https://qiita.com/tamanobi/items/a57f2802c7fd1236ea52

 

コード

$ git clone [email protected]:robozushi10/qiita-influxdb-docker
$ cd qiita-influxdb-docker/influxdb-1.8

手順

1. 必要なファイルを準備する

ファイル構成

$ tree . --charset=c
.
|-- PV
|   |-- fluentd
|   |   |-- etc
|   |   |   `-- fluent.conf
|   |   `-- log
|   |-- grafana
|   |   `-- data
|   `-- influxdb
|       `-- conf
|-- assets
|   `-- fluentd
|       `-- Dockerfile
`-- docker-compose.yml

 

ファイルの中身

./docker-compose.yml

version: '3'
services:
  grafana:
    image: grafana/grafana
    container_name: myinflxdb_grafana
    ports:
      - '3000:3000'
    # エラー「GF_PATHS_DATA='/var/lib/grafana' is not writable」の対策として、UID = 472 にする
    # https://amemo.hatenablog.jp/entry/2018/07/20/212116
    # https://grafana.com/docs/grafana/latest/installation/docker/#migrate-to-v51-or-later
    user: '472:0'
#   user: 'root'
    volumes:
      - './PV/grafana/data:/var/lib/grafana'
    depends_on:
      - influxdb
  fluentd:
    image: fluent/fluentd:v1.13-1
    build: assets/fluentd/.
    container_name: myinflxdb_fluentd
    user: '1000:1000'
    restart: always
    command: >
      /usr/bin/fluentd -c /fluentd/etc/fluent.conf -v
    ports:
      - "127.0.0.1:44224:44224"
      - "127.0.0.1:44224:44224/udp"
    volumes:
      - ./PV/fluentd/log:/fluentd/log
      - ./PV/fluentd/etc:/fluentd/etc
  influxdb:
    image: influxdb:1.8
    container_name: myinflxdb_influxdb
    ports:
      - '8086:8086'
    environment:
      - INFLUXDB_DB=grafana
      - INFLUXDB_USER=grafana
      - INFLUXDB_USER_PASSWORD=grafana
      - INFLUXDB_ADMIN_ENABLED=true
      - INFLUXDB_ADMIN_USER=admin
      - INFLUXDB_ADMIN_PASSWORD=admin
    volumes:
      - './PV/influxdb/data:/var/lib/influxdb'
      - './PV/influxdb/conf:/etc/influxdb/'
  chronograf:
    container_name: chronograf
    image: chronograf
    ports:
      - "8888:8888"
    links:
      - influxdb
    volumes:
      - './PV/chronograf/data:/var/lib/chronograf'

 

./PV/fluentd/etc/fluent.conf

<source>
  @type tail
  path /var/log/logs.json
  pos_file /fluentd/logs.json.pos
  tag default.logs
  format json
</source>

<match default.logs>
  @type influxdb
  host  influxdb
  port  8086
  dbname grafana
  user  admin
  password  admin
  use_ssl false
  time_precision ms
  <buffer>
    @type memory
    flush_interval 5
  </buffer>
</match>

 

./assets/fluentd/Dockerfile

FROM fluent/fluentd:v1.13-1

# 次のエラー回避のために root 権限で実行すること.
# You don't have write permissions for the /usr/lib/ruby/gems/2.7.0 directory.
# (ref. https://qiita.com/tamanobi/items/a57f2802c7fd1236ea52)
USER root

RUN gem install fluent-plugin-influxdb

USER fluentd

2. 起動させる

$ docker-compose build --no-cache
$ docker-compose up -d

 

3. localhost:3000 にアクセスして Grafana のセットアップをする

初回ログインは「admin」「admin」である

 

「admin」「admin」でログインするとパスワード変更を求められる

 

「DATA SOURCES」の設定をする

下図の設定で OK であった.

・「URL」は http://物理ホストのIP:8086 とする.
・「Password」には admin を入力する


 

4. InfluxDB の GUI にアクセスする

Chronograf「http://物理ホストのIP:8888」にアクセスすると、下図のような画面が表示される.

なお、図中の「Connection Name」は任意の名前で良いと思われる.

 

以上.