使用nginx官方SPRM进行重建

使用nginx官方SPRM进行重新构建

One possible paraphrase in Chinese could be: “目标” (mù

由于在 Apache httpd 中,可以快速使用 yum 进行安装,而在 nginx 中,模块完全是第三方选项,因此决定创建一个尽可能接近 nginx 官方 Yum 仓库的自定义 RPM 包。

这次的需求

    • LDAP対応

 

    • HTTP/2対応

 

    • SSLライブラリ埋め込み

 

    • 複数サーバへ展開するのと後々バージョンあげるかもしれないのでお手軽にrpm化

 

    CentOS7向け

为了完全支持HTTP/2标准,LDAP模块需要使用openssl库的某个特定版本。然而,由于CentOS7的官方仓库中没有分发该版本,所以必须进行嵌入。

因为有这样的原因,收集必要的源代码包也是一件很繁琐的事情,所以我们使用nginx-build作为下载器。

在Docker容器中进行rpmbuild可以更加方便。

请注意

    • pcre

 

    zlib

虽然可以将以上的软件包集成在一起,但由于我现在没有遇到问题,所以我使用操作系统标准的软件包进行编译。

流程

1. 下载所需的东西 (Xia zai suo xu de dongxi)

    1. 下载nginx-build二进制文件并解压到HOME目录。

 

    1. 从官方网站下载想要构建的nginx-SRPM版本,命令为wget http://nginx.org/packages/centos/7/SRPMS/nginx-1.12.1-1.el7.ngx.src.rpm。

在HOME目录下安装nginx-SRPM,文件将被解压。命令为rpm -Uvh {SRPM路径}。

安装所需的依赖包(操作系统标准包)。命令为sudo yum install pcre-devel.x86_64 zlib-devel.x86_64 openldap-devel.x86_64。

下载nginx-build的最新版本。命令为./nginx-build -v 1.12.1 -m module_3rdparty.ini -openssl -clear -configureonly -d work。

//module_3rdparty.ini
[nginx-auth-ldap]
form=git
url=https://github.com/kvspb/nginx-auth-ldap
rev=master

当您通过nginx-build进行下载时,将生成以下目录。

$ ls -la work/nginx/1.12.1/
nginx-1.12.1/ nginx-1.12.1.tar.gz nginx-auth-ldap/ nginx-auth-ldap.log openssl-1.0.2n/ openssl-1.0.2n.tar.gz

模块的目录看起来是这样的

ls -la work/nginx/1.12.1/nginx-auth-ldap/
total 100
drwxrwxrwx 3 builder builder 113 Apr 16 11:43 .
drwxr-xr-x 5 builder builder 148 Apr 16 11:43 ..
drwxrwxrwx 8 builder builder 152 Apr 16 11:43 .git
-rw-rw-rw- 1 builder builder 1507 Apr 16 11:43 LICENSE
-rw-rw-rw- 1 builder builder 3537 Apr 16 11:43 README.md
-rw-rw-rw- 1 builder builder 672 Apr 16 11:43 config
-rw-rw-rw- 1 builder builder 1590 Apr 16 11:43 example.conf
-rw-rw-rw- 1 builder builder 83529 Apr 16 11:43 ngx_http_auth_ldap_module.c

2. 准备建造

    进入工作目录下的nginx版本1.12.1文件夹,打包nginx-auth-ldap文件并将其储存在~/rpmbuild/SOURCES/nginx-auth-ldap.tar.gz中。将openssl-1.0.2l.tar.gz文件复制到~/rpmbuild/SOURCES/目录中。

修改SPEC文件

我所做的

    • opensslは同梱させるのでrequireを外す

 

    • module追加するのでそれのオプションを追加

–add-module=nginx-auth-ldap –with-openssl=openssl-1.0.2l –with-openssl-opt=’-fPIC'”

build時に同梱させるのでそのオプションを追加

Source14: nginx-auth-ldap.tar.gz
Source15: openssl-1.0.2l.tar.gz
%setup -a 14 -a 15 -q -n nginx-%{version}

关于setup宏选项的含义,您可以在这里参考:
https://vinelinux.org/docs/vine6/making-rpm/setup-macro.html

这里是以上内容的diff。

diff -u nginx.spec rpmbuild/SPECS/nginx.spec
--- nginx.spec 2017-07-11 22:49:34.000000000 +0900
+++ rpmbuild/SPECS/nginx.spec 2017-09-12 18:53:00.060241472 +0900
@@ -12,8 +12,8 @@
Requires(pre): shadow-utils
Requires: initscripts >= 8.36
Requires(post): chkconfig
-Requires: openssl
-BuildRequires: openssl-devel
+#Requires: openssl
+#BuildRequires: openssl-devel
%endif
%if 0%{?rhel} == 6
@@ -21,8 +21,8 @@
Requires(pre): shadow-utils
Requires: initscripts >= 8.36
Requires(post): chkconfig
-Requires: openssl >= 1.0.1
-BuildRequires: openssl-devel >= 1.0.1
+#Requires: openssl >= 1.0.1
+#BuildRequires: openssl-devel >= 1.0.1
%endif
%if 0%{?rhel} == 7
@@ -31,9 +31,9 @@
Epoch: %{epoch}
Requires(pre): shadow-utils
Requires: systemd
-Requires: openssl >= 1.0.1
+#Requires: openssl >= 1.0.1
BuildRequires: systemd
-BuildRequires: openssl-devel >= 1.0.1
+#BuildRequires: openssl-devel >= 1.0.1
%endif
%if 0%{?suse_version} == 1315
@@ -41,7 +41,7 @@
%define nginx_loggroup trusted
Requires(pre): shadow
Requires: systemd
-BuildRequires: libopenssl-devel
+#BuildRequires: libopenssl-devel
BuildRequires: systemd
%endif
@@ -55,7 +55,7 @@
%define WITH_CC_OPT $(echo %{optflags} $(pcre-config --cflags)) -fPIC
%define WITH_LD_OPT -Wl,-z,relro -Wl,-z,now -pie
-%define BASE_CONFIGURE_ARGS $(echo "--prefix=%{_sysconfdir}/nginx --sbin-path=%{_sbindir}/nginx --modules-path=%{_libdir}/nginx/modules --conf-path=%{_sysconfdir}/nginx/nginx.conf --error-log-path=%{_localstatedir}/log/nginx/error.log --http-log-path=%{_localstatedir}/log/nginx/access.log --pid-path=%{_localstatedir}/run/nginx.pid --lock-path=%{_localstatedir}/run/nginx.lock --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp --user=%{nginx_user} --group=%{nginx_group} --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module")
+%define BASE_CONFIGURE_ARGS $(echo "--prefix=%{_sysconfdir}/nginx --sbin-path=%{_sbindir}/nginx --modules-path=%{_libdir}/nginx/modules --conf-path=%{_sysconfdir}/nginx/nginx.conf --error-log-path=%{_localstatedir}/log/nginx/error.log --http-log-path=%{_localstatedir}/log/nginx/access.log --pid-path=%{_localstatedir}/run/nginx.pid --lock-path=%{_localstatedir}/run/nginx.lock --http-client-body-temp-path=%{_localstatedir}/cache/nginx/client_temp --http-proxy-temp-path=%{_localstatedir}/cache/nginx/proxy_temp --http-fastcgi-temp-path=%{_localstatedir}/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=%{_localstatedir}/cache/nginx/uwsgi_temp --http-scgi-temp-path=%{_localstatedir}/cache/nginx/scgi_temp --user=%{nginx_user} --group=%{nginx_group} --with-compat --with-file-aio --with-threads --with-http_addition_module --with-http_auth_request_module --with-http_dav_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream --with-stream_realip_module --with-stream_ssl_module --with-stream_ssl_preread_module --add-module=nginx-auth-ldap --with-openssl=openssl-1.0.2l --with-openssl-opt='-fPIC'")
Summary: High performance web server
Name: nginx
@@ -78,6 +78,8 @@
Source11: nginx-debug.service
Source12: COPYRIGHT
Source13: nginx.check-reload.sh
+Source14: nginx-auth-ldap.tar.gz
+Source15: openssl-1.0.2l.tar.gz

License: 2-clause BSD-like license

@@ -96,7 +98,7 @@
%endif

%prep
-%setup -q
+%setup -a 14 -a 15 -q -n nginx-%{version}
cp %{SOURCE2} .
sed -e 's|%%DEFAULTSTART%%|2 3 4 5|g' -e 's|%%DEFAULTSTOP%%|0 1 6|g' \
-e 's|%%PROVIDES%%|nginx|g' < %{SOURCE2} > nginx.init

4. 运行build

    如果执行用户是build用户,请更改为该用户。切换到~/rpmbuild目录,然后执行rpmbuild -ba –clean SPECS/nginx.spec。如果没有错误,将在RPMS/目录中生成rpm文件。
广告
将在 10 秒后关闭
bannerAds