• Linux RPM 构建


    • 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
    
    • 1

    如何构建自己的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
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42

    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.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21

    The prep section

    准备阶段
    在这里插入图片描述
    The prep section, short for prepare, defines the commands necessary to prepare for the build
    If you are starting with a compressed tar archive (a tarball) of the sources, the prep section needs
    to extract the sources
    The prep section starts with a %prep statement
    This example uses the %setup RPM macro, which knows about tar archives, to extract the files

    • prep部分(prepare的缩写)定义了为构建做准备所需的命令
    • 如果你从压缩的tar文件(tarball)开始,准备部分需要提取信息源
    • prep部分以一个%prep语句开始
    • 这个例子使用%setup RPM宏来解压缩文件,它知道tar存档

    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
    
    • 1
    • 2
    • 3

    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
    
    • 1
    • 2
    • 3
    • 4

    The spec file

    在这里插入图片描述

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

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

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

    展开src包

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

    去哪里寻找src.rpm包

    • rpmfind.net
    • rpmone.com

    defiining package information

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

    在这里插入图片描述

    rpmbuild  --clean nginx.spec
    
    • 1

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

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

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

  • 相关阅读:
    不要再说你不会了——网络性能问题排查思路
    Shiro授权
    一起Talk Android吧(第三百六十六回:多线程之LOCK锁)
    计算机毕业设计node+vue基于微信小程序的乐团团购系统的设计与实现
    Linux下安装配置redis详细教程,并配置哨兵模式,redis中文详解
    基于TCP/UDP协议的Socket编程方法
    Verilog HDL中的数据类型
    [英雄星球六月集训LeetCode解题日报] 第15日 树状数组
    Mysql分组查询每组最新的一条数据
    看透react源码之感受react的进化
  • 原文地址:https://blog.csdn.net/xixihahalelehehe/article/details/127746922