借助fpm轻松打包rpm

fpm介绍

项目地址:https://github.com/jordansissel/fpm

fpm的目标是使构建软件包(如rpm,deb,OSX软件包等)变得容易且快速。

简单说就是将一种类型的包转换成另一种类型。

安装fpm

  1. fpm是ruby写的,因此系统环境需要ruby,CentOS 7需要ruby版本号大于2.2。

  2. 安装ruby模块

    yum -y install ruby rubygems ruby-devel rpm-build

  3. 查看当前使用的rubygems仓库

    gem sources list

  4. 添加淘宝的Rubygems仓库,外国的源慢,移除原生的Ruby仓库

    gem sources --add https://ruby.taobao.org/ --remove http://rubygems.org/

  5. 安装fpm,gem从rubygem仓库安装软件类似yum从yum仓库安装软件。

    gem install fpm

ps: 遇到安装错误请检查ruby版本

使用fpm

常用参数

    -s          指定源类型
    -t          指定目标类型,即想要制作为什么包
    -n          指定包的名字
    -v          指定包的版本号
    -C          指定打包的相对路径  Change directory to here before searching forfiles
    -d          指定依赖于哪些包
    -f          第二次打包时目录下如果有同名安装包存在,则覆盖它
    -p          输出的安装包的目录,不想放在当前目录下就需要指定
    --post-install      软件包安装完成之后所要运行的脚本;同--after-install
    --pre-install       软件包安装完成之前所要运行的脚本;同--before-install
    --post-uninstall    软件包卸载完成之后所要运行的脚本;同--after-remove
    --pre-uninstall     软件包卸载完成之前所要运行的脚本;同--before-remove

打包rpm实例

  1. 创建文件夹

    mkdir -p /opt/server/{pkg,scripts}

  2. 创建用户

    useradd -s /sbin/nologin -M www

  3. 下载nginx源码包,解压

    wget http://nginx.org/download/nginx-1.16.1.tar.gz

    tar zxvf nginx-1.16.1.tar.gz

  4. yum安装依赖

    yum install -y pcre-devel openssl-devel

  5. 编译安装

./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_sub_module --with-stream --with-stream_ssl_module

make

make install

  1. 准备安装用到的脚本
[root@localhost scripts]# cat /opt/server/scripts/nginx_install_before.sh
#!/bin/bash

useradd www -s /sbin/nologin -M
mkdir -p /etc/nginx

[root@localhost scripts]# cat /opt/server/scripts/nginx_install_after.sh 
#!/bin/bash

ln -s /usr/local/nginx/sbin/* /usr/local/sbin/
ln -s /usr/local/nginx/conf/nginx.conf /etc/nginx

  1. 打包rpm,默认输出到当前路径
 fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'pcre-devel,openssl-devel' --before-install /opt/server/scripts/nginx_install_pre.sh --after-install /opt/server/scripts/nginx_install_post.sh -f /usr/local/nginx/

rpm包的使用方法

  1. rpm命令安装

    [root@localhost~]# rpm -ivh nginx-1.16.1-1.x86_64.rpm

    error: Failed dependencies:

    pcre-devel is needed by nginx-1.16.1-1.x86_64

    openssl-devel is needed nginx-1.16.1-1.x86_64

但会报如上依赖错误,需要先yum安装依赖才能安装rpm包。

  1. yum命令安装rpm包

    yum -y localinstall nginx-1.16.1-1.x86_64.rpm

这个命令会自动先安装rpm包的依赖,然后再安装rpm包。

  1. 离线网络下需要先搭建本地YUM源
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值