1 安装rpm-build软件包
[root@web1 ~]# yum -y install rpm-build
2 生成rpmbuild目录结构
[root@web1 ~]# rpmbuild -ba nginx.spec //会报错,没有文件或目录,用于生成目录
[root@web1 ~]# ls /root/rpmbuild //自动生成的目录结构
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
目录结构说明
目录名 说明 macros中的宏名
BUILD 编译rpm包的临时目录 %_builddir
BUILDROOT 编译后生成的软件临时安装目录 %_buildrootdir
RPMS 最终生成的可安装rpm包的所在目录 %_rpmdir
SOURCES 所有源代码和补丁文件的存放目录 %_sourcedir
SPECS 存放SPEC文件的目录(重要) %_specdir
SRPMS 软件最终的rpm源码格式存放路径(暂时忽略掉,别挂在心上) %_srcrpmdir
3 准备工作,将源码软件复制到SOURCES目录
[root@web1 ~]# cp /root/lnmp_soft/nginx-1.12.2.tar.gz /root/rpmbuild/SOURCES/
4 创建并修改SPEC配置文件
[root@web1 ~]# vim /root/rpmbuild/SPECS/nginx.spec
Name:nginx #名字为tar包的名字
Version:1.12.2 #版本号,一定要与tar包的一致
Release: 10 #释出号,也就是第几次制作rpm
Summary: Nginx is a web server software. #软件包的摘要信息
#group: #组名,可以通过less /usr/share/doc/rpm-4.8.0/GROUPS 选择合适组,可以为空
License:GPL #软件的授权方式
URL: www.test.com # 这里本来写源码包的下载路径或者自己的博客地址或者公司网址之类,随意
Source0:nginx-1.12.2.tar.gz #源代码包的名称
#BuildRequires: #制作过程中用到的软件包
#Requires: #软件运行需要的软件包
%description #软件包的详细说明信息,但最多只能有80个英文字符
nginx [engine x] is an HTTP and reverse proxy server.
%post
useradd nginx #非必需操作:安装后脚本(创建账户)
%prep
%setup –q #自动解压源码包,并cd进入目录
%build
./configure #./configure 也可以用%configure来替换
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
%doc
/usr/local/nginx/* //对哪些文件与目录打包
%changelog
5 安装依赖软件包
[root@web1 ~]# yum -y install gcc pcre-devel zlib-devel openssl-devel
6 rpmbuild创建RPM软件包
[root@web1 ~]# rpmbuild -ba /root/rpmbuild/SPECS/nginx.spec
[root@web1 ~]# ls /root/rpmbuild/RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm
/root/rpmbuild/RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm
[root@web1 ~]# rpm -qpi /root/rpmbuild/RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm
Name : nginx Relocations: (not relocatable)
Version : 1.12.2 Vendor: (none)
Release : 10 Build Date: Mon 02 May 2016 02:30:53 AM PDT
Install Date: (not installed) Build Host: localhost
Group : Applications/Internet Source RPM: nginx-1.8.0-1.src.rpm
Size : 721243 License: GPL
Signature : (none)
URL : www.nginx.org
Summary : Nginx is a web server software.
Description :
nginx [engine x] is an HTTP and reverse proxy server.
7 安装nginx软件
[root@web1 ~]# rpm -ivh /root/rpmbuild/RPMS/x86_64/nginx-1.12.2-10.x86_64.rpm
[root@web1 ~]# rpm -qa |grep nginx
[root@web1 ~]# /usr/local/nginx/sbin/nginx
[root@web1 ~]# curl http://127.0.0.1/