如何制作nginx的RPM包

  • 假如官网没有提供rpm包只有源码包那怎么办呢?这里主要讲的nginx的源码包制作rpm包的过程。

1. 安装rpm-build软件包

[root@localhost ~]# yum -y install rpm-build

2. 生成rpmbuild目录结构

[root@localhost ~]# rpmbuild -ba nginx.spec   会报错,没有文件或目录,但是会自动创建一个目录rpmbuild并生成目录结构
error: failed to stat /root/nginx.spec: No such file or directory
[root@localhost ~]# ls rpmbuild/
BUILD  BUILDROOT  RPMS  SOURCES  SPECS  SRPMS

3. 准备工作,将源码软件包复制到SOURCES目录

[root@localhost ~]# cp nginx-1.18.0.tar.gz rpmbuild/SOURCES/

4. 创建并修改SPEC配置文件

[root@localhost ~]# vim /root/rpmbuild/SPECS/nginx.spec      #这里的编辑的文件名后缀必须是spec
Name:nginx										#源码包软件名称
Version:1.18.0									#源码包软件的版本号
Release:	1									#制作的RPM包版本号
Summary: Nginx is a web server software.			#RPM软件的概述	
License:GPL										#软件的协议
URL:	www.test.com									#网址
Source0:nginx-1.18.0.tar.gz						#源码包文件的全称

#BuildRequires:									#制作RPM时的依赖关系,这里只有提示依赖不会自动安装依赖包
#Requires:										#安装RPM时的依赖关系
%description
nginx [engine x] is an HTTP and reverse proxy server.	#软件的详细描述

%post
useradd -s /sbin/nologin nginx  -M                     		 #非必需操作:安装后脚本(创建账户)

%prep
%setup -q								#自动解压源码包,并cd进入源码包目录

%build
./configure   --prefix=/usr/local/nginx  --user=nginx  --group=nginx      #预编译,这里可以自由安装模块
make %{
    
    ?_smp_mflags}                                                     #编译

%install
make install DESTDIR=%{
    
    buildroot}                                      #安装

%files
%doc
/usr/local/nginx/*					#对哪些文件与目录打包

%changelog

5.使用配置文件创建RPM包

#安装依赖包
[root@localhost ~]# yum -y install  gcc  pcre-devel openssl-deve
#rpmbuild创建RPM软件包
[root@localhost ~]# rpmbuild  -ba /root/rpmbuild/SPECS/nginx.spec
[root@localhost ~]# ls /root/rpmbuild/RPMS/x86_64/   ---查看创建的rpm包,第一个是制作好的nginx的rpm包
nginx-1.18.0-1.x86_64.rpm  nginx-debuginfo-1.18.0-1.x86_64.rpm

6.安装测试:

[root@localhost ~]# yum  install /root/rpmbuild/RPMS/x86_64/nginx-1.18.0-1.x86_64.rpm
[root@localhost ~]# rpm -q nginx 
nginx-1.18.0-1.x86_64

猜你喜欢

转载自blog.csdn.net/weixin_45625174/article/details/109818284