Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Building RPM Packages for Prometheus Node Exporter Binaries on RHEL Systems

Tech 1

Standardizing binary distributions in to native system packages reduces manual overhead and simplifies lifecycle management. This workflow demonstrates packaging the Prometheus node_exporter executable for Rocky Linux 9, replacing tedious extraction steps with automated installation procedures.

Environment: OS: Rocky Linux 9.2 Binary Asset: node_exporter-1.7.0.linux-amd64.tar.gz

Prerequisites

Install the necessary development utilities to generate RPM artifacts.

dnf install rpm-build rpmdevtools -y

Directory Initialization

Run the setup command to create the standard build tree within your user home directory.

rpmdev-setuptree

The resulting hierarchy includes directories for source files, specifications, and built binaries:

~/rpmbuild/
├── SOURCES     # Source archives and patches
├── SPECS       # Package definition files
└── RPMS        # Compiled binary packages

Asset Preparation

Move the compiled archive into the sources directory. Create a corresponding systemd unit file to ensure service integration upon installation.

~/rpmbuild/SOURCES/
├── node_exporter-1.7.0.linux-amd64.tar.gz
└── exporter.service

Systemd Unit Definition (exporter.service):

[Unit]
Description=Prometheus Node Exporter
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/local/bin/node_exporter
Restart=on-failure

[Install]
WantedBy=multi-user.target

Specification File Creation

Define the package logic in ~/rpmbuild/SPECS/node_exporter.spec. This text-based recipe controls how files are staged, installed, and verified.

Name:           node_exporter
Version:        1.7.0
Release:        1%{?dist}
Summary:        Hardware metrics collector
License:        ASL 2.0
URL:            https://prometheus.io/
Source0:        %{name}-%{version}.linux-amd64.tar.gz

Requires:       libc.so.6

%description
Provides hardware and OS metrics exposed by *NIX kernels.

%prep
# Extract archive quietly to build directory
%setup -q -n %{name}-%{version}.linux-amd64

%install
# Copy binary to execution path
mkdir -p %{buildroot}/usr/local/bin
install -p -m 755 node_exporter %{buildroot}/usr/local/bin/node_exporter

# Configure systemd service
mkdir -p %{buildroot}/usr/lib/systemd/system
install -m 644 %{_sourcedir}/exporter.service %{buildroot}/usr/lib/systemd/system/exporter.service

%files
/usr/local/bin/node_exporter
/usr/lib/systemd/system/exporter.service

%changelog
* Mon Apr 20 2024 System Admin - 1.7.0-1
- Initial RPM build for RHEL-based systems

Build Execution

Compile the specification into a binary RPM using the -ba flag (build all).

rpmbuild -ba ~/rpmbuild/SPECS/node_exporter.spec

Deployment

Locate the ganerated RPM in RPMS/x86_64. Deploy using the distribution manager.

dnf install ~/rpmbuild/RPMS/x86_64/node_exporter-1.7.0-1.el9.x86_64.rpm
systemctl start node_exporter

Networked environments automatically fetch required library dependencies. For disconnected workstations, pre-resolve these requirements before transfer.

Offline Dependency Handling

Inspect the package without installing to reveal missing libraries:

dnf install node_exporter-1.7.0-1.el9.x86_64.rpm --show-duplicates

Collect dependencies into a temporary repository folder:

dnf download --resolve --downloaddir=/repo/packages node_exporter-1.7.0-1.el9.x86_64.rpm

Transfer both the package and dependencies to the target host. Execute a local transaction from the directory containing all RPM files:

cd /repo/packages
dnf localinstall ./*.rpm

Alternatively, mount this directory as a custom repository to enable direct installs from the local cache.

Key Specification Directives

  • Metadata: Fields like Version and Release define identity.
  • Sources: Source0 references the input archive.
  • Staging: %prep unpacks data; %install places files into the roootfs for packaging.
  • Manifest: %files explicitly declares included artifacts.
  • Logging: %changelog tracks version history.
Tags: packaging

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.