openresty rpm 构建

2022/4/3 6:23:22

本文主要是介绍openresty rpm 构建,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

预备

  • perl-Test-Simple.spec 问题
    1.302175版本不存在,可以调整为1.302190,可以按需调整
  • 依赖问题
    需要依赖zlib,pcre,openssl,等rpm包,需要先构建zib 然后是openssl,然后是pcre,同时构建好之后还需要先安装,然后就能继续构建了
    说明下官方的文档并不是很清楚
 
rpmbuild  -ba openresty-zlib.spec
rpmbuild  -ba openresty-openssl111.spec
rpmbuild  -ba openresty-pcre.spec
yum install -y RPMS/x86_64/* // 构建目录
  • ccache: command not found
yum install -y ccache
  • 依赖的一些其他包
yum -y install perl-ExtUtils-MakeMaker
  • 后续构建
    可以直接构建,比如openresty 之类的

集成外部扩展

基本剋有说包含三大类

  • 静态模块(直接内嵌的)
  • 动态模块(通过库引入的)
  • patch+ (动态或者静态模式的)
    对于静态模块比较好说,动态,模块是需要编译参数兼容的,否则是不能运行的(实际上比较好解释,因为不同构建参数依赖的东西是不一样的,而且很有可能因为依赖的构建有patch 造成服务不能兼容)
    对于包含patch 的目前稍微有点不是很好处理,一种解决方法是直接集成好包含patch 以及module 的源码,然后直接运行就可以了
    比如openresty 集成ngx_healthcheck_module 模块,我们就可以先做好包含模块的源码包,然后运行就直接在构建
  • 参考修改
 
Name:           openresty
Version:        1.19.9.1
Release:        1%{?dist}
Summary:        OpenResty, scalable web platform by extending NGINX with Lua
 
Group:          System Environment/Daemons
 
# BSD License (two clause)
# http://www.freebsd.org/copyright/freebsd-license.html
License:        BSD
URL:            https://openresty.org/
# 包含了模块以及patch 的源码包,可以在其他地方
Source0:        /root/rpmbuild/SOURCES/openresty-%{version}.tar.gz
 
%if 0%{?amzn} >= 2 || 0%{?suse_version} || 0%{?fedora} || 0%{?rhel} >= 7
%define         use_systemd   1
%endif
 
Source1:        openresty.service
Source2:        openresty.init
 
BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
BuildRequires:  perl-File-Temp
BuildRequires:  ccache, gcc, make, perl, systemtap-sdt-devel
BuildRequires:  openresty-zlib-devel >= 1.2.12-1
BuildRequires:  openresty-openssl111-devel >= 1.1.1h-1
BuildRequires:  openresty-pcre-devel >= 8.44-1
Requires:       openresty-zlib >= 1.2.12-1
Requires:       openresty-openssl111 >= 1.1.1h-1
Requires:       openresty-pcre >= 8.44-1
   
%if 0%{?suse_version}
 
# for /sbin/service
Requires(post):  insserv-compat
Requires(preun): insserv-compat
 
BuildRequires:  systemd
 
%else
 
%if 0%{?use_systemd}
 
BuildRequires:  systemd
Requires:       systemd
 
%else
 
# for /sbin/service
Requires(post):  chkconfig
Requires(preun): chkconfig, initscripts
 
%endif
 
%endif
 
AutoReqProv:        no
 
%define orprefix            %{_usr}/local/%{name}
%define zlib_prefix         %{orprefix}/zlib
%define pcre_prefix         %{orprefix}/pcre
%define openssl_prefix      %{orprefix}/openssl111
   
%description
This package contains the core server for OpenResty. Built for production
uses.
 
OpenResty is a full-fledged web platform by integrating the standard Nginx
core, LuaJIT, many carefully written Lua libraries, lots of high quality
3rd-party Nginx modules, and most of their external dependencies. It is
designed to help developers easily build scalable web applications, web
services, and dynamic web gateways.
 
By taking advantage of various well-designed Nginx modules (most of which
are developed by the OpenResty team themselves), OpenResty effectively
turns the nginx server into a powerful web app server, in which the web
developers can use the Lua programming language to script various existing
nginx C modules and Lua modules and construct extremely high-performance
web applications that are capable to handle 10K ~ 1000K+ connections in
a single box.
   
%if 0%{?suse_version}
 
%debug_package
 
%else
 
# Remove source code from debuginfo package.
%define __debug_install_post \
    %{_rpmconfigdir}/find-debuginfo.sh %{?_missing_build_ids_terminate_build:--strict-build-id} %{?_find_debuginfo_opts} "%{_builddir}/%{?buildsubdir}"; \
    rm -rf "${RPM_BUILD_ROOT}/usr/src/debug"; \
    mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug/openresty-%{version}"; \
    mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug/tmp"; \
    mkdir -p "${RPM_BUILD_ROOT}/usr/src/debug/builddir"; \
%{nil}
 
%endif
 
%if 0%{?fedora} >= 27
%undefine _debugsource_packages
%undefine _debuginfo_subpackages
%endif
 
%if 0%{?rhel} >= 8
%undefine _debugsource_packages
%undefine _debuginfo_subpackages
%endif
   
%package resty
 
Summary:        OpenResty command-line utility, resty
Group:          Development/Tools
Requires:       perl, openresty >= %{version}-%{release}
Requires:       perl(File::Spec), perl(FindBin), perl(List::Util), perl(Getopt::Long), perl(File::Temp), perl(POSIX), perl(Time::HiRes)
 
%if 0%{?fedora} >= 10 || 0%{?rhel} >= 6 || 0%{?centos} >= 6
BuildArch:      noarch
%endif
   
%description resty
This package contains the "resty" command-line utility for OpenResty, which
runs OpenResty Lua scripts on the terminal using a headless NGINX behind the
scene.
 
OpenResty is a full-fledged web platform by integrating the standard Nginx
core, LuaJIT, many carefully written Lua libraries, lots of high quality
3rd-party Nginx modules, and most of their external dependencies. It is
designed to help developers easily build scalable web applications, web
services, and dynamic web gateways.
   
%package doc
 
Summary:        OpenResty documentation tool, restydoc
Group:          Development/Tools
Requires:       perl, perl(Getopt::Std), perl(File::Spec), perl(FindBin), perl(Cwd), perl(File::Temp), perl(Pod::Man), perl(Pod::Text)
 
%if (!0%{?rhel} || 0%{?rhel} < 7) && !0%{?fedora}
Requires:       groff
%endif
 
%if (0%{?rhel} && 0%{?rhel} >= 7) || 0%{?fedora}
Requires:       groff-base
%endif
 
Provides:       restydoc, restydoc-index, md2pod.pl
 
%if 0%{?fedora} >= 10 || 0%{?rhel} >= 6 || 0%{?centos} >= 6
BuildArch:      noarch
%endif
   
%description doc
This package contains the official OpenResty documentation index and
the "restydoc" command-line utility for viewing it.
 
OpenResty is a full-fledged web platform by integrating the standard Nginx
core, LuaJIT, many carefully written Lua libraries, lots of high quality
3rd-party Nginx modules, and most of their external dependencies. It is
designed to help developers easily build scalable web applications, web
services, and dynamic web gateways.
   
%package opm
 
Summary:        OpenResty Package Manager
Group:          Development/Tools
Requires:       perl, openresty >= %{version}-%{release}, perl(Digest::MD5)
Requires:       openresty-doc >= %{version}-%{release}, openresty-resty >= %{version}-%{release}
Requires:       curl, tar, gzip
#BuildRequires:  perl(Digest::MD5)
Requires:       perl(Encode), perl(FindBin), perl(File::Find), perl(File::Path), perl(File::Spec), perl(Cwd), perl(Digest::MD5), perl(File::Copy), perl(File::Temp), perl(Getopt::Long)
 
%if 0%{?fedora} >= 10 || 0%{?rhel} >= 6 || 0%{?centos} >= 6
BuildArch:      noarch
%endif
   
%description opm
This package provides the client side tool, opm, for OpenResty Pakcage Manager (OPM).
   
%prep
%setup -q -n "openresty-%{version}"
 
# 包含了模块的构建
%build
./configure \
    --prefix="%{orprefix}" \
    --with-cc='ccache gcc -fdiagnostics-color=always' \
    --with-cc-opt="-DNGX_LUA_ABORT_AT_PANIC -I%{zlib_prefix}/include -I%{pcre_prefix}/include -I%{openssl_prefix}/include" \
    --with-ld-opt="-L%{zlib_prefix}/lib -L%{pcre_prefix}/lib -L%{openssl_prefix}/lib -Wl,-rpath,%{zlib_prefix}/lib:%{pcre_prefix}/lib:%{openssl_prefix}/lib" \
    --with-pcre-jit \
    --without-http_rds_json_module \
    --without-http_rds_csv_module \
    --without-lua_rds_parser \
    --with-stream \
    --with-stream_ssl_module \
    --with-stream_ssl_preread_module \
    --with-http_v2_module \
    --without-mail_pop3_module \
    --without-mail_imap_module \
    --without-mail_smtp_module \
    --with-http_stub_status_module \
    --with-http_realip_module \
    --with-http_addition_module \
    --with-http_auth_request_module \
    --with-http_secure_link_module \
    --with-http_random_index_module \
    --with-http_gzip_static_module \
    --with-http_sub_module \
    --with-http_dav_module \
    --with-http_flv_module \
    --with-http_mp4_module \
    --with-http_gunzip_module \
    --with-threads \
    --with-compat \
    --add-module=./ngx_healthcheck_module \  
    --with-luajit-xcflags='-DLUAJIT_NUMMODE=2 -DLUAJIT_ENABLE_LUA52COMPAT' \
    -j`nproc`
 
make -j`nproc`
   
%install
rm -rf %{buildroot}
make install DESTDIR=%{buildroot}
 
rm -rf %{buildroot}%{orprefix}/luajit/share/man
rm -rf %{buildroot}%{orprefix}/luajit/lib/libluajit-5.1.a
 
mkdir -p %{buildroot}/usr/bin
ln -sf %{orprefix}/bin/resty %{buildroot}/usr/bin/
ln -sf %{orprefix}/bin/restydoc %{buildroot}/usr/bin/
ln -sf %{orprefix}/bin/opm %{buildroot}/usr/bin/
ln -sf %{orprefix}/nginx/sbin/nginx %{buildroot}/usr/bin/%{name}
 
%if 0%{?use_systemd}
 
mkdir -p %{buildroot}%{_unitdir}
%{__install} -p -m 0644 %{SOURCE1} %{buildroot}%{_unitdir}/
 
%else
 
mkdir -p %{buildroot}/etc/init.d
%{__install} -p -m 0755 %{SOURCE2} %{buildroot}/etc/init.d/%{name}
 
%endif
 
# to silence the check-rpath error
export QA_RPATHS=$[ 0x0002 ]
   
%clean
rm -rf %{buildroot}
   
%post
 
%if 0%{?use_systemd}
%systemd_post openresty.service
%else
%if ! 0%{?suse_version}
/sbin/chkconfig --add %{name}
%endif
%endif
   
%preun
%if 0%{?use_systemd}
%systemd_preun openresty.service
%else
%if ! 0%{?suse_version}
if [ $1 = 0 ]; then
    /sbin/service %{name} stop >/dev/null 2>&1
    /sbin/chkconfig --del %{name}
fi
%endif
%endif
   
%if 0%{?use_systemd}
%postun
%systemd_postun_with_restart openresty.service
%endif
   
%files
%defattr(-,root,root,-)
 
%if 0%{?use_systemd}
%{_unitdir}/%{name}.service
%else
/etc/init.d/%{name}
%endif
/usr/bin/%{name}
%{orprefix}/bin/openresty
%{orprefix}/site/lualib/
%{orprefix}/luajit/*
%{orprefix}/lualib/*
%{orprefix}/nginx/html/*
%{orprefix}/nginx/logs/
%{orprefix}/nginx/sbin/*
%config(noreplace) %{orprefix}/nginx/conf/*
%{orprefix}/COPYRIGHT
   
%files resty
%defattr(-,root,root,-)
 
/usr/bin/resty
%{orprefix}/bin/resty
   
%files doc
%defattr(-,root,root,-)
 
/usr/bin/restydoc
%{orprefix}/bin/restydoc
%{orprefix}/bin/restydoc-index
%{orprefix}/bin/md2pod.pl
%{orprefix}/bin/nginx-xml2pod
%{orprefix}/pod/*
%{orprefix}/resty.index
   
%files opm
%defattr(-,root,root,-)
 
/usr/bin/opm
%{orprefix}/bin/opm
%{orprefix}/site/manifest/
%{orprefix}/site/pod/

说明

对于包含ngx_healthcheck_module 的rpm 我已经push 到github 了大家可以直接安装使用,实际上我们可以直接做一个yum 私服使用

参考资料

https://github.com/openresty/openresty-packaging
https://github.com/rongfengliang/my-rpms/tree/master/x86_64



这篇关于openresty rpm 构建的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程