如何在Kibana Docker镜像与RPM包中预置现成仪表盘?
Hey there! Let's tackle your two Kibana packaging questions—this is a common use case for distributing pre-configured analytics tools, and I’ve worked through this a bunch of times. Here’s a step-by-step breakdown:
The core idea is to pre-seed Kibana with your saved dashboards/reports (called "saved objects" in Kibana terms) so they load automatically on first launch. Below are the workflows for both Docker and RPM:
Docker Image Approach
Step 1: Export Your Prebuilt Dashboards
First, set up a temporary Kibana instance, create all your desired dashboards, visualizations, and index patterns. Then:
- Go to Stack Management > Saved Objects > Export
- Check the Include related objects box (critical to capture dependencies like visualizations or index patterns)
- Export the bundle as a file named
prebuilt-dashboards.ndjson
Step 2: Build a Custom Docker Image
Create a Dockerfile based on the official Kibana image, and add your saved objects + configuration to auto-import them:
# Use the exact Kibana version you used to export the objects FROM docker.elastic.co/kibana/kibana:8.11.3 # Copy your saved objects bundle into the image COPY prebuilt-dashboards.ndjson /usr/share/kibana/data/ # Copy a custom kibana.yml with import settings COPY kibana.yml /usr/share/kibana/config/
Update your kibana.yml to enable automatic import on startup:
# Enable saved object imports xpack.savedObjects.import.enabled: true # Path to your prebuilt bundle xpack.savedObjects.import.path: /usr/share/kibana/data/prebuilt-dashboards.ndjson # Overwrite existing objects (safe for first-time launches) xpack.savedObjects.import.overwrite: true # Keep other default Kibana settings here, or copy from the official image's kibana.yml
Step 3: Build & Test the Image
Run these commands to build and verify your custom image:
docker build -t my-custom-kibana . docker run -p 5601:5601 my-custom-kibana
Once Kibana starts, open http://localhost:5601—your dashboards should be ready to use immediately.
RPM Package Approach
Step 1: Export Your Saved Objects
Same as the Docker workflow: export your dashboards and dependencies as prebuilt-dashboards.ndjson.
Step 2: Create a Custom RPM Spec File
You’ll build a custom RPM that layers your prebuilt objects and configuration on top of the official Kibana RPM. Here’s a sample spec file:
Name: my-custom-kibana Version: 8.11.3 Release: 1%{?dist} Summary: Kibana with preconfigured dashboards License: Elastic License URL: https://elastic.co Source0: https://artifacts.elastic.co/downloads/kibana/kibana-%{version}-x86_64.rpm Source1: prebuilt-dashboards.ndjson Source2: kibana.yml BuildArch: x86_64 Requires: kibana = %{version} %description Custom Kibana package with prebuilt dashboards ready to use on first launch. %prep # Extract files from the official Kibana RPM rpm2cpio %{SOURCE0} | cpio -idmv %install # Copy saved objects to Kibana's data directory install -Dm 644 %{SOURCE1} %{buildroot}/usr/share/kibana/data/prebuilt-dashboards.ndjson # Override the default kibana.yml with our import-enabled config install -Dm 644 %{SOURCE2} %{buildroot}/etc/kibana/kibana.yml %files /usr/share/kibana/data/prebuilt-dashboards.ndjson /etc/kibana/kibana.yml
Step 3: Prepare the Custom kibana.yml
Use the same import configuration as the Docker workflow, plus any default Kibana settings you need:
xpack.savedObjects.import.enabled: true xpack.savedObjects.import.path: /usr/share/kibana/data/prebuilt-dashboards.ndjson xpack.savedObjects.import.overwrite: true # Add other default settings from /etc/kibana/kibana.yml here
Step 4: Build & Install the RPM
Use rpmbuild to package your custom Kibana:
# Place source files in the rpmbuild SOURCES directory cp prebuilt-dashboards.ndjson kibana.yml ~/rpmbuild/SOURCES/ cp kibana-%{version}-x86_64.rpm ~/rpmbuild/SOURCES/ # Build the RPM rpmbuild -ba my-custom-kibana.spec
Install and test the package:
rpm -ivh ~/rpmbuild/RPMS/x86_64/my-custom-kibana-8.11.3-1.el8.x86_64.rpm systemctl start kibana
Navigate to Kibana in your browser—your prebuilt dashboards will be waiting.
- Version Lock: Always use the exact same Kibana version for exporting saved objects and building your package/image. Saved objects often break across major versions.
- Dependency Checks: Double-check that you exported all related objects (index patterns, searches, visualizations) — missing these will leave your dashboards empty or broken.
- Clean Environment Testing: Test your image/RPM in a fresh environment to ensure no hidden dependencies are missing.
内容的提问来源于stack exchange,提问作者sillydeedee

