Skip to content

Commit ec1d8a9

Browse files
committed
PS-9608 [DOCS] - How to build RPM packages from PS source code
On branch ps-9608 new file: docs/build-rpm-packages.md
1 parent 77fd55e commit ec1d8a9

File tree

1 file changed

+338
-0
lines changed

1 file changed

+338
-0
lines changed

docs/build-rpm-packages.md

+338
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
# Build from RPM packages
2+
3+
This guide provides step-by-step instructions for building Percona Server for MySQL from source and packaging it as an RPM package. The guide covers setting up the build environment, downloading the source code, creating a SPEC file, building the RPM package, and verifying the installation.
4+
5+
## Prerequisites
6+
7+
```{.bash data-prompt="$"}
8+
# Install build dependencies
9+
sudo yum groupinstall "Development Tools"
10+
sudo yum install \
11+
cmake \
12+
openssl-devel \
13+
libaio-devel \
14+
ncurses-devel \
15+
boost-devel \
16+
rpmdevtools \
17+
rpmlint \
18+
systemd-devel \
19+
vim-common
20+
```
21+
22+
The `yum groupinstall` command installs a group of development tools using the yum package manager. The "Development Tools" group includes essential compilers, debuggers, and other tools required for building software.
23+
24+
The `yum install` command installs additional packages required for building Percona Server for MySQL. These packages include CMake, OpenSSL development libraries, libaio development libraries, ncurses development libraries, Boost development libraries, rpmdevtools, rpmlint, systemd development libraries, and vim-common.
25+
26+
## Setup RPM Build Environment
27+
28+
These commands set up the necessary directory structure for building RPM packages.
29+
30+
```{.bash data-prompt="$"}
31+
# Create RPM build directory structure
32+
rpmdev-setuptree
33+
34+
# Directory structure created:
35+
# ~/rpmbuild/
36+
# ├── BUILD
37+
# ├── RPMS
38+
# ├── SOURCES
39+
# ├── SPECS
40+
# └── SRPMS
41+
```
42+
43+
The `rpmdev-setuptree` command creates the necessary directory structure for building RPM packages. The structure includes the following directories:
44+
45+
* `BUILD`: Where the build process takes place.
46+
47+
* `RPMS`: Where the finished RPM packages are stored.
48+
49+
* `SOURCES`: Where the source tarballs and other sources are stored.
50+
51+
* `SPECS`: Where the SPEC files are stored.
52+
53+
* `SRPMS`: Where the source RPM packages are stored.
54+
55+
## Download and Prepare Source
56+
57+
These commands help you download the necessary source files and libraries required to build Percona Server for MySQL.
58+
59+
```{.bash data-prompt="$"}
60+
# Download Percona Server source
61+
cd ~/rpmbuild/SOURCES
62+
wget https://downloads.percona.com/downloads/Percona-Server-8.0/Percona-Server-{{release}}/source/tarball/percona-server-8.0.40.tar.gz
63+
```
64+
65+
Change to the `SOURCES` directory within your rpmbuild environment using the cd command. Then, use the `wget` command to download the Percona Server source tarball from the specified URL. This tarball contains the source code needed to build Percona Server.
66+
67+
```{.bash data-prompt="$"}
68+
# Download boost if not included
69+
wget https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0.tar.gz
70+
```
71+
72+
Use the `wget` command to download the Boost library tarball from the specified URL. Boost provides a set of libraries that help with various programming tasks, and you need it for building Percona Server if it's not already included in the source.
73+
74+
## Create SPEC File
75+
76+
This SPEC file automates the process of building, installing, and packaging Percona Server for MySQL into an RPM package, ensuring that all necessary steps and dependencies are properly managed.
77+
78+
Create `~/rpmbuild/SPECS/percona-server-8.0.spec`:
79+
80+
```text
81+
%define mysql_version {{tag}}
82+
%define rpm_version {{tag}}
83+
84+
Name: percona-server
85+
Version: %{mysql_version}
86+
Release: 1%{?dist}
87+
Summary: Percona Server for MySQL
88+
License: GPL-2.0
89+
90+
Source0: percona-server-%{mysql_version}.tar.gz
91+
Source1: boost_1_77_0.tar.gz
92+
93+
BuildRequires: cmake
94+
BuildRequires: openssl-devel
95+
BuildRequires: libaio-devel
96+
BuildRequires: ncurses-devel
97+
BuildRequires: systemd-devel
98+
BuildRequires: boost-devel
99+
100+
%description
101+
Percona Server for MySQL is a free, fully compatible, enhanced, and open source drop-in replacement for MySQL.
102+
103+
%prep
104+
%setup -q -n percona-server-%{mysql_version}
105+
106+
%build
107+
mkdir build
108+
cd build
109+
cmake .. \
110+
-DCMAKE_INSTALL_PREFIX=/usr \
111+
-DINSTALL_LAYOUT=RPM \
112+
-DWITH_SSL=system \
113+
-DWITH_BOOST=../../boost_1_77_0 \
114+
-DWITH_SYSTEMD=1
115+
116+
make %{?_smp_mflags}
117+
118+
%install
119+
cd build
120+
make DESTDIR=%{buildroot} install
121+
122+
%files
123+
%{_bindir}/*
124+
%{_sbindir}/*
125+
%{_libdir}/*
126+
%{_datadir}/*
127+
%{_sysconfdir}/*
128+
%{_unitdir}/*
129+
130+
%post
131+
/sbin/ldconfig
132+
%systemd_post mysqld.service
133+
134+
%preun
135+
%systemd_preun mysqld.service
136+
137+
%postun
138+
/sbin/ldconfig
139+
%systemd_postun_with_restart mysqld.service
140+
```
141+
142+
The provided SPEC file outlines the instructions to build and package Percona Server for MySQL as an RPM package. Here's a breakdown of what each section does:
143+
144+
1. **Definitions**:
145+
```plaintext
146+
%define mysql_version 8.0.40
147+
%define rpm_version 8.0.40
148+
```
149+
These lines define variables for the MySQL and RPM version numbers.
150+
151+
2. **Package Information**:
152+
```plaintext
153+
Name: percona-server
154+
Version: %{mysql_version}
155+
Release: 1%{?dist}
156+
Summary: Percona Server for MySQL
157+
License: GPL-2.0
158+
```
159+
This section provides metadata about the package, including its name, version, release number, summary, and license.
160+
161+
3. **Sources**:
162+
```plaintext
163+
Source0: percona-server-%{mysql_version}.tar.gz
164+
Source1: boost_1_77_0.tar.gz
165+
```
166+
These lines specify the source tarballs needed to build the package.
167+
168+
4. **Build Requirements**:
169+
```plaintext
170+
BuildRequires: cmake
171+
BuildRequires: openssl-devel
172+
BuildRequires: libaio-devel
173+
BuildRequires: ncurses-devel
174+
BuildRequires: systemd-devel
175+
BuildRequires: boost-devel
176+
```
177+
This section lists the packages required to build the software.
178+
179+
5. **Description**:
180+
```plaintext
181+
%description
182+
Percona Server for MySQL is a free, fully compatible, enhanced, and open source drop-in replacement for MySQL.
183+
```
184+
A brief description of the package.
185+
186+
6. **Preparation**:
187+
```plaintext
188+
%prep
189+
%setup -q -n percona-server-%{mysql_version}
190+
```
191+
This section sets up the build environment by extracting the source tarball.
192+
193+
7. **Build**:
194+
```plaintext
195+
%build
196+
mkdir build
197+
cd build
198+
cmake .. \
199+
-DCMAKE_INSTALL_PREFIX=/usr \
200+
-DINSTALL_LAYOUT=RPM \
201+
-DWITH_SSL=system \
202+
-DWITH_BOOST=../../boost_1_77_0 \
203+
-DWITH_SYSTEMD=1
204+
make %{?_smp_mflags}
205+
```
206+
This section compiles the software using CMake and Make, with specific build options.
207+
208+
8. **Installation**:
209+
```plaintext
210+
%install
211+
cd build
212+
make DESTDIR=%{buildroot} install
213+
```
214+
This section installs the compiled software into a build root directory.
215+
216+
9. **Files**:
217+
```plaintext
218+
%files
219+
%{_bindir}/*
220+
%{_sbindir}/*
221+
%{_libdir}/*
222+
%{_datadir}/*
223+
%{_sysconfdir}/*
224+
%{_unitdir}/*
225+
```
226+
This section lists the files and directories included in the package.
227+
228+
10. **Post-Installation and Pre-Uninstallation Scripts**:
229+
```plaintext
230+
%post
231+
/sbin/ldconfig
232+
%systemd_post mysqld.service
233+
234+
%preun
235+
%systemd_preun mysqld.service
236+
237+
%postun
238+
/sbin/ldconfig
239+
%systemd_postun_with_restart mysqld.service
240+
```
241+
These scripts handle tasks to be performed after installation and before and after uninstallation, such as updating the shared library cache and managing the `mysqld` service with systemd.
242+
243+
244+
## Build RPM Package
245+
246+
These commands help you build and verify RPM packages from a downloaded Percona Server for MySQL tar file. The first command builds the package, while the second command checks the directory to confirm that the packages are created successfully.
247+
248+
```{.bash data-prompt="$"}
249+
# Build the RPM package
250+
cd ~/rpmbuild
251+
rpmbuild -ba SPECS/percona-server-8.0.spec
252+
```
253+
254+
First, change to the rpmbuild directory with the `cd` command. Then, use the `rpmbuild -ba` command to build the RPM package based on the percona-server-8.0.spec file located in the SPECS directory. The `-ba` option tells rpmbuild to build both the binary and source RPM packages.
255+
256+
```{.bash data-prompt="$"}
257+
# Check for built packages
258+
ls -l RPMS/x86_64/
259+
```
260+
261+
This command lists the contents of the RPMS/x86_64 directory to verify that the built RPM packages are present. The `ls -l` command lists the files in the directory, and the `RPMS/x86_64/` argument specifies the directory to list.
262+
263+
## Important Build Configuration Options
264+
265+
These CMAKE options help configure the build process according to your specific requirements, ensuring that the software is installed and functions correctly on your system.
266+
267+
- `-DCMAKE_INSTALL_PREFIX=/usr`: Installation directory
268+
- `-DINSTALL_LAYOUT=RPM`: RPM-specific installation layout
269+
- `-DWITH_SSL=system`: Use system OpenSSL
270+
- `-DWITH_BOOST`: Path to Boost library
271+
- `-DWITH_SYSTEMD=1`: Enable systemd support
272+
273+
These commands are CMake options used to customize the build process for your project. Here is what each one does:
274+
275+
| Option | Description |
276+
|-------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
277+
| **`-DCMAKE_INSTALL_PREFIX=/usr`** | This option sets the installation directory to `/usr`. When you install the software, the files will be placed in the `/usr` directory. |
278+
| **`-DINSTALL_LAYOUT=RPM`** | This option specifies the installation layout for RPM packages. It ensures that the files are organized in a way that is compatible with RPM packaging standards. |
279+
| **`-DWITH_SSL=system`** | This option tells CMake to use the system's OpenSSL library. Instead of compiling and using a separate OpenSSL library, it will use the one already installed on your system. |
280+
| **`-DWITH_BOOST`** | This option sets the path to the Boost library. It ensures that CMake can find and use the Boost libraries during the build process. |
281+
| **`-DWITH_SYSTEMD=1`** | This option enables support for systemd, the system and service manager for Linux operating systems. It allows the software to integrate with systemd for service management. |
282+
283+
284+
285+
286+
## Verification Steps
287+
288+
These commands help you verify the integrity of the RPM package and check for any dependencies, and ensures a smooth installation process.
289+
290+
```{.bash data-prompt="$"}
291+
# Check RPM package integrity
292+
rpm -Kv RPMS/x86_64/percona-server-*.rpm
293+
```
294+
295+
This command verifies the integrity of the built RPM package. The `-K` option stands for check, and `-v` is for verbose output.
296+
297+
```{.bash data-prompt="$"}
298+
# Check package dependencies
299+
rpm -qpR RPMS/x86_64/percona-server-*.rpm
300+
```
301+
302+
This command lists the dependencies required by the built RPM package. The `-qpR` option queries the package for its dependencies.
303+
304+
## Installation Test
305+
306+
These steps help you install and verify the Percona Server package on your system, and ensures everything is set up correctly.
307+
308+
```{.bash data-prompt="$"}
309+
# Install built package
310+
sudo rpm -ivh RPMS/x86_64/percona-server-*.rpm
311+
```
312+
313+
This command installs the built Percona Server package. The `-i` option stands for install, `-v` for verbose, and -h shows hash marks as the package installs. Using `sudo` ensures you have the necessary administrative privileges.
314+
315+
# Verify installation
316+
317+
```{.bash data-prompt="$"}
318+
rpm -qa | grep percona-server
319+
mysqld --version
320+
```
321+
322+
This command has the following options:
323+
324+
`rpm -qa | grep percona-server`: This command lists all installed packages and filters the list to show only those related to Percona Server. The `rpm -qa` command queries all installed RPM packages, and `grep percona-server` searches for Percona Server entries.
325+
326+
`mysqld --version`: This command displays the installed version of the MySQL server, confirming the successful installation of Percona Server.
327+
328+
## Troubleshooting
329+
330+
The following are common issues encountered during the RPM build process:
331+
332+
333+
| Issue | Troubleshooting Steps |
334+
|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------|
335+
| **Missing dependencies** | ```bash $ # Install additional dependencies if needed sudo yum-builddep SPECS/percona-server-8.0.spec ``` |
336+
| **Build failures** | - Check build logs in `~/rpmbuild/BUILD/` <br> - Verify all build dependencies are installed <br> - Ensure enough disk space is available |
337+
| **Version mismatches** | - Double-check version numbers in SPEC file <br> - Verify source tarball version matches SPEC file |
338+

0 commit comments

Comments
 (0)