构建基于RHEL8系列(CentOS8,AlmaLinux8,RockyLinux8等)的Nginx1.24.0的RPM包

本文适用:rhel8系列,或同类系统(CentOS8,AlmaLinux8,RockyLinux8等)
文档形成时期:2022-2023年
因系统版本不同,构建部署应略有差异,但本文未做细分,对稍有经验者应不存在明显障碍。
因软件世界之复杂和个人能力之限,难免疏漏和错误,欢迎指正。

环境准备

yum install rpmdevtools
#创建目录
rpmdev-setuptree
#或手动创建目录:

mkdir rpmbuild-nginx-1.24.0; cd rpmbuild-nginx-1.24.0
mkdir -p ./{BUILD,RPMS,SOURCES,SPECS,SRPMS}

#无论是使用rpmdev-setuptree创建目录,还是手动创建的,默认使用路径是/root/rpmbuild,除非使用参数--define "_topdir `pwd`",可在其它目录下构建。

rpmbuild命令详解

rpmbuild --help
-ba build source and binary packages from
-bb build binary package only from

rpmbuild的spec文件说明

参考:https://blog.csdn.net/qq_22418329/article/details/109983388
%pre和%post中的scriptlet分别在安装软件包之前和之后运行。脚本%preun和%postun在软件包卸载之前和之后运行。脚本%pretrans和%posttrans在事务的开始和结束时运行。

依赖包:
/root/software/{openssl-1.1.1w.tar.gz,pcre-8.45.tar.gz,zlib-1.2.13.tar.gz} 解压即可

源目录文件列表:
ls SOURCES/
nginx-1.24.0.tar.gz nginx.conf nginx.service phpinfo.php

nginx-1.24.0-el8.spec内容

Name:           nginx
Version:	1.24.0
Release:	custom%{?dist}
Summary:	www.nginx.org
 
Group:		GNU Linux Nginx Product
License:	GPLv3+
URL:	        https://nginx.org/en/download.html
Source0:	https://nginx.org/download/%{name}-%{version}.tar.gz
 
BuildRequires:	gcc
Requires:	perl perl-devel



%define debug_package %{nil}
%define _prefix  /opt/nginx
Prefix:     %{_prefix}




%description
nginx install
 



%prep
%setup -q
 
 


%build
./configure --prefix=%{_prefix} \
--user=www --group=www \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-http_flv_module \
--with-http_realip_module \
--with-http_ssl_module \
--with-http_v2_module \
--with-stream \
--with-pcre=/root/software/pcre-8.45 \
--with-openssl=/root/software/openssl-1.1.1w \
--with-zlib=/root/software/zlib-1.2.13

make %{?_smp_mflags}
 
 



#
# Installation section
#
%install
[ %{buildroot} != "/" ] && rm -rf %{buildroot}
make install DESTDIR=%{buildroot}

%__install -c -d -m 755 "%{buildroot}%{_prefix}/conf"
%__install -c -d -m 755 "%{buildroot}/usr/lib/systemd/system"
%__install -c -d -m 755 "%{buildroot}/opt/web/eg"
cp -f %_sourcedir/nginx.service "%{buildroot}/usr/lib/systemd/system/nginx.service"
cp -f %_sourcedir/nginx.conf "%{buildroot}%{_prefix}/conf/"
cp -f %_sourcedir/phpinfo.php "%{buildroot}/opt/web/eg/"





#
# Clean section
#

%clean
[ %{buildroot} != "/" ] && rm -rf "%{buildroot}"






#将所需要打包的文件都存放到这边中;-f %{name}.lang 加上后的意思为声明找到的文件
%files
%{_prefix}
%doc
/usr/lib/systemd/system/nginx.service
/opt/web/eg




#安装后执行的命令
%post
if [ $1 == 1 ];then
    groupadd www -g 319 2> /dev/null
    useradd -s /sbin/nologin -M www -u 319 -g 319 2> /dev/null
    mkdir /home/www 2> /dev/null
    chown www:www /home/www 2> /dev/null
    chown www:www -R /opt/web/eg
    
    systemctl daemon-reload
    systemctl enable nginx
fi

 



#卸载前执行的命令
%preun
if [ "$1" = 0 ]
then
    systemctl disable nginx
    systemctl stop nginx
    # userdel -r www
    cp -r %{_prefix}/conf /opt/nginx_conf.rpmsave-`date +"%Y%m%d-%H%M%S"`
fi






%postun
if [ "$1" = 0 ]
then
    systemctl disable nginx
    rm -f /usr/lib/systemd/system/nginx.service
    rm -rf /opt/nginx
    echo "%{name}-%{version}-%{release} uninstalled."
fi





#软件更新说明
%changelog
* Thu Dec 14 2023 A
- For the first time, Custom made Nginx1.24.0 in AlmaLinux8.8.

构建

cd /root/rpmbuild-nginx-1.24.0
rpmbuild --define "_topdir `pwd`" --nodebuginfo -ba SPECS/nginx-1.24.0-el8.spec

构建后的主要文件:
Nginx1.24.0构建后的主要文件

安装

dnf localinstall nginx-1.24.0-custom.el8.x86_64.rpm

  • 16
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沉思的归零者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值