Kylin ARM System: Compile Zabbix-Agent RPM Package from Source in 3 Steps!

Compile Zabbix-Agent RPM Package from Source in 3 Steps!

1. Why Compile “RPM from Source”?

For various domestic ARM architectures, including Kylin, finding a compatible Zabbix-Agent RPM package is extremely difficult. Compiling from source into an RPM package is the way to go — it not only matches the system architecture but also allows for unified management of installation/uninstallation. When deploying multiple machines later, you can simply transfer the RPM package for use, significantly enhancing operational efficiency!

2. Preparation: 3 Core Files/Tools

  1. 1. System Environment Requirements
  • • ARM Linux System (Kylin, Euler, or Tongxin are all acceptable)
  • • Must have root access
  • • Install dependencies in advance:<span>yum install -y rpm-build gcc make pkgconfig openssl-devel</span>
  • • Download & Organize Files

First, place the files according to the rpmbuild standard directory structure. The final directory structure is as follows (just copy it):

1. Create rpmbuild standard directory
mkdir -p ~/rpmbuild/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS}
2. Download Zabbix source package (official website https://cdn.zabbix.com/zabbix/sources/stable/)
Place it in the source directory ~/rpmbuild/SOURCES/
3. Prepare 3 key configuration files (copy directly to the SOURCES directory)
① zabbix-agent.service (systemd service file)
② zabbix_agentd.conf (Agent configuration file)
③ zabbix-tmpfiles.conf (temporary directory configuration for generating pid file storage location)
The final SOURCES directory is as follows:
ls ~/rpmbuild/SOURCES/
zabbix-5.0.45.tar.gz  zabbix-agent.service  zabbix_agentd.conf  zabbix-tmpfiles.conf

Overall directory structure
[root@c7tmpl ~]# tree rpmbuild/
rpmbuild/
├── BUILD
├── BUILDROOT
├── RPMS
├── SOURCES
│   ├── zabbix-5.0.45.tar.gz
│   ├── zabbix_agentd.conf
│   ├── zabbix-agent.service
│   └── zabbix-tmpfiles.conf
├── SPECS
│   └── zabbix-agent.spec
└── SRPMS

6 directories, 5 files
[root@c7tmpl ~]#

3. Core Steps: Write Spec File + Compile RPM

  1. 1. Write zabbix-agent.spec (Key!)

Create a new file named<span>zabbix-agent.spec</span> in the<span>~/rpmbuild/SPECS/</span> directory, and copy the content below (already adapted for Kylin ARM; other versions only need to modify the version number):

Name: zabbix-agent
Version: 5.0.45
Release: 1%{?dist}
Summary: Zabbix Agent for arm kylinux

Group: Applications/System
License: GPLv2
URL: https://www.zabbix.com
Source0: zabbix-5.0.45.tar.gz
Source1: zabbix-agent.service
Source2: zabbix_agentd.conf
Source3: zabbix-tmpfiles.conf

BuildRequires: gcc, make, pkgconfig, openssl-devel
Requires: openssl
Requires(post): systemd
Requires(preun): systemd
Requires(postun): systemd

%description
Zabbix Agent for monitoring system metrics and communicating with Zabbix Server.
Includes zabbix_get and zabbix_sender utilities.

%prep
%setup -q -n zabbix-5.0.45

%build
./configure --prefix=/usr/local/zabbix --enable-agent
make %{?_smp_mflags}

%install
# Create necessary directory structure
mkdir -p %{buildroot}/usr/local/zabbix/sbin
mkdir -p %{buildroot}/usr/local/zabbix/bin
mkdir -p %{buildroot}/usr/local/zabbix/etc
mkdir -p %{buildroot}/var/log/zabbix
mkdir -p %{buildroot}/usr/lib/systemd/system
mkdir -p %{buildroot}/usr/lib/tmpfiles.d

# Install compiled files
make install DESTDIR=%{buildroot}

# Remove unnecessary help files
rm -rf %{buildroot}/usr/local/zabbix/share
rm -rf %{buildroot}/usr/local/zabbix/include

# Install configuration files, service files, and tmpfiles configuration
install -D -m 640 %{SOURCE2} %{buildroot}/usr/local/zabbix/etc/zabbix_agentd.conf
install -D -m 644 %{SOURCE1} %{buildroot}/usr/lib/systemd/system/zabbix-agent.service
install -D -m 644 %{SOURCE3} %{buildroot}/usr/lib/tmpfiles.d/zabbix-agent.conf

# Set correct file permissions
chmod 755 %{buildroot}/usr/local/zabbix/sbin/zabbix_agentd
chmod 755 %{buildroot}/usr/local/zabbix/bin/zabbix_get
chmod 755 %{buildroot}/usr/local/zabbix/bin/zabbix_sender
chmod 750 %{buildroot}/usr/local/zabbix/etc/zabbix_agentd.conf

%pre
# Before the software package installation (pre-install), create zabbix user and group
getent group zabbix &gt;/dev/null || groupadd -r zabbix
getent passwd zabbix &gt;/dev/null || \
    useradd -r -g zabbix -d /var/lib/zabbix -s /sbin/nologin \
    -c "Zabbix Monitoring System" zabbix

%post
# After the software package installation (post-install), set directory permissions
chown -R zabbix:zabbix /var/log/zabbix
chmod 755 /var/log/zabbix

# Create runtime directory
mkdir -p /run/zabbix
chown zabbix:zabbix /run/zabbix
chmod 755 /run/zabbix

# Apply tmpfiles configuration
systemd-tmpfiles --create /usr/lib/tmpfiles.d/zabbix-agent.conf 2&gt;/dev/null || :

# Reload systemd configuration
systemctl daemon-reload &gt;/dev/null 2&gt;&amp;1 || :

# Enable service (start on boot)
systemctl enable zabbix-agent.service &gt;/dev/null 2&gt;&amp;1 || :

# Start service
systemctl start zabbix-agent.service &gt;/dev/null 2&gt;&amp;1 || :

%preun
# Before uninstalling the package, stop the service
systemctl stop zabbix-agent.service &gt;/dev/null 2&gt;&amp;1 || :
systemctl disable zabbix-agent.service &gt;/dev/null 2&gt;&amp;1 || :

%postun
# After uninstalling the package, reload systemd configuration
systemctl daemon-reload &gt;/dev/null 2&gt;&amp;1 || :

%clean
# Clean up build directory after RPM package is built
rm -rf %{buildroot}

%files
%defattr(-,root,root,-)

# Main program - Zabbix Agent
%attr(755,root,root) /usr/local/zabbix/sbin/zabbix_agentd

# Utility programs
%attr(755,root,root) /usr/local/zabbix/bin/zabbix_get
%attr(755,root,root) /usr/local/zabbix/bin/zabbix_sender

# Configuration files
%config(noreplace) %attr(640,root,zabbix) /usr/local/zabbix/etc/zabbix_agentd.conf

# systemd service file
%attr(644,root,root) /usr/lib/systemd/system/zabbix-agent.service

# tmpfiles configuration file
%attr(644,root,root) /usr/lib/tmpfiles.d/zabbix-agent.conf

# Directory declarations
%dir %attr(755,zabbix,zabbix) /var/log/zabbix/
%dir %attr(755,root,root) /usr/local/zabbix/
%dir %attr(755,root,root) /usr/local/zabbix/bin/
%dir %attr(755,root,root) /usr/local/zabbix/sbin/
%dir %attr(755,root,root) /usr/local/zabbix/etc/
  • • One-click Compile RPM Package

Switch to the SPECS directory and execute the compile command, waiting 1-2 minutes (depending on server performance):

# Core compile command (-bb indicates only generate binary RPM)
rpmbuild -bb ~/rpmbuild/SPECS/zabbix-agent.spec

After successful compilation, the RPM package will be generated in ~/rpmbuild/RPMS/arm64/ (default path for Kylin ARM architecture):

ls ~/rpmbuild/RPMS/arm64/
# zabbix-agent-5.0.45-1.el7.arm64.rpm  # This is the final RPM package!

4. Verification: Install + Check Status

Test the installation of the compiled RPM package to see if it runs normally and starts automatically on boot:

# Install RPM package
[root@c7tmpl ~]# rpm -ivh ~/rpmbuild/RPMS/arm64/zabbix-agent-5.0.45-1.el7.arm64.rpm
Preparing...                          ################################# [100%]
Upgrading/Installing...
   1:zabbix-agent-6.0.41-1.el7        ################################# [100%]
[root@c7tmpl ~]# systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Agent
   Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; enabled; vendor preset: disabled)
   Active: active (running) since Thu 2025-08-25 21:24:48 CST; 11s ago
  Process: 1596 ExecStart=/usr/local/zabbix/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS)
 Main PID: 1598 (zabbix_agentd)
   CGroup: /system.slice/zabbix-agent.service
           ├─1598 /usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
           ├─1599 /usr/local/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
           ├─1600 /usr/local/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
           ├─1601 /usr/local/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
           ├─1602 /usr/local/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
           └─1603 /usr/local/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]

Aug 25 21:24:48 c7tmpl systemd[1]: Starting Zabbix Agent...
Aug 25 21:24:48 c7tmpl systemd[1]: Started Zabbix Agent.
# You can see the service is automatically active and enabled

5. Common Pitfalls & Solutions

  1. 1. Compilation Error: “Missing openssl-devel”: Execute yum install -y openssl-devel to install the dependency
  2. 2. Service Start Failure: “Directory does not exist”: Manually create /run/zabbix and chown zabbix:zabbix /run/zabbix
  1. 3. RPM Package Not Found: Ensure the compile command is rpmbuild -bb (not -ba), and the path is under RPMS/arm64

6. Summary

Compiling the Zabbix-Agent RPM package for Kylin ARM system boils down to 3 core steps:Set up directory → Write spec → Run compile. The compiled RPM package can be directly copied to other Kylin ARM machines for installation without reconfiguration, effectively doubling operational efficiency!

If you encounter any issues, feel free to leave a comment, and we can troubleshoot together~

Leave a Comment