rpm 打包
本文档介绍 rpm 打包 的相关内容。
rpm 打包 rpmbuild命令打包较为复杂,这里我们使用简单的打包工具FPM fpm github: https://github.com/jordansissel/fpm/ fpm 功能简单说就是将一种类型的包转换为另一种类型 支持的源类型包 dir 将目录打包成所需要的类型,可以用于源码编译安装的软件包 主要了解 rpm 对rpm进行转换 gem 对rubygem包进行转换 python 将python模块打包成相应的类型 支持的目标类型包 rpm 转换为rpm包 主要了解 deb 转换为deb包 solaris 转换为solaris包 puppet 转换为puppet模块 安装ruby 环境和fpm工具 fpm是ruby 写的,因此系统环境需要安装ruby ,且ruby的版本号大于1.8.5 # 安装Ruby模块 yum -y install ruby rubygems ruby-devel rpm-build # 查看ruby源有哪些 gem source list # 添加阿里云的Rubygems 仓库,外国的源慢 gem sources -a https://mirrors.aliyun.com/rubygems/ # 移除原生的Ruby仓库 gem sources --remove https://rubygems.org/ # 安装fpm gem install fpm fpm使用方法 fpm --help s 指定源类型 t 指定目标类型,即想要制作为什么包 n 指定包的名字 -v 指定包的版本号 C 指定打包的相对路径 change directory to here before searching for files d 指定依赖于哪些包 f 第二次打包时目录下如果有同名安装包存在,则覆盖它 p 输出的安装包目录,不想放在当前目录就指定 -post-install 软件包安装完成之后所需要运行的脚本; 同 --after-install -pre-install 软件包安装完成之前所需要运行的脚本; 同 --before-install -post-uninstall 软件包卸载之后所需要运行的脚本; 同 --after-remove -pre-uninstall 软件包卸载之前所需要运行的脚本; 同 --before-remove 例一: 编写一个脚本 nginx_rpm.sh # !/bin/bash useradd nginx -M -s /sbin/nologin ln -s /application/nginx-1.6.3/ /application/nginx 打包 fpm -s dir -t rpm -n nginx -v 1.6.3 -d 'pcre-devel,openssl-devel' --post-install /server/nginx_rpm.sh -f /application/nginx-1.6.3/ # 说明: # -s dir 指定源的类型为目录 # -t rpm 指定需要打成包的类型 # -n 包的名称 # -v 包的版本 # -d 依赖,多个用,号隔开 # --post-install /server/nginx_rpm.sh 脚本的绝对路径 # -f /application/nginx-1.6.3/ 强制覆盖,包存放的位置 例二: 不能使用相对路径打包 fpm -s dir -t rpm -n nginx -v 1.6.3 -f . # . 为相对路径打包,不能使用这种方式,不然打包出来的内容都被安装到根目录中 如果非要使用相对路径打包可以用下边的目录结构 ├── rpmbuild │ ├── ceph_exporter-2.0.0-1.x86_64.rpm │ └── usr │ ├── bin │ │ └── ceph_exporter │ └── lib │ └── systemd │ └── system │ └── ceph_exporter.service 进入到rpmbuild目录中,执行命令:fpm -s dir -t rpm -n ceph_exporter -v 2.0.0 -f ./usr 本文由作者按照 CC BY 4.0 进行授权