1. 建立工作路径
mkdir -p ~/rpmbuild/{BUILD,RPMS,SOURCES,SPECS,SRPMS}
2. 下载Redis源码
cd ~/rpmbuild/SOURCES
wget https://download.redis.io/releases/redis-6.2.5.tar.gz
3. 安装依赖、编译和打包工具
yum install -y rpm-build
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
gcc -v
4. 编写SPEC文件
cd ~/rpmbuild/SPECS
vim redis_build.spec
Name: redis
Version: 6.2.5
Release: 1%{?dist}
Summary(zh_CN): 这是redis项目
License: GPLv3+
URL: https://download.redis.io/releases/
Source0: redis-6.2.5.tar.gz
BuildRequires: gcc
%description -l zh_CN
这个是一个redis项目练手项目,进行redis打包等操作。
%prep
%setup -q
%build
make
%install
rm -rf %{buildroot}
make install PREFIX=%{buildroot}
cp %{_builddir}/%{name}-%{version}/redis.conf %{buildroot}/bin/
%post
cat>/lib/systemd/system/redis.service<<-EOF
[Unit]
Description=Redis
After=network.target
[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/bin/redis-server
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target
EOF
%preun
rm -rf /lib/systemd/system/redis.service
%files
/bin/*
%changelog
5.检查SPEC文件(可略)
rpmlint redis_build.spec
6.打包
centos7以及下命令:
cd ~/rpmbuild/SPECS
rpmbuild -ba redis_build.spec
centos8命令:
cd ~/rpmbuild/SPECS
rpmbuild -ba redis_build.spec --nodebuginfo
|