1. Download nginx source code package
wget http://nginx.org/download/nginx-1.20.1.tar.gz
2. Update yum software source
yum update
3. Download compilation tools and dependencies
yum install -y gcc pcre-devel pcre zlib zlib-devel
4. Unzip the tar package
tar -zxvf nginx-1.20.1.tar.gz -C ~/
5. Enter the source code file to configure compilation information
# --prefix后面加的是绝对地址 意思是编译安装后软件输出的位置
./configure --prefix=/opt/nginx
6. Compile & compile and install
make && make install
7.Install RAM Key
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
8. Install RAM
curl -L get.rvm.io | bash -s stable
9. Update RAM configuration file
source /etc/profile.d/rvm.sh
10.Install Ruby2.6
rvm install 2.6
11. Check whether ruby is installed successfully
ruby -v
12. Install fpm dependent modules
yum -y install rubygems ruby-devel
13. Replace rubygems warehouse
gem sources -a http://mirrors.aliyun.com/rubygems/
gem sources --remove https://rubygems.org/
gem source list
14.Install fpm tool
gem install fpm
15. Check whether fpm is installed correctly
fpm --help
16.Write shell file
vim /root/rpm_building/ngnix_rpm.sh
#!/bin/bash
# 源码编译一般都要添加执行用户
useradd nginx -M -s /sbin/nologin
17. Packing
Packaging format:
fpm -s 源文件类型 -t 目标文件类型 -n 打包后名称 -v 打包后版本号 -d 所需要依赖 --post-install 安装完后执行的脚本 -f 源文件地址
fpm -s dir -t rpm -n nginx -v 1.20.1 -d 'pcre-devel,openssl-devel' --post-install /root/rpm_building/ngnix_rpm.sh -f /opt/nginx/
Parameter Description:
1.-s specifies the source type
2.-t specifies the target type, that is, what package you want to make
3.-n specifies the name of the package
4.-v specifies the version number of the package
5.-d specifies which packages it depends on
6.- f If there is an installation package with the same name in the directory during the second packaging, it will be overwritten.
7. –post-install script to be run after the software package is installed; the same as –after-install
Possible errors:
- Need executable ‘rpmbuild’ to convert dir to rpm {:level=>:error}
Solution: install rpm-build
yum install rpm-build -y