- 準(zhǔn)備安裝包環(huán)境
yum install make gcc gcc-c++ openssl openssl-devel pcre-devel zlib-devel rpm-build-4.11.3-48.el7_9.x86_64 rpmlint.noarch -y
wget http://nginx.org/download/nginx-1.22.1.tar.gz
- 準(zhǔn)備制作RPM包目錄
mkdir -p ~/rpmbuild/SOURCES
cp nginx-1.22.1.tar.gz ~/rpmbuild/SOURCES
- 目錄結(jié)構(gòu)
[root@iZ0jl7nhcg5nazteof1pt3Z ~]# tree -L 3
.
└── rpmbuild
├── BUILD
│ └── nginx-1.22.1
├── BUILDROOT
├── RPMS
│ └── x86_64
├── SOURCES
│ └── nginx-1.22.1.tar.gz
├── SPECS
│ ├── nginx.spec
│ └── nginx.spec.bak
└── SRPMS
4 nginx.spec文件
Summary: High Performance Web Server
Name: nginx
Version: 1.22.1
Release: el7
License: GPL
Group: Applications/Server
Source: nginx-1.22.1.tar.gz
URL: http://nginx.org/
Distribution: Linux
Packager: qiao <181864031@qq.com>
BuildRoot: root/nginx-1.22.1-el7
BuildRequires: gcc,gcc-c++,pcre-devel,zlib-devel
%description
nginx [engine x] is a HTTP and reverse proxy server, as well as a mail proxy server
%post
id nginx &>/dev/null
if [ $? -ne 0 ];
then
useradd nginx
fi
echo "export PATH=/usr/local/nginx/sbin:$PATH" >> /etc/profile
source /etc/profile
declare -a filePaths
filePaths=(/var/log/nginx /var/run /var/cache/nginx)
for i in ${filePaths[*]}
do
if [ ! -d ${i} ];
then
mkdir ${i}
fi
done
%preun
userdel -r nginx
%prep
%setup -q
%build
./configure \
--prefix=/usr/local/nginx \
--user=nginx \
--group=nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--modules-path=/usr/lib64/nginx/modules \
--sbin-path=/usr/local/nginx/sbin/nginx \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_addition_module \
--with-http_sub_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_mp4_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_random_index_module \
--with-http_secure_link_module \
--with-http_stub_status_module \
--with-http_auth_request_module \
--with-mail \
--with-mail_ssl_module \
--with-file-aio \
--with-ipv6 \
--with-stream
make %{?_smp_mflags}
%install
make install DESTDIR=%{buildroot}
%files
/usr/local/nginx
/etc/nginx
5.檢查語法
[root@iZ0jl7nhcg5nazteof1pt3Z SPECS]# rpmlint nginx.spec
nginx.spec:6: W: non-standard-group Applications/Server
nginx.spec:37: W: configure-without-libdir-spec
nginx.spec: W: invalid-url Source0: nginx-1.22.1.tar.gz
0 packages and 1 specfiles checked; 0 errors, 3 warnings.
[root@iZ0jl7nhcg5nazteof1pt3Z SPECS]#
6.生成rpm包
rpmbuild -bb nginx.spec
7安裝包位置
── RPMS
│ └── x86_64
│ ├── nginx-1.22.1-el7.x86_64.rpm
│ └── nginx-debuginfo-1.22.1-el7.x86_64.rpm
├── SOURCES
│ └── nginx-1.22.1.tar.gz
├── SPECS
│ ├── nginx.spec
│ └── nginx.spec.bak
└── SRPMS
8.安裝nginx
rpm -ivh nginx-1.22.1-el7.x86_64.rpm