Carry の Blog Carry の Blog
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)

Carry の Blog

好记性不如烂键盘
首页
  • Nginx
  • Prometheus
  • Iptables
  • Systemd
  • Firewalld
  • Docker
  • Sshd
  • DBA工作笔记
  • MySQL
  • Redis
  • TiDB
  • Elasticsearch
  • Python
  • Shell
  • MySQL8-SOP手册
  • 分类
  • 标签
  • 归档
GitHub (opens new window)
  • 工作笔记

  • K8S

  • Systemd

  • Nginx

    • Nginx添加用户认证
    • 利用nginx+sftp实现一个可供用户下载的服务
    • nginx配置文件及模块
    • 通过脚本按天切割nginx的日志
    • nginx通过四层代理实现端口转发
    • NGINX基于cookie针对同一域名进行分流转发
    • nginx利用内置模块配置限速限流
    • 利用NGINX内置模块mirror进行流量复制等操作
    • 使用$remote_user字段记录访问NGINX的用户
    • 从NGINX自身配置文件中定义访问日志按时间切割
    • NGINX配置单独代理百度的sitemap文件
    • nginx配置微信小程序校验及其他
    • nginx配置gzip压缩
    • 由Nginx集中代理分散的PHP集群的实践
    • http状态码详解
    • OpenResty-1-13-6-2-新增ldap模块儿
    • 排查NGINX的open_file_cache导致发布后访问404的问题
    • 制作OpenResty-1-19-9-1的RPM包
      • 1,物料
      • 2,我的
      • 3,打包
      • 4,模块儿
    • nginx-proxy-managar使用笔记
    • Nginx 的端口复用:提升服务器并发能力
  • Supervisord

  • OpenLdap

  • OpenVPN

  • GitLab

  • Sshd

  • WebDev

  • Docker

  • Prometheus

  • Rclone

  • Iptables

  • Firewalld

  • Linux笔记
  • Nginx
Carry の Blog
2021-10-21
目录

制作OpenResty-1-19-9-1的RPM包收藏(二丫讲梵)备查

源码包有源码包的灵活,RPM包有RPM包的方便,一些比较常用的生产工具包,打成RPM包还是比较方便的。

# 1,物料

  • openresty官网 (opens new window)
  • openresty-packaging (opens new window):官方维护的RPM构建的基础文件。

# 2,我的

官方提供的包大多给的是默认配置,不大适合在生产直接使用,因此借鉴官方的包进行了一些简单的调整改造,并将基础文件整理成了项目:

rpmbuild

工作中常用的RPM构建spec

- name: rpmbuild
  desc: 工作中常用的RPM构建spec
  avatar: https://avatars2.githubusercontent.com/u/416130?s=460&u=8753e86600e300a9811cdc539aa158deec2e2724&v=4 # 可选
  link: https://github.com/carry00/rpmbuild # 可选
  bgColor: '#FBDE4B' # 可选,默认var(--bodyBg)。颜色值有#号时请添加单引号
  textColor: '#fff' # 可选,默认var(--textColor)
1
2
3
4
5
6

调整说明如下:

  • 替换了默认的nginx.conf文件内容

    • 调整日志格式为json,日志路径如下

      error_log /data/log/error.log;
      access_log /data/log/tmp.log json;
      
      1
      2
    • 调整支持传递带有下划线的header。

  • 主动创建一些软链,便于维护或者规范

    ln -snf /usr/local/openresty/nginx/sbin/nginx /usr/sbin/nginx
    ln -snf /usr/local/openresty/nginx/conf /etc/nginx
    
    1
    2
  • 添加基于logrotate的日志清理策略

    /data/log/tmp.log
    /data/log/error.log
    {
        daily
        dateext
        missingok
        rotate 7
        notifempty
        create 755 www
        sharedscripts
        postrotate
            [ -f /var/run/nginx.pid ] && kill -USR1 `cat /var/run/nginx.pid`
        endscript
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

添加模块儿如下:

  • 添加ldap模块儿的支持
  • 添加upsync模块儿的支持

# 3,打包

如下内容基于CentOS7进行。

首先将项目克隆在主机的root目录下,因为rpmbuild有不少变量是基于家目录来做的。

$ git clone https://github.com/carry00/rpmbuild.git
1

配置阿里和openresty的yum源:

$ yum -y install yum-utils
$ yum-config-manager --add-repo http://mirrors.aliyun.com/repo/Centos-7.repo
$ yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
1
2
3

安装基础构建工具:

$ yum -y install rpm-build redhat-rpm-config rpmdevtools
1

安装项目编译依赖:

$ yum -y install gcc gcc-c++ systemtap-sdt-devel openresty-zlib-devel openresty-openssl-devel openresty-pcre-devel gd-devel openresty-openssl111-devel ccache
1

下载spec中定义的源码文件:

# 进入到工作目录
$ cd /root/rpmbuild/SPECS/openresty/
$ spectool -g -R openresty.spec
1
2
3

执行打包命令:

$ rpmbuild -ba openresty.spec
1

当看到最后结果返回值为0时,则说明构建成功。如果有报错,则根据报错信息进行具体应对工作。

成功之后,会在 /root/rpmbuild/RPMS 目录中生成构建好的rpm包。

查看构建的包信息:

$ cd /root/rpmbuild/RPMS/x86_64
$ rpm -qpi openresty-1.19.9.1-1.eryajf.el7.x86_64.rpm
Name        : openresty
Version     : 1.19.9.1
Release     : 1.eryajf.el7
Architecture: x86_64
Install Date: (not installed)
Group       : System Environment/Daemons
Size        : 3714763
License     : BSD
Signature   : (none)
Source RPM  : openresty-1.19.9.1-1.eryajf.el7.src.rpm
Build Date  : Thu Oct 21 23:00:12 2021
Build Host  : 13264c814536
Relocations : (not relocatable)
Packager    : https://github.com/carry00
URL         : https://openresty.org/
Summary     : OpenResty, scalable web platform by extending NGINX with Lua
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.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35

# 4,模块儿

日常工作中可能会有其他模块儿的使用场景,一般通过 --add-module进行添加,我这里目前添加了两个模块儿:

$ ll
total 104
-rw-r--r--  1 liqilong  staff    12K 10 21 14:59 openresty-ldap.spec
-rw-r--r--  1 liqilong  staff    12K 10 21 14:58 openresty-upsync.spec
1
2
3
4

一个是支持基于ldap做认证的ldap模块儿。配置参考:点我 (opens new window)

一个是微博开源的能够基于consul做配置中心的upsync模块儿。

如果你在使用过程中有什么问题,欢迎留言交流。

#nginx#openresty#rpm#consul#ldap
上次更新: 4/24/2025

← 排查NGINX的open_file_cache导致发布后访问404的问题 nginx-proxy-managar使用笔记→

最近更新
01
tidb fast ddl
04-04
02
TiDB配置文件调优 原创
04-03
03
如何移除TiDB中的表分区 原创
04-03
更多文章>
Theme by Vdoing
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式