前言
拥有源码,把源码制作RPM包进行安装和使用。
制作RPM包步骤
- 准备普通用户(rpmbuilduser)
- 创建目录结构和原材料放到对于的目录中
- 写Spec文件
- 编译
准备环境
- 准备普通用户(rpmbuilduser)
#创建rpmbuilduser 用户制作rpm包
useradd rpmbuilduser
#查看rpmbuild查看宏
rpmbuild --showrc
#没有rpmbuild命令则安装rpm-build
yum -y install rpm-build
- 创建目录结构和原材料放到对于的目录中
# 切换到制作rpm包用户
su rpmbuilduser
mkdir RPM_BUILD/{BUILD,RPMS,SOURCES,SPECS,SRPMS} -p
tree RPM_BUILD/
RPM_BUILD/
├── BUILD #源代码解压的位置,自动解压到这里,只需要创建目录,build的时候会自动解压到此处。
├── RPMS #编译后生产的rpm包存放的位置,里面有各种平台的目录。
├── SOURCES #存放源码等我们提供的所有文件存放的位置。
├── SPECS #存放specs文件的位置。
└── SRPMS #存放二进制rpm包存放的位置。
# 修改rpmbuild工作位置
vim ~/.rpmmacros
%_topdir %{getenv:HOME}/RPM_BUILD
#查看确定是否为该路径
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}/RPM_BUILD
- 写Spec文件
文件所在位置:- 源文件获取
wget http://nginx.org/download/nginx-1.6.1.tar.gz
https://git.centos.org/commit/rpms!nginx16-nginx.git/673bbd21b5835a380bc52ee1194a968f0ce62859
├── BUILD
├── BUILDROOT
├── RPMS
├── SOURCES
│ ├── 404.html
│ ├── 50x.html
│ ├── action-upgrade.sh
│ ├── index.html
│ ├── nginx-1.6.1-CVE-2014-3616.patch
│ ├── nginx-1.6.1.tar.gz
│ ├── nginx-auto-cc-gcc.patch
│ ├── nginx.conf
│ ├── nginx.init
│ ├── nginx-logo.png
│ ├── nginx.logrotate
│ ├── nginx.service
│ └── nginx.sysconfig
├── SPECS
│ └── nginx.spec
└── SRPMS
- 编译过程
$rpmbuild -ba nginx.spec
error: Failed build dependencies:
gd-devel is needed by nginx-1:1.6.1-2.el7.centos.x86_64
libxslt-devel is needed by nginx-1:1.6.1-2.el7.centos.x86_64
perl-devel is needed by nginx-1:1.6.1-2.el7.centos.x86_64
perl(ExtUtils::Embed) is needed by nginx-1:1.6.1-2.el7.centos.x86_64
#root用户安装
#yum -y install gd-devel libxslt-devel perl-devel perl
$rpmbuild -ba nginx.spec
error: Failed build dependencies:
perl(ExtUtils::Embed) is needed by nginx-1:1.6.1-2.el7.centos.x86_64
#root用户安装
#yum -y install perl-ExtUtils-Embed
... ...
#再次执行,则成功编译出rpm包
$rpmbuild -ba nginx.spec
- 编译解析
rpmbuidl 的几个过程
-bp build through %prep (unpack sources and apply patches) from <specfile>
-bc build through %build (%prep, then compile) from <specfile>
-bi build through %install (%prep, %build, then install) from <specfile>
-bl verify %files section from <specfile>
-ba build source and binary packages from <specfile>
-bb build binary package only from <specfile>
-bs build source package only from <specfile>
-tp build through %prep (unpack sources and apply patches) from <tarball>
-tc build through %build (%prep, then compile) from <tarball>
-ti build through %install (%prep, %build, then install) from <tarball>
-ta build source and binary packages from <tarball>
-tb build binary package only from <tarball>
-ts build source package only from <tarball>
Spec步骤
安装包信息
%description
%prep段
%build段
%install段
%files段
%changelog段