[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Osaka/Yokohama/Tokushima] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[Compatible with over 200 countries] Global eSIM “Beyond SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[If you are traveling, business trip, or stationed in China] Chinese SIM service “Choco SIM”

[Global exclusive service] Beyond's MSP in North America and China

[Global exclusive service] Beyond's MSP in North America and China

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

[CentOS7] Rpmbuild Redis 8, which does not have an official RPM for EL7

Introduction

It's been a while.
I'm Mikoto, a graduate of 2024, and I'm starting to feel a bit impatient as my junior colleagues' training is nearing completion
I'd like to talk about rpmbuild, which I learned about for the first time the other day from someone in the company

At the time , I was looking into how to install Redis 8 on a CentOS 7

"I think I made a .rpm a while back."

I was shocked to hear such a thing. (Please forgive me, I'm still a novice.)
So, I used a test environment to actually create an RPM with rpmbuild and install it locally , so I'd like to share the process and the problems I encountered!

About the environment

environment

We use Vagrant.
We have also included a link, so if you have never used Vagrant before, please give it a try!

(I'm also working on a blog on how to set up an environment using Vagrant.)

In the past, a great senior has explained Vagrant, so please take a look at that

How to use a command-line tool called Vagrant to build your own verification environment

Setting up the rpmbuild environment

This was helpful
for building the rpmbuild environment I started with zero knowledge, so I didn't even know the structure at the time, but... (^ ^ ;)

# Install the required tools $ sudo yum install rpmdevtools yum-utils # Build the rpmbuild environment $ rpmdev-setuptree

Once you have completed the rpmbuild setup, the following directory will appear.
You might be thinking, "Huh?", but the only things you need to adjust before building are SOURCES and SPECS.

~/rpmbuild ├ BUILD # Working directory ├ BUILDROOT # Virtual root for temporarily installing the finished product ├ RPMS # Destination for the completed .rpm ├ SOURCES # Destination for input files required for building, such as source archives ├ SPECS # Destination for .spec files └ SRPMS # Destination for .src.rpm

The contents of ~/rpmbuild/ after the final build

After much effort, I finally arrived at the following configuration under ~/rpmbuild.
I haven't touched anything else since it was automatically added during the build. (Probably)

SOURCES ├ redis-8.0.2.tar.gz ├ redis.conf └ redis.service SPECS └ redis-8.0.2.spec

Before doing this, I simply compiled redis-8.0.2.tar.gz, but it seemed that I had to manually register the systemctl Unit, so this time I made sure that the redis.service file was also applied during installation.
Also, although the archive contained a conf file, the data was stored in a different location, so this time I included the redis.conf file I prepared here to reference after installation.

*Note: Before updating, please make sure that Redis is set to persist data.

In my environment, Redis data was set to persist from the beginning, but depending on the settings, if the data isn't persisted and is lost when the system is restarted, a tragedy could occur, so be sure to check!

# redis-cli CONFIG GET save 1) "save" 2) "3600 1 300 100 60 10000"

↑It looks like the RDB snapshot is persisted! If the conditions for when to take the snapshot are not written here, it may not be persisted.

How I found out about SPEC

Failed to read spec file

While checking the procedure, I innocently ran the rpmbuild command thinking, "If I build redis-8.0.2.tar.gz with the rpmbuild command, I'll get an .rpm!"

but……

rpmbuild -tb --clean redis-8.0.2.tar.gz error: Failed to read spec file from redis-8.0.2.tar.gz

 

"What, there's no spec file?"

That's the simple thought I had,
and after some searching I realized I had to create it myself.

What is a spec file?

A spec file is a file that describes how to build an rpm package .
It describes the actual build procedure, the location of the package's conf file, registration with systemctl, etc.

It seems that it is sometimes included in tar.gz, but this time it was not there, so an error occurred.

If it doesn't exist, just make it.

After that, I googled and asked an AI and found out that I could create it manually, so I used all my skills and somehow managed to create a spec file.

After much struggle, I finally managed to build the project by putting the files into the ~/rpmbuild/SPECS directory mentioned at the beginning.

SPECS └ redis-8.0.2.spec ★

From what I saw in
the documentation I'll take a look at that next time (solo talk).

The spec file that was finally successfully updated this time looks like this:

Name: redis Version: 8.0.2 Release: 1%{?dist} Summary: Redis is an in-memory database that persists on disk License: BSD URL: https://redis.io/ Source0: redis-8.0.2.tar.gz # If including redis.service Source1: redis.service # Packages required for building BuildRequires: gcc # Add any others required # BuildRequires: make, systemd, etc. # (Optional) Runtime dependencies # Requires: systemd %description Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. %prep # Extract the tar.gz %setup -q -n redis-8.0.2 %build # Build Redis make %install # Clean up buildroot rm -rf %{buildroot} # Create a directory to place the binaries mkdir -p %{buildroot}/usr/bin # Install pre-built executables install -p -m 0755 src/redis-server %{buildroot}/usr/bin/redis-server install -p -m 0755 src/redis-cli %{buildroot}/usr/bin/redis-cli # Create the /etc/redis directory and place redis.conf in it mkdir -p %{buildroot}/etc/redis install -p -m 0644 %{_sourcedir}/redis.conf %{buildroot}/etc/redis/redis.conf # Place systemd units # %{_unitdir} usually expands to /usr/lib/systemd/system mkdir -p %{buildroot}%{_unitdir} install -p -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/redis.service %files # Binaries /usr/bin/redis-server /usr/bin/redis-cli # Configuration file (noreplace option prevents user edits from being overwritten) %config(noreplace) /etc/redis/redis.conf # systemd unit file %{_unitdir}/redis.service %post # Processing immediately after installation if [ $1 -eq 1 ] ; then # Enable the systemd unit on a fresh install /bin/systemctl enable redis.service &>/dev/null || : fi # Initialize (reload) systemd after installation/update /bin/systemctl daemon-reload &>/dev/null || : %preun # Package removal processing if [ $1 -eq 0 ] ; then # Stop/disable the service only on uninstallation /bin/systemctl stop redis.service &>/dev/null || : /bin/systemctl disable redis.service &>/dev/null || : fi %postun # Post-uninstall/update processing /bin/systemctl daemon-reload &>/dev/null || : %changelog * Sat Jun 14 2025 John Doe < [email protected] > - 8.0.2-1 - Initial build of Redis with systemd unit

Create an rpm and install it

First, check the materials

This is the most important part.
, let's review the contents of
SOURCES and SPEC mentioned above I'll write it down later as a memo, but if you neglect to check the contents of each SOURCE, you'll end up in trouble, so check it carefully (warning).

SOURCES ├ redis-8.0.2.tar.gz ├ redis.conf └ redis.service SPECS └ redis-8.0.2.spec

Try building it

The actual command used for the build is below.
Create an .rpm based on the spec file you created.

rpmbuild -bb /root/rpmbuild/SPECS/redis-8.0.2.spec

* -bb is an option to create only the .rpm file. If necessary, change it to -ba (creates .src.rpm and .rpm), etc.

If the process finishes without errors, the build is complete!

Load the data before updating

Before updating, make sure to input appropriate data.
Even if you can update, it's pointless if the data is lost!
↑ A person who lost data many times during testing

# redis-cli set beyond "24365" # redis-cli get beyond "24365"

Install the resulting .rpm package locally

The completed package was located at ~/rpmbuild/RPMS/x86_64/redis-8.0.2-1.el7.x86_64.rpm.
After confirming that it is installed, let's install it right away!

# yum localinstall ~/rpmbuild/RPMS/x86_64/redis-8.0.2-1.el7.x86_64.rpm Examining ~/rpmbuild/RPMS/x86_64/redis-8.0.2-1.el7.x86_64.rpm: redis-8.0.2-1.el7.x86_64 Marking ~/rpmbuild/RPMS/x86_64/redis-8.0.2-1.el7.x86_64.rpm to be installed Resolving Dependencies --> Running transaction check ---> Package redis.x86_64 0:8.0.2-1.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ====================================================================================== ====================================================================================== Package Arch Version Repository Size ====================================================================================== ====================================================================================== Installing: redis x86_64 8.0.2-1.el7 /redis-8.0.2-1.el7.x86_64 4.4 M Transaction Summary ====================================================================================== ====================================================================================== Install 1 Package Total size: 4.4 M Installed size: 4.4 M Is this ok [y/d/N]: y Downloading packages: Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : redis-8.0.2-1.el7.x86_64 1/1 Verifying : redis-8.0.2-1.el7.x86_64 1/1 Installed: redis.x86_64 0:8.0.2-1.el7 Complete!

It says "
Complete But here's the problem... Will it start properly?

● redis.service - Redis In-Memory Data Store Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled) Active: active (running) since Wed 2025-06-18 00:07:56 UTC; 7h ago Main PID: 1151 (redis-server) CGroup: /system.slice/redis.service mq1151 /usr/local/bin/redis-server 127.0.0.1:6380 Jun 18 00:07:57 ansible-bastion redis-server[1151]: 1151:C 18 Jun 2025 00:07:57.249 * Redis version=8.0.2, bits=64, commit=00000000, modified=1, pid=1151, just started

It's up and running 🎉🎉🎉
and the version is 8.0.2

# redis-cli get beyond "24365"

It seems that the data inside is still intact even after the update!

Spec Memo for adjustment

When creating the spec file, there were
some issues that would produce errors during the build and some that I didn't notice until after I installed the rpm I created The issues that produced errors were actually easy to fix, but there were also many times when I tried to use a package that built without any issues and found that various adjustments were required.

I'm summarizing this here as a warning to be more careful next time.

%Changelog date should be written correctly

The %changelog in the spec file is where you put the date.
Enter the date, name, email address, and version as shown below.

%changelog * Thu Jun 13 2025 Test Taro &amp;lt; [email protected] &amp;gt; - 8.0.2-1

The error that often appears here is the one below.
It's hard to tell what went wrong just from this.

RPM build errors: bogus date in %changelog: Thu Jun 13 2025 Test Taro &amp;lt; [email protected] &amp;gt; - 8.0.2-1

The correct answer is here:
"Thu Jun 13 2025"

June 13, 2025 a Friday .
you should have entered
"Fri Jun 13 2025" here Even a mistake like this will result in a long-running error, so be careful (^^;)

Check the location and content of redis.conf

As with any package, when you upgrade, you make a backup of the conf file and check the differences after the update to make sure there are no major differences and that they have not had any impact.

I should have carefully checked the port number and data storage directory of the conf file that was replaced when updating the package I created

The mistakes I made are listed below.

  • Because different ports were specified, separate Redis instances were started on ports 6379 and 6380.
  • The destination directory was incorrect, so the data was saved in a different directory than expected.

▼Port

# Accept connections on the specified port, default is 6379 (IANA #815344). # If port 0 is specified Redis will not listen on a TCP socket. port 6379

▼Directory

# Note that you must specify a directory here, not a file name. dir /var/lib/redis

Do not change the location of the installed commands

After installing Redis using yum, I thought I could use the redis-server and redis-cli commands, but they didn't work.
I didn't get any errors, but I realized this after I installed them.

Here's the cause.

# Contents of spec file %files /usr/local/bin/redis-server /usr/local/bin/redis-cli # Environment where Redis 7 series to be updated is running /usr/bin/redis-server /usr/bin/redis-cli

If you build in this state and try to use redis-server, this is what happens.

[root@test-web redis]# sudo /usr/local/bin/redis-server /etc/redis.conf --daemonize no sudo: /usr/local/bin/redis-server: command not found

I finally got it in and thought it was working, but then this happens... Let's check the settings carefully.

Conclusion

What do you think?
This time, I wrote about the process of creating an rpm and the problems I encountered.

I thought it would be fun to install an rpm file that I'd customized in various ways and actually use it, but I still haven't really thought of any ways to use it...

I will continue to work hard every day so that I can be of help to someone someday!

If you found this article helpful , please give it a like!
3
Loading...
3 votes, average: 1.00 / 13
83
X facebook Hatena Bookmark pocket
[Webinar] Introduction to Multi-Cloud: Which cloud is best for your business? Get the latest information on the 8 major clouds!

[Webinar] Introduction to Multi-Cloud: Which cloud is best for your business? Get the latest information on the 8 major clouds!

[Webinar] From the operational structure to specific steps! A complete overview of cloud server operation and maintenance

[Webinar] From the operational structure to specific steps! A complete overview of cloud server operation and maintenance

The person who wrote this article

About the author

Mikoto

I am an infrastructure engineer who joined the company in April 2024 from the Faculty of Arts and Sciences.
I couldn't think of a nickname, so I chose one that my mother often uses.
Shoebill storks are cute, aren't they?