LoginSignup
0
0

More than 1 year has passed since last update.

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

Last updated at Posted at 2021-08-16

はじめに

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

が、コンテナ起動後の grafana から influxdb への接続設定で次のエラーが発生し、
残念ながら解消させることができなかった.
🔥「502 Bad Gateway」
🔥「Failed to fetch」

ただ、コンテナ起動の docker-compose.yml の情報は使えるかも知れないことと、
将来、エラー「Bad Gateway」や「Failed to fetch」の対策方法が判明したときに備えて
書き残しておく.

なお、influxdb 1.8 を使えば起動することを確認しているので、
急ぎで influxdb が必要な場合は 1.8 を使うと良いかも知れない.

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

構成

No サービス ホスト側ポート コンテナ側ポート 備考
1 grafana 3000 3000
2 influxdb 8086 8086
3 Fluentd 44224 44224 本記事の趣旨とは無関係であるが、使用していたので載せているだけである

参考にしたサイト

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 git@github.com:robozushi10/qiita-influxdb-docker
$ cd qiita-influxdb-docker/influxdb-2.0

手順

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

ファイル構成

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

 

アクセス権限設定をする

下記エラー回避のために UID = 472, GID = 0(root) を付与しておく.

$ mkdir -p PV/grafana/data
$ sudo chown 472:0 PV/grafana/data

発生したエラー

myinflxdb_grafana | GF_PATHS_DATA='/var/lib/grafana' is not writable.
myinflxdb_grafana | You may have issues with file permissions, more information here: http://docs.grafana.org/installation/docker/#migrate-to-v51-or-later
myinflxdb_grafana | mkdir: can't create directory '/var/lib/grafana/plugins': Permission denied

./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'
    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
    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/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
$ docker-compose ps
       Name                     Command               State                                      Ports                                   
-----------------------------------------------------------------------------------------------------------------------------------------
myinflxdb_fluentd    tini -- /bin/entrypoint.sh ...   Up      24224/tcp, 127.0.0.1:44224->44224/tcp, 127.0.0.1:44224->44224/udp, 5140/tcp
myinflxdb_grafana    /run.sh                          Up      0.0.0.0:3000->3000/tcp                                                     
myinflxdb_influxdb   /entrypoint.sh influxd           Up      0.0.0.0:8086->8086/tcp  

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

・初回ログインは「admin」「admin」である.
・するとパスワード変更が求められる. (面倒なら「skip」をクリックすればよい)
・下図「DATA SOURCES」→「InfluxDB」に進む

image.png
image.png

4. InfluxDB 接続のためのパラメータを入力する.

物理ホストの IP を設定すると「Failed to fetch」が発生してしまう

・物理ホストの IP を 192.168.10.115 とする

image.png

・下図の「Password」には admin を入れた.

image.png

「influxdb」というマシン名を設定すると「Failed to fetch」が発生してしまう

docker-compose.yml での service 名称「influxdb」を使って、
上図の「URL」欄に http://influxdb:8086 を設定すると
「502 Bad Gateway」が発生してしまう.

 

以下メモ

もしかしたら、influxdb に grafana というテーブルが存在していないのかも知れない.

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0