
2.8 如何在异构环境重新编译RPM
在前文中我们已经提到,有的RPM包与运行环境有关,有的无关。如果一个RPM依赖于某一个版本的运行环境(Linux版本或处理器架构),我们如何让这个RPM在其他的环境中运行?这会涉及异构环境下的RPM重新编译。
Mock是一个用于构建RPM包的工具(就像Docker启动一个build的环境一样,摆脱对编译环境Linux版本的限制)。它可以为不同的架构、Linux版本构建RPM软件包。在RHEL系统上使用Mock,需要启用“Extra Packages for Enterprise Linux”(EPEL)存储库。
针对RPM包,Mock最常见的用例之一是创建原始的构建环境。通过指定/etc/mock目录下不同的配置文件,模拟使用不同的构建环境。
查看mock配置文件,如图2-25所示。
我们以epel-7-x86_64.cfg为例,查看其中关于架构的描述,具体如下所示,可以看到是x86_64和Red Hat Linux发行版7的信息。

图2-25 查看mock配置文件
[root@master mock]# cat epel-7-x86_64.cfg |grep -i arch config_opts['target_arch'] = 'x86_64' config_opts['legal_host_arches'] = ('x86_64',) mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=updates mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-7&arch=x86_64 mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=extras mirrorlist=http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=sclo-rh mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=testing-epel7&arch=x86_64 mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=epel-debug-7&arch=x86_64
使用epel-7-x86_64配置来构建SRPM,如图2-26所示。

图2-26 使用epel-7-x86_64构建SRPM
使用epel-6-x86_64配置来构建二进制RPM,如图2-27所示。
查看构建好的二进制RPM cello-1.0-1.el6.x86_64.rpm,如图2-28所示。
安装cello-1.0-1.el6.x86_64.rpm,如图2-29所示。
查看构建好的二进制RPM cello-1.0-1.el7.x86_64.rpm,并进行安装验证,如图2-30所示。

图2-27 使用epel-6-x86_64构建二进制RPM

图2-28 查看构建好的二进制RPM

图2-29 安装构建好的二进制RPM

图2-30 查看构建好的二进制RPM
至此,在异构环境下重新编译二进制RPM成功。