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

table of contents
Introduction
It's been a while.
I'm Mikoto, a 2024 graduate, and I'm starting to feel a bit anxious as my junior colleagues' training is almost over.
I only recently learned about from someone in the company rpmbuild, which I'd like to talk about
At the time CentOS 7 on a Redis 8 , I was looking into how to install
"I think I made a .rpm a while back."
I heard something quite shocking. (Please forgive me, as I'm still a novice.)
So, I decided to use a test environment to actually create an RPM using rpmbuild and perform a local installation.I'd like to share the process and the problems I encountered!
About the environment
environment
I'm using Vagrant.
I've also included a link, so if you've never used Vagrant before, please give it a try!
- Virtual Box:Oracle VM VirtualBox
- Vagrant:Vagrant by HashiCorp
- OS:Oracle Linux 7.9
(I'm also working on a blog on how to set up an environment using Vagrant.)
A great senior colleague has previously provided an explanation of Vagrant, sothatout as well!
How to create your own testing environment using the command line tool Vagrant
Setting up the rpmbuild environment
for setting up the rpmbuild environment This was helpful
I started with absolutely no knowledge, so I didn't even know the structure at the time... (^ ^ ;)
# Install the required tools $ sudo yum install rpmdevtools yum-utils # Build the rpmbuild environment $ rpmdev-setuptree
Once you've finished setting up rpmbuild, you'll see a directory structure like this.
You might be thinking, "Ugh," but basically, 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 struggle, I finally arrived at the following structure under ~/rpmbuild.
I haven't touched anything after that, as I believe it was automatically added during the build process. (Probably)
SOURCES ├ redis-8.0.2.tar.gz ├ redis.conf └ redis.service SPECS └ redis-8.0.2.spec
Before doing this, I simply tried compiling redis-8.0.2.tar.gz, but it seemed that registering the systemctl unit also had to be done manually, so this time I've made sure the redis.service file is also applied during installation.
Also, although a conf file existed in the archive, the data location was different, so this time I've included a redis.conf file that I prepared myself to refer to 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 naively the rpmbuild command, thinking that building redis-8.0.2.tar.gz would create an .rpm file! executed
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 simply what I thought.
After doing some research, I realized I had to create it myself.
What is a spec file?
A spec file isa file that describes how to build an RPM package. It includes
the actual build procedure, the location of the package's configuration file, registration with systemctl, and so on.
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 ★
the documentation, it seems like you can create the types using commands, rather than having to do it entirely manually...?
I'll keep that in mind for next time (muttering to myself).
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 others as needed # BuildRequires: make, systemd, etc. # (Optional) Dependencies required at runtime # 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 tar.gz %setup -q -n redis-8.0.2 %build # Build Redis make %install # Clean up buildroot rm -rf %{buildroot} # Create directory for 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 the systemd unit # %{_unitdir} is usually extracted to /usr/lib/systemd/system mkdir -p %{buildroot}%{_unitdir} install -p -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/redis.service %files # Binary /usr/bin/redis-server /usr/bin/redis-cli # Configuration file (use the noreplace option to prevent 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 new installations /bin/systemctl enable redis.service &>/dev/null || : fi # Initialize (reload) systemd after installation/updates /bin/systemctl daemon-reload &>/dev/null || : %preun # Package removal process if [ $1 -eq 0 ] ; then # Stop/disable the service only during uninstallation /bin/systemctl stop redis.service &>/dev/null || : /bin/systemctl disable redis.service &>/dev/null || : fi %postun # Processing after uninstallation/update /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.
mentioned earlier SOURCES and SPEC , let's review the contents of
As I'll write about later as a memo, it's crucial to carefully check the contents of each SOURCES, as neglecting to do so can lead to serious problems (a word of caution).
SOURCES ├ redis-8.0.2.tar.gz ├ redis.conf └ redis.service SPECS └ redis-8.0.2.spec
Try building it
The command actually used for the build is below. A
.rpm file is created based on the generated spec file.
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, put in some random data.
There's no point in updating if your data is lost!
↑Someone who lost data multiple 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.
Let's confirm that it's there and proceed with the installation!
# 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!
"Complete! It says
But now the problem is... will it actually start up...?
● 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 8.0.2 is
# 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,issues where errors would appear during the build process,created issues that I wouldn't notice until after installing thethere were
Actually, the issues that caused errors were easier to fix, but there were many times when applying a package that built without any problems required various adjustments.
I'm summarizing this here as a warning to be more careful next time
%Changelog date should be written correctly
In a spec file, %changelog is where you enter the date.
You enter the date, name, email address, and version, like this:
%changelog * Thu Jun 13 2025 Test Taro <[email protected]> - 8.0.2-1
And here's a common error that occurred: [error message].
It's hard to tell what's wrong just from this, isn't it?
RPM build errors: bogus date in %changelog: Thu Jun 13 2025 Test Taro <[email protected]> - 8.0.2-1
The correct answer is here:
"Thu Jun 13 2025"
June 13, 2025a Friday.
Therefore, it"Fri Jun 13 2025"should have been
Even small mistakes like this can cause errors to appear for a long time, 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
of the conf file that would be replaced when updating the package I created the port number and data storage directory I should have carefully checked
The mistakes I made are listed below
- Because different ports were specified,separate Redis instances started on ports 6379 and 6380.
- because the save destination directory was incorrect.The data was saved to a different directory than intended
▼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 expected to be able to use commands like `redis-server` and `redis-cli`, but I was wrong. There
weren't any errors or anything, but I only realized this after actually applying 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
So, what did you think?
This time, I wrote about the process of creating an RPM package 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!
4
