rpm打包教程


一、安装 rpm-build

yum install -y rpm-build rpmdevtools gcc gcc-c++ make autoconf

二、生成相关目录

useradd www
su www
rpmdev-setuptree

三、编写 spec 文件:/root/rpmbuild/SPECS/redis.spec

[shell]
Name: redis
Version: 3.2.8
Release: 1
Vendor: Redis
Summary: GUN Redis X86_64
License: GPL
Source: redis-3.2.8.tar.gz
Group: Redis
URL: https://redis.io/
Packager: mogu
%description
Redis 3.2.8 Server

%pre
useradd redis
mkdir -p /www/redis/6379
echo '
bind 127.0.0.1
port 6379
dir /www/redis/6379
pidfile /www/redis/6379/redis.pid
logfile /www/redis/6379/redis.log
daemonize yes
requirepass 123456
maxmemory 1G
' > /www/redis/6379/redis.conf
chown redis.redis /www/redis

%prep
pkill redis-server
%setup -q
%build
make
%install
make install
%clean
make clean

%files
%defattr (-,root,root)
[/shell]

四、把源码包放在 /root/rpmbuild/SOURCES 目录下

cp redis-3.2.8.tar.gz /root/rpmbuild/SOURCES/

五、开始打包

rpmbuild -bb /root/rpmbuild/SPECS/redis.spec

其他:获取官方包的 spec 文件

yum install -y epel-release
yum install -y rpm-build rpm cpio yum-utils rpmrebuild
yum remove -y epel-release
yumdownloader nginx
rpmrebuild -e -p --notest-install *.rpm
rpm2cpio nginx*.rpm | cpio -div