下载工具rpm-build
yum search rpm-build
yum install rpm-build.x86_64
制作属于自己的RPM包
1.准备打包目录
ls rpmbuild/
BUILD BUILDROOT RPMS SOURCES SPECS SRPMS
2.放入软件包
cp /root/nginx-1.18.0.tar.gz rpmbuild/SOURCES/
3.编辑spec文件
vim rpmbuild/SPECS/nginx.spec
文件内容如下
Name: nginx # 软件包名
Version: 1.18.0 # 版本
Release: 1%{?dist} # 发行次数 需要手动修改
Summary: A light-weight WEB server
License: GPL # 开源协议
URL: https://nginx.org/en/ # 项目官网
Source0: nginx-1.18.0.tar.gz # 源码包 从soureces 目录下面找
BuildRequires: gcc gcc-c++ make # 编译环境
Requires: zlib zlib-devel openssl-devel openssl pcre pcre-devel # 软件包依赖关系%description # 描述信息
Engine x is a light web server and a useful reverse proxy server.%prep # 安装rpm包前的准备脚本%setup -q # 解压源码包%build # 开始编译
./configure --prefix=/usr/local/nginx --user=nginx --group=nginx # 配置编译参数
make %{?_smp_mflags} # 编译%install # 安装
make install DESTDIR=%{buildroot}%files # 指定文件释放路径
/usr/local/nginx/*%post #安装
useradd -M -s /sbin/nologin nginx
ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx%postun #卸载
if [ $1 -eq 0 ]; then/usr/sbin/userdel nginx
fi%changelog
4.检查
tree rpmbuild/
rpmbuild/
├── BUILD // 源码包编译的工作现场
├── BUILDROOT // 另一个源码包编译的工作现场
├── RPMS // 保存打包完成的rpm包
├── SOURCES // 源码包
│ └── nginx-1.18.0.tar.gz
├── SPECS // 制作RPM包要使用的配置文件
│ └── nginx.spec
└── SRPMS // 包含源码未编译的RPM包
5.制作软件包
rpmbuild -ba rpmbuild/SPECS/nginx.spec
6.复制出来并检查
cp rpmbuild/RPMS/x86_64/nginx-1.18.0-1.el8.x86_64.rpm .
>rpm -qpi nginx-1.18.0-1.el8.x86_64.rpm
Name : nginx
Version : 1.18.0
Release : 1.el8
Architecture: x86_64
Install Date: (not installed)
Group : Unspecified
Size : 773910
License : GPL
Signature : (none)
Source RPM : nginx-1.18.0-1.el8.src.rpm
Build Date : Wed 17 Apr 2024 02:03:02 AM PDT
Build Host : bogon
Relocations : (not relocatable)
URL : https://nginx.org/en/
Summary : A light-weight WEB server
Description :
Engine x is a light web server and a useful reverse proxy server.