Linux RPM 构建

发布于:2022-11-08 ⋅ 阅读:(776) ⋅ 点赞:(0)

  • preparing to build RPMS
  • Planning for RPMS
  • Explaining the build process
  • using building files
  • seeing the results
  • verifying your RPMS
  • writing spec files
  • defiining package information
  • controlling the build
  • listing the files in the package
  • defining spec file macros

preparing to build RPMS

The main tasks in building RPMs
are:

  • Planning what you want to build

  • Gathering the software to package

  • Patching the software as needed

  • Creating a reproducible build of the software

  • Planning for upgrades

  • Outlining any dependencies

  • Building the RPMS

  • Testing the RPMs

  • 计划你想要建造什么

  • 收集软件包

  • 根据需要打补丁

  • 创建软件的可复制构建

  • 升级计划

  • 列出所有依赖关系

  • 构建rpm

  • 测试rpm

场景:cacti 0.8.7 --> 0.8.8 升级,删除原来,打补丁…需求

RPM capability 能力 封装 构建 厕所

Planning what you want to build

  • An application

  • Customized or patched?

  • A programming library

  • A set of system configuration files

  • Or a documentation package

  • Creating a binary RPM or a source RPM or both?

  • 一个应用程序

  • 定制或者修补吗?

  • 一个编程库

  • 一组系统配置文件

  • 或者文件包

  • 创建二进制RPM或源RPM或两者?

src.rpm tar.gz , spec

Building RPMS

1.Set up the directory structure
2.Place the sources in the right directory
3.Create a command what to do spec file that tells the rpmbuild
4. Build the source and binary RPMs

1.设置目录结构
2.将源代码放在正确的目录中
3.创建一个命令做什么规格文件告诉rpmbuild
4. 构建源代码和二进制rpm

Set up the directory structure

在这里插入图片描述

rpmbuild --showrc | grep macros

如何构建自己的rpmbuild车间

[root@k3smaster ~]# rpmbuild --showrc |grep _topdir
-14: _builddir  %{_topdir}/BUILD
-14: _buildrootdir      %{_topdir}/BUILDROOT
-14: _rpmdir    %{_topdir}/RPMS
-14: _sourcedir %{_topdir}/SOURCES
-14: _specdir   %{_topdir}/SPECS
-14: _srcrpmdir %{_topdir}/SRPMS
-14: _topdir    %{getenv:HOME}/rpmbuild
[root@k3smaster ~]# su - mage
su: user mage does not exist
[root@k3smaster ~]# useradd zongxun
[root@k3smaster ~]# su - zongxun
[zongxun@k3smaster ~]$ rpmbuild --showrc | grep _topdir
-14: _builddir  %{_topdir}/BUILD
-14: _buildrootdir      %{_topdir}/BUILDROOT
-14: _rpmdir    %{_topdir}/RPMS
-14: _sourcedir %{_topdir}/SOURCES
-14: _specdir   %{_topdir}/SPECS
-14: _srcrpmdir %{_topdir}/SRPMS
-14: _topdir    %{getenv:HOME}/rpmbuild
[zongxun@k3smaster ~]$ ls
[zongxun@k3smaster ~]$ vim .rpmmacros
[zongxun@k3smaster ~]$ cat .rpmmacros
%_topdir        /home/zongxun
[zongxun@k3smaster ~]$ vim .rpmmacros
[zongxun@k3smaster ~]$ cat .rpmmacros
%_topdir        /home/zongxun/rpmbuild
[zongxun@k3smaster ~]$ mkdir -pv rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
mkdir: created directory ‘rpmbuild’
mkdir: created directory ‘rpmbuild/BUILD’
mkdir: created directory ‘rpmbuild/RPMS’
mkdir: created directory ‘rpmbuild/SOURCES’
mkdir: created directory ‘rpmbuild/SPECS’
mkdir: created directory ‘rpmbuild/SRPMS’
[zongxun@k3smaster ~]$ rpmbuild --showrc | grep _topdir
-14: _builddir  %{_topdir}/BUILD
-14: _buildrootdir      %{_topdir}/BUILDROOT
-14: _rpmdir    %{_topdir}/RPMS
-14: _sourcedir %{_topdir}/SOURCES
-14: _specdir   %{_topdir}/SPECS
-14: _srcrpmdir %{_topdir}/SRPMS
-14: _topdir    /home/zongxun/rpmbuild

The introduction section

在这里插入图片描述
source BUILD
BUILDROOT

BuildRequires 依赖包

查看rpm文件

rpm -qi httpd
Name        : httpd
Version     : 2.4.6
Release     : 97.el7.centos.5
Architecture: x86_64
Install Date: Tue 08 Nov 2022 01:48:37 PM CST
Group       : System Environment/Daemons
Size        : 9821136
License     : ASL 2.0
Signature   : RSA/SHA256, Fri 25 Mar 2022 02:21:56 AM CST, Key ID 24c6a8a7f4a80eb5
Source RPM  : httpd-2.4.6-97.el7.centos.5.src.rpm
Build Date  : Thu 24 Mar 2022 10:59:42 PM CST
Build Host  : x86-02.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://httpd.apache.org/
Summary     : Apache HTTP Server
Description :
The Apache HTTP Server is a powerful, efficient, and extensible
web server.

The prep section

准备阶段
在这里插入图片描述

The build section

在这里插入图片描述

the install section

在这里插入图片描述

脚本段

  • %pre 安装之前
  • %post安装之后
  • %preun卸载之前
  • %postun卸载之后

BUILDROOT/

install 比cp更强大

install /etc/fstab /tmp
install -d /tmp/test
install -D /etc/nagios/nagios.cfg /tmp/nagios/nagios.cfg

The clean section

在这里插入图片描述

The files sections

在这里插入图片描述

changelog 段

定义日志版本更新说明

Build RPMS with the rpmbuild command
在这里插入图片描述

rpmbuild -bp nignx.spec
rpmbuild -bc nginx.spec
rpmbuild -bi nginx.spec
rpmbuild -ba nginx.spec

The spec file

在这里插入图片描述

在注视当中要用%%表示%

rpmbuildd ba 既生成源码包又生成二进制包

rpm2cpio xxxx.rpm  cpio文件(乱码)
rpm3cpio xxxx.rpm | cpio -t
rpmbuild -rebuild  xxx.src.rpm

展开src包

rpm2cpio nginx-1.0.14-3.src.rpm | cpio -id

去哪里寻找src.rpm包

  • rpmfind.net
  • rpmone.com

defiining package information

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述

rpmbuild  --clean nginx.spec

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

rpm -K xxx.rpm  #检查安装包的来源

在这里插入图片描述
在这里插入图片描述


网站公告

今日签到

点亮在社区的每一天
去签到