In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about how to create a rpm package according to the source package under CentOS/RedHat, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
Sometimes you may need to get a source package for an open source application, but you may not be able to install it to the system through the application's RPM file.
In this case, you can either compile the source installation or create a rpm package file with the source package to install the application.
There is also a situation where you want to create a custom RPM package that you develop yourself.
In order to create the rpm package, you will need the source package (usually a compressed file that also contains the SPEC file).
The SPEC file contains the following instructions: how to create the rpm package, the files contained in the package, and the path to the installation.
RPM will show the testing process during the creation process.
Execute the system commands and macro commands defined in the prep block in the spec file.
Detect the contents of the file list
Execute the system commands and macro commands defined in the build block in the spec file. In this step, the macro command in the file list is also executed.
Create a binary package file
Create a source package file
Once RPM has performed the above steps, a binary package file and a source package file will be created.
Binary package file A source file that contains all additional information about installing or uninstalling the package.
Usually all the options for installing the package are platform-specific. The binary package file contains a complete application or library compiled for a particular structure. The source package usually contains the original compressed tar file, spec file, and patches related to the creation of the binary package.
Let's use the tar file to see how to create a simple source and binary RPM package.
If you are new to rpm packages, you should first understand how to install, upgrade and uninstall packages on CentOS/Redhat using the rpm command.
1. Install the rpm-build package
To create a rpm file based on the spec file, we need to use the rpmbuild command.
The rpmbuild command is part of the rpm-build package. The installation process is as follows.
# yum install rpm-build
Rpm-build relies on the following packages. If you haven't installed it yet, install these packages automatically.
Elfutils-libelf rpm rpm-libs rpm-python
2. Create a directory in RPM
The rpm-build command automatically creates the following directory structure during the build phase.
# ls-lF / root/rpmbuild/drwxr-xr-x. 2 root root 4096 Feb 4 12:21 BUILD/drwxr-xr-x. 2 root root 4096 Feb 4 12:21 BUILDROOT/drwxr-xr-x. 2 root root 4096 Feb 4 12:21 RPMS/drwxr-xr-x. 2 root root 4096 Feb 4 12:21 SOURCES/drwxr-xr-x. 2 root root 4096 Feb 4 12:21 SPECS/drwxr-xr-x. 2 root root 4096 Feb 4 12:21 SRPMS/
Note: the above directory structure applies to both CentOS and Redhat. You can also use the / usr/local/redhat command, but you want to modify the topdir parameter during the build phase. If you are using SuSE Enterprise Linux, use the / usr/src/packages directory.
If you want to use your own command structure instead of / root/rpmbuild, you can use the following options:
Use-buildroot to select and define a custom directory in the rpmbuild phase.
Define topdir parameters in a rpmrc file or rpmmacros file
3. Download the source tar file
Next, download the source tar file of the package you want to create and save it in the SOURCES directory.
In this example, I am using the source package of icecase open source software, which is a streaming multimedia server software. But these steps are the same when creating other rpm packages. You only need to download the source package of the software you want.
# cd / root/rpmbuild/SOURCES/# wget http://downloads.xiph.org/releases/icecast/icecast-2.3.3.tar.gz# ls-1 RW Murray. 1 root root 1161774 Jun 11 2012 icecast-2.3.3.tar.gz
4. Create a spec file
In this step, we define the creation process by creating a spec file. This spec file usually contains the following eight different blocks:
The Preamble-preamable block contains information about the package being created and defines related dependencies. It is usually a line that begins with a label message, followed by a colon, followed by some explanatory information.
% prep-in this block, we will prepare the software for the creation process. In the process, any previous creation is deleted, and the source file (. Tar) files are extended, and so on. A more critical thing is to understand that there are predefined macro commands available that can execute various shortcut options to build the rpm package. You may be using this macro command when you try to create a complex package. In the following example, I use a macro named% setup, which removes the previous creation, decompresses the source file, and changes the permissions of the file. You can also use sh scripts in the% prep section to do this, but the% setup macro uses predefined sh scripts to simplify the process.
% description-description blocks usually contain description information for packages
% build-this is the block that actually executes the build instruction. It's usually a sh script.
% install -% install blocks are also executed as sh scripts, just like% prep and% build blocks. The steps in the installation phase at this time
% files-this block contains a series of files for this package. Files that are not in this block will not be available. The requirement is the full path, and in this block you can set the properties and permissions of the file.
% clean-this block is used to clean up other files that are not normally created by the application. For example, if the application creates a temporary directory structure under the / tmp directory during creation, it will not be removed; but if it is defined in that block, the temporary directory will be removed after the correct installation.
Here is the icecast.spec file
# cat / root/rpmbuild/SPECS/icecast.specName: icecast Version: 2.3.3Release: 0Summary: Xiph Streaming media server that supports multiple formats. Group: Applications/Multimedia License: GPL URL: http://www.icecast.org/ Vendor: Xiph.org Foundation team@icecast.org Source: http://downloads.us.xiph.org/releases/icecast/%{name}-%{version}.tar.gz Prefix:% {_ prefix} Packager: Karthik BuildRoot:% {_ tmppath} /% {name}-root% Description Icecast isa streaming media server which currently supports Ogg Vorbisand MP3 audio streams. It can be used to create an Internet radio station or a privately running jukebox and many things in between. It is very versatile in that new formats can be added relatively easily and supports open standards for commuincation and interaction. Prep% setup-Q-n% {name} -% {version}% build CFLAGS= "$RPM_OPT_FLAGS". / configure-- prefix=% {_ prefix}-- mandir=% {_ mandir}-- sysconfdir=/etc make% install ["$RPM_BUILD_ROOT"! = "/"] & & rm-rf $RPM_BUILD_ROOT make DESTDIR=$RPM_BUILD_ROOT install rm-rf $RPM_BUILD_ROOT% {_ datadir} / doc/% {name}% clean [" $RPM_BUILD_ROOT "! =" / "] & & rm-rf $RPM_BUILD_ROOT% files% defattr (- Root,root)% doc README AUTHORS COPYING NEWS TODO ChangeLog% doc doc/*.html% doc doc/*.jpg% doc doc/*.css% config (noreplace) / etc/% {name} .xml% {_ bindir} / icecast% {_ prefix} / share/icecast/*% changelog In this file, under% prep section you may noticed the macro "% setup-Q-n% {name} -% {version}". This macro executes the following command in the background. Cd / usr/src/redhat/BUILD rm-rf icecast gzip-dc / usr/src/redhat/SOURCES/icecast-2.3.3.tar.gz | tar-xvvf-if [$?-ne 0]; then exit $? Fi cd icecast cd / usr/src/redhat/BUILD/icecast chown-R root.root. Chmod-R axiorrX.glichrowfurow.
In the% build section, you will see CFLAGS with configuration options, which defines the options and prefix options that can be used during RPM installation, forcing directories to be used for installation and sysconfig directories, where system files need to be copied.
In this line, you will see the make utility, which determines the list of files that need to be compiled and compiles them appropriately.
In the% installation section, the lines below the% installation of "make install" are used for the binaries compiled from the previous steps and installed or copied to the appropriate location so that they can be accessed.
5. Create a rpm file using the rpmbuild command
Once the SPEC file is ready, you can start using the rpm-b command to build the rpm. The b option is used to perform all stages of the build process. If you see any errors at this stage, you need to resolve it before trying again. Errors are usually library dependencies, which you can download and install when needed.
# cd / root/rpmbuild/SPECS# rpmbuild-ba icecast.specExecuting (% prep): / bin/sh-e / var/tmp/rpm-tmp.Kohe4t + umask 022 + cd / root/rpmbuild/BUILD + cd / root/rpmbuild/BUILD + rm-rf icecast-2.3.3 + / usr/bin/gzip-dc / root/rpmbuild/SOURCES/icecast-2.3.3.tar.gz + / bin/tar-xf-+ STATUS=0 +'[0-ne 0']'+ cd icecast-2 .3.3 + / bin/chmod-Rf a+rX Upright weight, etc. + exit 0 Executing (% build): / bin/sh-e / var/tmp/rpm-tmp.ynm7H7 + umask 022 + cd / root/rpmbuild/BUILD + cd icecast-2.3.3 + CFLAGS='-O2-gags +. / configure-- prefix=/usr-- mandir=/usr/share/man-- sysconfdir=/etc checking for a BSD-compatible install... / usr/bin/install-c checking whether build environment is sane... Yes checking for a thread-safe mkdir-p. / bin/mkdir-p checking for gawk... Gawk checking whether make sets $(MAKE)... Yes checking whether to enable maintainer-specific portions of Makefiles... No checking for gcc... Gcc.. .. .. Wrote: / root/rpmbuild/SRPMS/icecast-2.3.3-0.src.rpm Wrote: / root/rpmbuild/RPMS/x86_64/icecast-2.3.3-0.x86_64.rpm Executing (% clean): / bin/sh-e / var/tmp/rpm-tmp.dzahrv + umask 022 + cd / root/rpmbuild/BUILD + cd icecast-2.3.3 +'['/ root/rpmbuild/BUILDROOT/icecast-2.3.3-0.x86_64 '! =' /']'+ rm-rf / root/rpmbuild/BUILDROOT/icecast-2.3.3-0.x86_64 + exit 0
Note: if you are using SuSE linux, if the rpmbuild tool is not available, try using "rpm-ba" to create the rpm package.
During installation, you may notice the following error message:
Error 1: XSLT configuration file not found
Checking for xslt-config... Noconfigure: error: XSLT configuration could not be founderror: Bad exit status from / var/tmp/rpm-tmp.8J0ynG (% build) RPM build errors: Bad exit status from / var/tmp/rpm-tmp.8J0ynG (% build)
Solution 1: install libxstl-devel
Yum install libxstl-devel
The following dependency packages are installed at the same time:
Libgcrypt
Libgcrypt-devel
Libgpg-error-devel
Error 2: libvorbis error
Checking for libvorbis... Configure: error: must have Ogg Vorbis v1.0 or above installederror: Bad exit status from / var/tmp/rpm-tmp.m4Gk3f (% build)
Solution 2: install libvorbis-devel
Yum install libvorbis-devel
The following dependency packages are installed at the same time:
Libogg
Libogg-devel
Libvorbis
6. Verify source and binary RPM packages
Once the rpmbuild command has finished successfully, you can verify the source RPM package and the binary rpm package file under the following command.
# ls-l / root/rpmbuild/SRPMS/-rw-r--r-- 1 root root 1162483 Aug 25 15:46 icecast-2.3.3-0.src.rpm# ls-l / root/rpmbuild/RPMS/x86_64/-rw-r--r--. 1 root root 349181 Feb 4 12:54 icecast-2.3.3-0.x86_64.rpm7. Install the RPM File to Verify
As a step of * *, you can install the binary package to verify that the installation was successful and that all dependencies are met.
# rpm-ivvh / root/rpmbuild/RPMS/x86_64/icecast-2.3.3-0.x86_64.rpmD: = / root/rpmbuild/RPMS/x86_64/icecast-2.3.3-0.x86_64.rpmD: loading keyring from pubkeys in / var/lib/rpm/pubkeys/*.keyD: couldn't find any keys in / var/lib/rpm/pubkeys/*.keyD: loading keyring from rpmdbD: opening db environment / var/lib/rpm cdb:mpool:joinenvD: opening db index / var/lib/rpm/Packages rdonly mode=0x0D: read h # 210 Header sanity check: OKD: added key gpg-pubkey-c105b9de-4e0fd3a3 to keyringD: Using legacy gpg-pubkey (s) from rpmdbD: Expected size: 349181 = lead (96) + sigs (180) + pad (4) + data (348901) D: Actual size: 349181D: = relocationsD: added binary package [0] D: found 0 source and 1 binary packagesD: = + icecast-2.3.3-0 x86_64/linux 0x2. ..
After the installation is complete, you can verify the success.
# rpm-qa icecasticecast-2.3.3-0.x86_64 after reading the above, do you have any further understanding of how to create a rpm package based on the source package under CentOS/RedHat? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.