1、安装rpm-build软件
[root@web46 ~]# yum -y install rpm-build
2、生成rpmbuild目录结构
[root@web46 ~]# rpmbuild -ba nginx.spec //报错,但会自动创建rpmbuild目录结构
错误:stat /root/nginx.spec 失败:没有那个文件或目录
[root@web46 ~]# ls
nginx-1.12.2.tar.gz rpmbuild
[root@web46 ~]# ls rpmbuild/
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
3、将源码包复制到SOURCES目录
[root@web46 ~]# ls
nginx-1.12.2.tar.gz rpmbuild
[root@web46 ~]# cp nginx-1.12.2.tar.gz rpmbuild/SOURCES/
4、创建并修改SPEC配置文件
[root@web46 ~]# vim rpmbuild/SPECS/nginx.spec
Name:nginx //软件包名称,不能写错
Version:1.12.2 //软件版本,不能写错
Release: 1%{?dist} //第几次打rpm包,默认第一次
Summary:this is a web server //简单描述
#Group:
License:GPL //GPL协议:任意复制,任意粘贴,任意修改
URL:www.abc.com //任意网址
Source0:nginx-1.12.2.tar.gz //源码包名称,不能写错
#BuildRequires: //源码安装提示的依赖包
#Requires: //rpm打包完成后,交付使用安装提示的依赖包
%description
this is a web server to. //详细描述
%post
useradd nginx //非必需操作:安装后脚本(创建账户)
%prep
%setup -q //自动解压源码包,并cd进入目录
%build
./configure --with-http_ssl_module //安装配置项
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/* //对哪些文件与目录打包
%changelog
5、安装依赖包
[root@web46 ~]# yum -y install gcc pcre-devel zlib-devel openssl-devel
6、rpmbuild创建rpm软件包
[root@web46 ~]# cd rpmbuild/SPECS/
[root@web46 SPECS]# ls
nginx.spec
[root@web46 SPECS]# rpmbuild -ba nginx.spec
[root@web46 SPECS]# ls /root/rpmbuild/RPMS/x86_64/
nginx-1.12.2-1.el7.centos.x86_64.rpm //打包完后生成的rpm包
nginx-debuginfo-1.12.2-1.el7.centos.x86_64.rpm
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
在/rpmbuild/SRPMS/目录下生成的nginx-*.src.rpm包含有源码包和spec文件
[root@web46 ~]# cd rpmbuild/SRPMS/
[root@web46 SRPMS]# ls
nginx-1.12.2-1.el7.centos.src.rpm
[root@web46 SRPMS]# rpm -qpl nginx-1.12.2-1.el7.centos.src.rpm
nginx-1.12.2.tar.gz
nginx.spec
[root@web46 SRPMS]# rpm2cpio nginx-1.12.2-1.el7.centos.src.rpm |cpio -div
nginx-1.12.2.tar.gz
nginx.spec
1919 块
[root@web46 SRPMS]# ls
nginx-1.12.2-1.el7.centos.src.rpm nginx-1.12.2.tar.gz nginx.spec