【运维工具】fpm实现nginx打包

本文介绍如何使用fpm工具在Linux环境下打包Nginx软件包,包括安装fpm及依赖、配置Nginx、执行打包脚本等步骤,最终生成可用于安装的rpm包。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

fpm是一个ruby实现的对rpmbuild进行封装的打包工具,方便linux系统下定制软件包管理,如下为Nginx打包示例供参考。

1. 安装fpm依赖包
yum -y  install ruby-devel gcc make rpm-build rubygems
2.安装fpm
gem install --no-ri --no-rdoc fpm
fpm --version
3.Nginx打包

安装pcre和openssl包

yum  install pcre pcre-devel openssl openssl-devel
mkdir -p /root/build/src 
mkdir -p /root/install/opt
cd /root/build/src/
wget http://nginx.org/download/nginx-1.13.4.tar.gz
tar -xvf nginx-1.13.4.tar.gz
cd nginx-1.13.4
./configure --prefix=/root/install/opt/nginx
make && make install
安装包后执行脚本(可根据需求定制):
cat /root/build/post-install.sh
#!/bin/bash
useradd nginx -M -s /sbin/nologin
chown nginx:nginx /opt/nginx -R

2.打包

fpm -s dir -t rpm -C /root/install -n nginx -v 1.13.4 \
--license BSD --url "https://www.nginx.com/" \
--post-install /root/build/post-install.sh --iteration 1 \
--vendor "admin@gmail.com" \
--description "Nginx v1.13.4 build in 2017/08/26" \
-d "pcre,pcre-devel,openssl,openssl-devel"

注:fpm -C 参数下目录结构为包实际安装目录。

当前目录生成nginx-1.13.4-1.x86_64.rpm包

rpm -ivh nginx-1.13.4-1.x86_64.rpm

[root@centos7-linux build]# rpm -qa| grep nginx
nginx-1.13.4-1.x86_64

[root@centos7-linux build]# ll /opt/nginx/
total 4
drwxr-xr-x. 2 nginx nginx 4096 Aug 26 09:01 conf
drwxr-xr-x. 2 nginx nginx   40 Aug 26 09:01 html
drwxr-xr-x. 2 nginx nginx    6 Aug 26 09:00 logs
drwxr-xr-x. 2 nginx nginx   19 Aug 26 09:01 sbin

[root@centos7-linux ~]# rpm -qi nginx
Name        : nginx
Version     : 1.13.4
Release     : 1
Architecture: x86_64
Install Date: Sat 26 Aug 2017 12:04:42 PM EDT
Group       : default
Size        : 3755485
License     : BSD
Signature   : (none)
Source RPM  : nginx-1.13.4-1.src.rpm
Build Date  : Sat 26 Aug 2017 12:03:55 PM EDT
Build Host  : centos7-linux.shared
Relocations : /
Packager    : <root@centos7-linux.shared>
Vendor      : admin@gmail.com
URL         : https://www.nginx.com/
Summary     : Nginx v1.13.4 build in 2017/08/26
Description :  Nginx v1.13.4 build in 2017/08/26

结束语:fpm功能较多,此例为简单打包演示,具体定制请参照官方文档深入。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值