grafana-使用grafana-image-renderer:v4.0.17渲染仪表盘图像
v4.0.17需要grafana版本在11.3.8以上。
我的是centos7, 升级grafana很简单,备份一下数据和配置,然后停掉grafana服务,然后使用【rpm -Uvh 新版本的rpm包 】就可以。
部署
参考官方的说明:
https://grafana.com/grafana/plugins/grafana-image-renderer/
我直接复制进来:
Installation 安装
We offer two installation methods: as a Docker image, and as a standalone service.我们提供两种安装方法:作为Docker镜像,以及作为独立服务。
I deploy Grafana in Docker/Kubernetes/...: Use the Docker image.我将Grafana部署在Docker/Kubernetes/…:使用Docker镜像。
I deploy Grafana as a user/in systemd/...:我将Grafana作为用户/部署在systemd/…中:
- Prefer the Docker image with
--networking=host
passed to the Docker container.首选传递给Docker容器的Docker映像--networking=host
。 - If that is not fitting, prefer the standalone server.如果不合适,建议使用独立服务器。
Docker image (recommended)Docker镜像(推荐)
If you want to run the service as a Docker container, use the Docker image we publish to DockerHub.如果你想将服务作为Docker容器运行,使用我们发布到DockerHub的Docker镜像。
With docker run
: 与 docker run
:
$
dockernetwork create grafana
$
dockerrun
--networkgrafana
--namerenderer
--rm--detach
grafana/grafana-image-renderer:latest
# The following is not a production-ready Grafana instance, but shows what env vars you should set:
$
dockerrun
--networkgrafana
--namegrafana
--rm--detach
--env
GF_RENDERING_SERVER_URL=
http://renderer:8081/render
--envhttp://grafana:3000/
--port3000
:3000 grafana/grafana-enterprise:latest
With docker compose
: 与 docker compose
:
services:
renderer:
image:
grafana/grafana
-image
-renderer
:latest
grafana:
image: grafana/grafana
-enterprise
:latest
ports:
- ‘3000
:3000’
environment:
GF_RENDERING_SERVER_URL: http
://renderer
:8081/render
GF_RENDERING_CALLBACK_URL: http
://grafana
:3000/
With Kubernetes, see our k3s setup.对于Kubernetes,请参阅k3s设置。
Run as standalone Node.js application作为独立的Node.js应用运行
The following example describes how to build and run the remote HTTP rendering service as a standalone Node.js application and configure Grafana appropriately.下面的例子描述了如何构建和运行远程HTTP渲染服务作为一个独立的Node.js应用程序,并适当地配置Grafana。
- Clone the Grafana image renderer plugin Git repository.克隆Grafana图像渲染插件Git库。
- Install dependencies and build:安装依赖项并构建:
- Run the server: 运行服务器:
- Update Grafana configuration:更新Grafana配置:
- Restart Grafana.
yarninstall
--pure-lockfile
yarn run build
- Using default configuration:
node build/app.js server
使用默认配置:node build/app.js server
- Using custom configuration:
node build/app.js server --config=dev.json
使用自定义配置:node build/app.js server --config=dev.json
- Using environment variables:
HTTP_PORT=8085 LOG_LEVEL=debug node build/app.js server
使用环境变量:HTTP_PORT=8085 LOG_LEVEL=debug node build/app.js server
[rendering]
server_url = http://localhost:8081/render
callback_url = http://localhost:3000/
我的情况
我的grafana是二进制安装的,但是我想使用docker部署renderer,其实本质上是一样的。grafana和renderer容器能够互相访问到就行。
sudo docker run --name renderer -h renderer -P --detach grafana-image-renderer:v4.0.17 [gyj@gyj-centos7 docker-ce-25.0.3-1]$ sudo docker ps [sudo] gyj 的密码: CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 67e79e0dc62d grafana-image-renderer:v4.0.17 "tini -- /nodejs/bin…" 31 minutes ago Up 31 minutes (healthy) 0.0.0.0:32768->8081/tcp, :::32768->8081/tcp renderer [gyj@gyj-centos7 docker-ce-25.0.3-1]$
然后再去grafana里面做配置:
[rendering] server_url = http://localhost:8081/render callback_url = http://localhost:3000/
这里,server_url中的localhost要设置为renderer容器所在的的主机地址,端口也要对应。callback_url中的localhost自然也要设置为grafana所在的地址和端口了。
然后就可以了。
FQA
图像渲染失败
我升级成功了,然后我想渲染图像,我部署了reder容器,按照官方的操作说明。但是还是不能成功渲染图像。
[gyj@gyj-centos7 docker-ce-25.0.3-1]$ sudo cat /etc/grafana/grafana.ini |grep -A 10 '\[rendering'|grep -v '^#'[rendering]server_url = http://192.168.50.104:32768/render callback_url = http://192.168.50.104:3000/ ;renderer_token = -;concurrent_render_request_limit = 30[gyj@gyj-centos7 docker-ce-25.0.3-1]$ sudo docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES67e79e0dc62d grafana-image-renderer:v4.0.17 "tini -- /nodejs/bin…" 11 minutes ago Up 11 minutes (healthy) 0.0.0.0:32768->8081/tcp, :::32768->8081/tcp renderer[gyj@gyj-centos7 docker-ce-25.0.3-1]$ sudo systemctl status grafana-server -l● grafana-server.service - Grafana instanceLoaded: loaded (/usr/lib/systemd/system/grafana-server.service; disabled; vendor preset: disabled)Active: active (running) since 五 2025-10-10 22:12:05 CST; 6min agoDocs: http://docs.grafana.org Main PID: 22326 (grafana)Tasks: 9Memory: 86.3MCGroup: /system.slice/grafana-server.service└─22326 /usr/share/grafana/bin/grafana server --config=/etc/grafana/grafana.ini --pidfile=/var/run/grafana/grafana-server.pid --packaging=rpm cfg:default.paths.logs=/var/log/grafana cfg:default.paths.data=/var/lib/grafana cfg:default.paths.plugins=/var/lib/grafana/plugins cfg:default.paths.provisioning=/etc/grafana/provisioning10月 10 22:12:11 gyj-centos7 grafana[22326]: logger=context userId=1 orgId=1 uname=admin t=2025-10-10T22:12:11.533606146+08:00 level=info msg="Request Completed" method=GET path=/api/dashboards/uid/ff0jldvduu6tcc/public-dashboards status=404 remote_addr=192.168.50.25 time_ms=2 duration=2.269567ms size=90 referer="http://192.168.50.104:3000/d/ff0jldvduu6tcc/new-dashboard?from=now-6h&orgId=1&timezone=browser&to=now" handler=/api/dashboards/uid/:dashboardUid/public-dashboards status_source=server errorReason=NotFound errorMessageID=publicdashboards.notFound error="FindByDashboardUid: Public dashboard not found by orgId: 1 and dashboardUid: ff0jldvduu6tcc"10月 10 22:12:14 gyj-centos7 grafana[22326]: logger=plugin.installer t=2025-10-10T22:12:14.687318859+08:00 level=info msg="Installing plugin" pluginId=grafana-exploretraces-app version=10月 10 22:12:14 gyj-centos7 grafana[22326]: logger=plugin.backgroundinstaller t=2025-10-10T22:12:14.687425773+08:00 level=error msg="Failed to install plugin" pluginId=grafana-exploretraces-app version= error="failed to extract plugin archive: could not create \"/var/lib/grafana/plugins/grafana-exploretraces-app\", permission denied, make sure you have write access to plugin dir"10月 10 22:12:14 gyj-centos7 grafana[22326]: logger=plugin.backgroundinstaller t=2025-10-10T22:12:14.687455049+08:00 level=info msg="Installing plugin" pluginId=grafana-metricsdrilldown-app version=10月 10 22:12:18 gyj-centos7 grafana[22326]: logger=plugin.installer t=2025-10-10T22:12:18.690448378+08:00 level=info msg="Installing plugin" pluginId=grafana-metricsdrilldown-app version=10月 10 22:12:18 gyj-centos7 grafana[22326]: logger=plugin.backgroundinstaller t=2025-10-10T22:12:18.690548017+08:00 level=error msg="Failed to install plugin" pluginId=grafana-metricsdrilldown-app version= error="failed to extract plugin archive: could not create \"/var/lib/grafana/plugins/grafana-metricsdrilldown-app\", permission denied, make sure you have write access to plugin dir"10月 10 22:12:18 gyj-centos7 grafana[22326]: logger=plugin.backgroundinstaller t=2025-10-10T22:12:18.690570527+08:00 level=info msg="Installing plugin" pluginId=grafana-lokiexplore-app version=10月 10 22:12:32 gyj-centos7 grafana[22326]: logger=plugin.installer t=2025-10-10T22:12:32.01881521+08:00 level=info msg="Installing plugin" pluginId=grafana-lokiexplore-app version=10月 10 22:12:32 gyj-centos7 grafana[22326]: logger=plugin.backgroundinstaller t=2025-10-10T22:12:32.019707896+08:00 level=error msg="Failed to install plugin" pluginId=grafana-lokiexplore-app version= error="failed to extract plugin archive: could not create \"/var/lib/grafana/plugins/grafana-lokiexplore-app\", permission denied, make sure you have write access to plugin dir"10月 10 22:13:10 gyj-centos7 grafana[22326]: logger=infra.usagestats t=2025-10-10T22:13:10.558337685+08:00 level=info msg="Usage stats are ready to report"[gyj@gyj-centos7 docker-ce-25.0.3-1]$
然后我发现点击生成图像的时候,grafana前端访问的接口地址是:"http://localhost:3000/render/d-solo/ff0jldvduu6tcc?orgId=1&from=2025-10-10T08:12:11.502Z&to=2025-10-10T14:12:11.502Z&timezone=browser&panelId=panel-1&__feature.dashboardSceneSolo=true&width=1000&height=500&scale=1&tz=Asia%2FShanghai",它怎么会访问localhost呢?
从配置和现象来看,核心问题是 Grafana 前端生成的渲染请求地址错误(用了 localhost:3000 而非实际服务器 IP),导致无法正确指向部署的 render 容器。这本质是 Grafana 的 “根 URL” 配置不正确,而非 render 容器本身的问题。以下是具体原因和解决步骤:
一、问题根源:Grafana 根 URL 未配置,默认用 localhost
Grafana 前端生成渲染请求地址时,会基于 grafana.ini 中的 root_url 字段拼接路径。如果该字段未配置(默认值为 %(protocol)s://%(domain)s:%(http_port)s/),Grafana 会默认将 “前端访问时的域名 / IP” 作为基准 —— 若你在服务器本地访问 Grafana(或配置中未明确服务器 IP),前端就会误将 localhost:3000 作为根 URL,导致渲染请求指向 localhost(仅服务器本地可访问,前端浏览器无法连接)。
你的配置中只设置了 [rendering] 下的 server_url 和 callback_url,但未配置 root_url,这是导致地址错误的关键。
二、解决步骤:修改 Grafana 配置,明确根 URL 和渲染参数
1. 编辑 grafana.ini,补充 3 个关键配置
打开 Grafana 主配置文件,重点修改 [server] 下的 root_url 和 [rendering] 下的 renderer_token(可选但推荐):
# 编辑配置文件(需 sudo 权限)
sudo vim /etc/grafana/grafana.ini
找到对应段落,按以下内容修改(关键配置已标红):
ini
# ---------------------
# [server] 段落:配置 Grafana 根 URL
# ---------------------
[server]
# 1. 核心:设置为 Grafana 实际访问地址(你的服务器 IP:3000)
# 例如你的服务器 IP 是 192.168.50.104,就配置为:
root_url = http://192.168.50.104:3000/
# (默认值是 %(protocol)s://%(domain)s:%(http_port)s/,会自动识别,但不稳定,建议手动指定)
# 其他默认配置可保留(如 http_port = 3000,无需修改)
# ---------------------
# [rendering] 段落:补充渲染配置
# ---------------------
[rendering]
# 你已配置的 2 个参数(确认正确,无需修改)
server_url = http://192.168.50.104:32768/render
callback_url = http://192.168.50.104:3000/
# 2. 可选但推荐:添加渲染令牌(增强安全性,避免未授权访问 render 容器)
# 生成一个随机令牌(如用命令:openssl rand -hex 16 生成)
renderer_token = your_random_token_here # 例如:a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6
- root_url 说明:必须与你浏览器访问 Grafana 的地址完全一致(例如你通过 http://192.168.50.104:3000 登录,就配置为这个地址),前端会基于这个 URL 拼接渲染请求路径,避免出现 localhost。
- renderer_token 说明:生成随机令牌后,后续启动 render 容器时需带上该令牌,确保只有你的 Grafana 能调用渲染服务(步骤 2 会用到)。
2. 重启 Grafana 服务,让配置生效
bash
# 重启服务
sudo systemctl restart grafana-server
# 确认服务正常运行(输出 active (running))
sudo systemctl status grafana-server -l
3. (可选)重启 render 容器,添加令牌(增强安全性)
如果步骤 1 中配置了 renderer_token,需要重启 render 容器并传入令牌环境变量,确保与 Grafana 配置一致:
bash
# 1. 先停止并删除旧容器
sudo docker stop renderer
sudo docker rm renderer
# 2. 启动新容器,添加 RENDERER_TOKEN 环境变量
# 替换 "your_random_token_here" 为步骤 1 中配置的令牌
sudo docker run -d \
--name renderer \
-p 32768:8081 \
-e RENDERER_TOKEN=your_random_token_here \
grafana-image-renderer:v4.0.17
- 若未配置 renderer_token,可跳过此步,直接使用原有容器(但生产环境建议配置令牌)。
4. 验证渲染请求地址是否正确
- 浏览器访问 Grafana(http://192.168.50.104:3000),进入任意仪表盘;
- 点击仪表盘右上角的 “分享”→“导出为图片”,触发渲染请求;
- 打开浏览器的 “开发者工具”(F12)→ 切换到 “网络” 标签页,找到 render 相关的请求(路径含 /render/d-solo/);
- 查看请求的 “请求 URL”,若显示为 http://192.168.50.104:3000/render/...(而非 localhost),说明配置生效。
成功:
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/934800.shtml
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!