Why use RPM to manage software packages? Compared to the use of shell scripts, from the source code to compile the installation, excluding the efficiency factors of the scale, the script is less maintainable than the RPM, of course, using RPM need to understand rpmbuild and spec documents, it seems not easy. But in the long run, the maintainability of RPM and Yum sources is more reliable than "scripting". In this article, the florist shared the steps to create a Yum source to manage "custom" packages on the system.
Creating a Yum source requires an FTP or HTTP service, and the HTTP service is recommended because of the annoying firewall policies of FTP (improper firewall configuration, improper use of the FTP mode-active/initial, service becomes unavailable).
One
1. Managing Yum sources requires a tool Createrepo
Can be installed with Yum:
Yum-y Install Createrepo
1. Plan and create a Yum source directory.
Here we use the HTTP service pattern, so I have a Web service installed.
I created a yum directory under the http://192.168.0.157/directory to hold the Yum source data.
Look at the official Yum Source directory plan, like Yum does not maintain arch itself, that does not differentiate I386 or x86_64 by itself, so it is placed separately in different directories.
Because our servers are all 64-bit, we only create a x64 directory.
I maintain a CentOS Linux 7-based package, and the planning directory is as follows:
Mkdir-p/opt/htdocs/yum/centos/7/x86_64
2. Initialize Repodata information:
Createrepo-p-d-o/opt/htdocs/yum/centos/7/x86_64/opt/htdocs/yum/centos/7/x86_64
(note here/opt/htdocs/yum/centos/7/x86_64 need to fill 2 times, has been space-separated, otherwise will be reported error:must specify a directory to index.)
After successful initialization, you will see a repodata directory in the/opt/htdocs/yum/centos/7/x86_64 directory, this is the meta data of the Yum source, and with this, Yum will be able to do "data information" with this "source".
3. Configure the local Yum to use the self-built Yum source.
To put it simply, create a new profile file (or add a configuration statement to an existing file) in the local/ETC/YUM.REPOS.D directory, with. Repo as the file name suffix, such as Jicki.repo, and then the contents are as follows:
-------------------------------------------------------------------
[Jicki-yum]
Name=jicki-yum
baseurl=http://192.168.0.157/yum/centos/$releasever/$basearch/
Enabled=1
Gpgcheck=0
gpgkey=
-------------------------------------------------------------------
Explain:
[....] The name that represents the library must be unique and cannot be duplicated.
Name= is the description of this library, not much practical meaning, just a field description.
Baseurl= instructions to take what way to transfer, where the specific path, you can use the way there, file://,ftp://,http://, etc., about baseurl variables, you can view the yum.conf manual: Man yum.conf, The last paragraph of the manual is described in detail.
Enabled=1 instructions to enable this update library, 0 means not enabled.
Gpgcheck=1 means using GPG files to check the signature of the software package
The gpgkey= represents the location where the GPG file is stored, and it can also be located in HTTP mode.
At this time, when we yum repolist, we can see the Jicki-yum source.
Second, make RPM package:
1. First check the software required to make the RPM package and install
Rpm-qa|grep GCC
Rpm-qa|grep Rpm-build
Yum Install-y Rpm-build
Centos7 under the RPM package to make the source code lock in the directory for/root/rpmbuild if not present, arbitrary to the file execution Rpmbuild nginx-1.7.9.tar.gz, can be generated.
The/root/rpmbuild directory structure is as follows:
Build-build location (Ignore)
BuildRoot, compile location (ignore)
RPMS-generated binary RPM storage location
SOURCES, storage source, patch files
SPECS----*.spec rule file for compiling scheme
SRPMS, generate RPM source package (src.rpm) storage location
2. Copy the source code to the sources directory
This will nginx-1.7.9.tar.gz copy the past.
CP nginx-1.7.9.tar.gz/root/rpmbuild/sources/
Tree
.
├──build
├──buildroot
├──rpms
├──sources
│└──nginx-1.7.9.tar.gz
├──specs
└──srpms
Generate Spec Rule file
Enter the specs directory to create a nginx-1.7.9 spec file
* You must use the VIM Compilation tool to generate the spec template file automatically
Vim Nginx-1.7.9.spec
The spec file explains the meaning of each part of the spec file as follows:
--------------------------------------------------------------------------------------------------------------- ------------
Name://software names, such as Nginx, can be referenced in the following way using%{name}
Version://Software release number, only if the software has a larger change than before, increase the version number. such as 1.7.9
Release:1%{?dist}//Software release serial number, marked the first several times packaging. If the software changes less than before, only increase the release sequence number, without changing the version number
Summary://overview, simple description of the software
Group://package category, specific categories see RPM's Help file/usr/share/doc/rpm-4.8.0/groups, all software must belong to one of these types.
License://License type, such as: GPL (Free software), commercial (commercial), Share (shared), GNU, etc.
URL://Software (can be omitted)
SOURCE0://Source Name
BuildRoot:% (mktemp-ud%{_tmppath}/%{name}-%{version}-%{release}-xxxxxx)
This parameter is important because in the process of generating the RPM, the software is installed in the path above when the make install is executed, and it is also dependent on the "virtual directory" for the "root directory" when packaging. You can refer to it later using the $rpm_build_root method.
Buildrequires://Software Dependency description (can be omitted)
Requires://The package name on which the RPM package depends
%description//Detailed description of the software, can write multiple lines
%prep//This segment is a preprocessing segment that is typically used to perform some of the commands for unlocking the source package to prepare for the next compilation installation.
%setup-q//extract source to build directory;-q = Do not display output (quietly)
%build//This paragraph is the creation of a segment, the command executed to generate a package service, equivalent to./configure and make%configure make%{?_smp_mflags}
%install//This section is mainly used to complete the actual installation of the software must execute the command, this section is generally composed of makeinstall directives, but sometimes also contains the CP, MV, install and other instructions
RM-RF $RPM _build_root makeinstall destdir= $RPM _build_root
The%clean////This section describes the following tasks that are automatically executed after the completion of the package, the script for this section is used to perform additional cleanup work, which is usually done simply by using the RM-RF $RPM _build_root command, and does not need to specify additional content for this section
RM-RF $RPM _build_root
%files//This section specifies the list of files that make up the package, which is represented by the section prefix%files. In addition, it contains a series of macro controls on file properties and configuration information after installation. , divided into three categories--documentation (DOC), configuration file (config) and execution program, also written according to the prompts. %files the files that should be bundled into RPM, and can optionally set permissions and other information
%defattr (-,root,root,-)//Specify the properties of the wrapper file, respectively (Mode,owner,group),-represents the default value, the text file is 0644, the executable is 0755%doc
%changelog//This paragraph is a modified log segment. You can record each modification of the software here and save it in a published package
-------------------------------------------------------------------------------------------
--------------------------------
Use Createrepo to create your own Yum source