如何将grafana的docker容器连接到mysql的docker容器?

j2qf4p5b  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(866)

我希望设置2个docker容器:grafana和mysql,并允许从grafana到mysql数据库的查询。我有一台aws机器,其中构建了以下文件夹结构:

- docker
  - docker-compose.yml
  - grafana:
    - config.ini
    - dashboards:
      - grafana_dashboard.json
    - provisioning:
      - dashboards:
        - all.yml
      - datasources:
        - all.yml
    - Dockerfile
  - mysql:
    - dbcreation.sql
    - Dockerfile
  - dashboards:
  - import.sh

docker-compose.yml的内容是:

version: '2'
services:
  db-service:
    build: './mysql'
    container_name: mysql
    restart: always
    ports:
      - "3306:3306"
    networks:
      net:
        ipv4_address: 172.16.1.3

  grafana-service:
    build: './grafana'
    container_name: grafana
    restart: always
    ports:
      - "3000:3000"
    environment:
      GF_SECURITY_ADMIN_PASSWORD: "XXX1"
      GF_AUTH_PROXY_ENABLED: "true"
      GF_SECURITY_DATA_SOURCE_PROXY_WHITELIST: 172.16.1.3:3306
      GF_AUTH_ANONYMOUS_ENABLED: "true"
      GF_LOG_LEVEL: "debug"
    depends_on:
      - db-service
    networks:
      net:
        ipv4_address: 172.16.1.4

networks:
  net:
    external: true

volumes:
  grafanadata:
    driver: local
  mysqldata:

grafana的dockerfile:

FROM grafana/grafana:5.2.2
ADD ./provisioning /etc/grafana/provisioning
ADD ./dashboards /var/lib/grafana/dashboards
ENV DS_DB "grafana"

mysql/dockerfile的内容是:

FROM mysql:8.0.12

ENV MYSQL_ROOT_PASSWORD="XXX2"
ENV MYSQL_DATABASE="grafana"

ADD ./dbcreation.sql /docker-entrypoint-initdb.d/dbcreation.sql
EXPOSE 3306

grafana_dashboard.json文件包含从我在自己的计算机上本地设置的grafana导出的json。dbcreation.sql文件包含从我在自己的计算机上本地设置的本地数据库导出的数据。
我正在运行以下命令:

docker network create --gateway 172.16.1.1 --subnet 172.16.1.0/24 net
docker-compose up --build

我得到一个错误:“身份验证插件不受支持”

当将grafana的日志级别转换为debug时,我看到:

t=2018-08-19T10:55:20+0000 lvl=dbug msg=getEngine logger=tsdb.mysql connection="root:XXX2@tcp(172.16.1.3:3306)/grafana?collation=utf8mb4_unicode_ci&parseTime=true&loc=UTC&allowNativePasswords=true"

t=2018-08-19T10:55:47+0000 lvl=eror msg="Request Completed" logger=context userId=1 orgId=1 uname=admin method=POST path=/api/tsdb/query status=500 remote_addr=XX.XXX.XXX.XXX time_ms=2 size=195 referer=http://XX.XXX.XXX.XXX:3000/datasources/edit/1

我已经使用了以下来源来设置它:https://ops.tips/blog/initialize-grafana-with-preconfigured-dashboards/
https://storage.pardot.com/138181/61672/mysql_on_docker_how_to_containerize_your_database.pdf
任何帮助都将不胜感激!谢谢

smtd7mpg

smtd7mpg1#

如本文所述:
go mysql:从go app容器连接到mysql容器时不支持身份验证插件
问题是grafana版本和mysql版本之间的兼容性。一旦移动到docker图像mysql:5.7 (也必须迁移数据)-问题已解决(还需要更改数据库中的排序规则和字符集,以便从版本8.0.12降级到5.7)。

相关问题