1. nginx

1.1 rpm-build安装

  1. # 安装rpm-build
  2. yum install -y rpm-build
  3. # 创建目录 (通过报错产生目录)
  4. cd ~; rpmbuild -ba nginx.spec
  5. # 目录结构
  6. tree -n ~/rpmbuild/
  7. /root/rpmbuild/
  8. ├── BUILD 配置编译目录
  9. ├── BUILDROOT
  10. ├── RPMS rpmbuild制作好的二进制包
  11. ├── SOURCES 源代码
  12. ├── SPECS 管理rpm制作进程的spec文件
  13. └── SRPMS rpmbuild制作好的源码包
  14. # 编写spec文件 (文件内容在2.3章节)
  15. vim ~/rpmbuild/SPECS/nginx.spec

1.2 制作rpm

  1. # centos8 (注意exclude顺序)
  2. tar cvzf nginx-1.22.0.tar.gz \
  3. --exclude nginx-1.22.0/objs --exclude nginx-1.22.0/objs/* \
  4. nginx-1.22.0
  5. # 拷贝tar.gz源代码
  6. mv nginx-1.22.0.tar.gz ~/rpmbuild/SOURCES
  7. # 制作rpm包
  8. rpmbuild -bb ~/rpmbuild/SPECS/nginx.spec
  9. # 查看rpm
  10. ll ~/rpmbuild/RPMS/x86_64/nginx-1.22.0-1.el8.x86_64.rpm

1.3 nginx.spec

  1. Name:nginx
  2. Version:1.22.0
  3. Release: 1%{?dist}
  4. Summary:this is a web server
  5. #Group:
  6. License:GPL
  7. URL:www.abc.com
  8. Source0:nginx-1.22.0.tar.gz
  9. #BuildRequires:
  10. #Requires:
  11. %description
  12. this is a web server
  13. %prep
  14. %setup -q
  15. %build
  16. ./configure --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx \
  17. --modules-path=/usr/lib64/nginx/modules --conf-path=/etc/nginx/nginx.conf \
  18. --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log \
  19. --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock \
  20. --http-client-body-temp-path=/var/cache/nginx/client_temp \
  21. --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
  22. --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
  23. --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
  24. --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
  25. --user=nginx --group=nginx --with-compat --with-file-aio --with-threads \
  26. --with-http_addition_module --with-http_auth_request_module \
  27. --with-http_dav_module --with-http_flv_module --with-http_gunzip_module \
  28. --with-http_gzip_static_module --with-http_mp4_module \
  29. --with-http_random_index_module --with-http_realip_module \
  30. --with-http_secure_link_module --with-http_slice_module \
  31. --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module \
  32. --with-http_v2_module --with-mail --with-mail_ssl_module --with-stream \
  33. --with-stream_realip_module --with-stream_ssl_module \
  34. --with-stream_ssl_preread_module \
  35. --with-cc-opt='-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector-strong --param=ssp-buffer-size=4 -grecord-gcc-switches -m64 -mtune=generic -fPIC' \
  36. --with-ld-opt='-Wl,-z,relro -Wl,-z,now -pie'
  37. make %{?_smp_mflags}
  38. %install
  39. %make_install
  40. make install
  41. %files
  42. %doc
  43. /etc/nginx/*
  44. /usr/sbin/nginx
  45. %changelog

1.4 一键rpm脚本

  1. #!/bin/bash
  2. nginx_src_path="/root/source"
  3. nginx_src_dir_name="nginx-1.22.0"
  4. rpm_path="/root/rpmbuild"
  5. rpm_src_dir_name="SOURCES"
  6. # get src tar.gz
  7. tar cvzf ${rpm_path}/${rpm_src_dir_name}/${nginx_src_dir_name}.tar.gz \
  8. --exclude objs --exclude objs/* \
  9. -C ${nginx_src_path} ${nginx_src_dir_name}
  10. # get rpm
  11. rpmbuild -bb ${rpm_path}/SPECS/nginx.spec
  12. ls -al ${rpm_path}/RPMS/x86_64/${nginx_src_dir_name}-*rpm

2. openresty