无意中看到一张架构图,迁出代码使用本地FPM打包,看不懂FPM是什么高级玩意,于是有了下文。
使用FPM封装RPM包_第1张图片

FPM介绍

简单的说FPM就是将一种类型的包转换到另外一种的类型。比如我们常说的将编译安装的包转换到rpm包。
进一步的官方说明可参考:
https://docs.google.com/present/view?id=0Aa9liCTsAyzRZGNtd3dkOTRfMTdmczY2azlkcg&hl=en
支持的源类型包有:rpm、npm、rubygem、ded、python、dir
支持的输出类型有:rpm、ded、solaris、puppet
本例只要介绍常用的rpm包制作方法,至于其它的功能可自行探索。

FPM安装

# 安装ruby
yum -y install ruby rubygems ruby-devel
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
gem sources -l
gem install fpm

使用FPM打RPM包

FPM常用参数

-s :指定源类型
-t :指定目标类型,即想要制作为什么包
-n :指定包的名字
-v :指定包的版本号
-C :指定打包的相对路径,即build directory
原文解释为:Change directory to here before searching for files
-d --depends :指定依赖于哪些包
--post-install :软件包安装完成之后所要运行的脚本;和”--after-install” 意思一样
--pre-install :软件包安装完成之前所要运行的脚本;和”--before-install” 意思一样
--post-uninstall :软件包卸载完成之后所要运行的脚本;和”--after-remove”意思一样
--pre-uninstall:软件包卸载完成之前所要运行的脚本;和”--before-remove”意思一样

fpm封包rpm

#这个 -C 是相对路径,在另外的服务器上执行rmp -ivh 会安装根目录下
[root@rabbitmq02 ~]# fpm -s dir -t rpm -n website -v 1.0.1 -C /root/downloads/

Created package {:path=>"website-1.0.1-1.x86_64.rpm"}
#绝对路径,这个比较好用
[root@rabbitmq02 ~]# fpm -s dir -t rpm -n website -v 1.0.2 -f  /root/downloads/

Created package {:path=>"website-1.0.2-1.x86_64.rpm"}
# 自己对文件进行增删,然后到第二台服务器rpm -Uvh 包名进行升级
[root@rabbitmq02 ~]# fpm -s dir -t rpm -n website -v 1.0.3 -f  /root/downloads/
Force flag given. Overwriting package at website-1.0.3-1.x86_64.rpm {:level=>:warn}

Created package {:path=>"website-1.0.3-1.x86_64.rpm"}
#自己对文件进行增删,然后到第二台服务器rpm -Uvh 包名进行升级
[root@rabbitmq02 ~]# fpm -s dir -t rpm -n website -v 1.0.4 -f  /root/downloads/ 
Created package {:path=>"website-1.0.4-1.x86_64.rpm"}

注意:website-1.0.3-1.x86_64.rpm生成的包名要每次不一样才能进行rpm -Uvh 升级,不懂的,需要rpm基础

查看安装包内容

第二台服务器上,看看rpm包安装的位置

[root@centos-docker ~]# rpm -qa|grep website
website-1.0.4-1.x86_64
[root@centos-docker ~]# rpm -ql website-1.0.4-1.x86_64
/root/downloads/3.txt
/root/downloads/python/2.txt
/root/downloads/python/login.py
/root/downloads/python/login.pyc
/root/downloads/python/logview.pyc
/root/downloads/python/sessions/068e4c1fbe06272c20bca327a50c46a200df9f1a
/root/downloads/web.py-0.33.tar.gz
/root/downloads/web.py-0.33/PKG-INFO
/root/downloads/web.py-0.33/build/lib/web/__init__.py
/root/downloads/web.py-0.33/build/lib/web/application.py
/root/downloads/web.py-0.33/build/lib/web/browser.py
/root/downloads/web.py-0.33/build/lib/web/contrib/__init__.py
/root/downloads/web.py-0.33/build/lib/web/contrib/template.py
/root/downloads/web.py-0.33/build/lib/web/db.py
/root/downloads/web.py-0.33/build/lib/web/debugerror.py
/root/downloads/web.py-0.33/build/lib/web/form.py
/root/downloads/web.py-0.33/build/lib/web/http.py
/root/downloads/web.py-0.33/build/lib/web/httpserver.py
/root/downloads/web.py-0.33/build/lib/web/net.py
/root/downloads/web.py-0.33/build/lib/web/session.py
/root/downloads/web.py-0.33/build/lib/web/template.py
/root/downloads/web.py-0.33/build/lib/web/test.py
/root/downloads/web.py-0.33/build/lib/web/utils.py
/root/downloads/web.py-0.33/build/lib/web/webapi.py
/root/downloads/web.py-0.33/build/lib/web/webopenid.py
/root/downloads/web.py-0.33/build/lib/web/wsgi.py
/root/downloads/web.py-0.33/build/lib/web/wsgiserver/__init__.py
/root/downloads/web.py-0.33/setup.py
/root/downloads/web.py-0.33/web/__init__.py
/root/downloads/web.py-0.33/web/application.py
/root/downloads/web.py-0.33/web/browser.py
/root/downloads/web.py-0.33/web/contrib/__init__.py
/root/downloads/web.py-0.33/web/contrib/template.py
/root/downloads/web.py-0.33/web/db.py
/root/downloads/web.py-0.33/web/debugerror.py
/root/downloads/web.py-0.33/web/form.py
/root/downloads/web.py-0.33/web/http.py
/root/downloads/web.py-0.33/web/httpserver.py
/root/downloads/web.py-0.33/web/net.py
/root/downloads/web.py-0.33/web/session.py
/root/downloads/web.py-0.33/web/template.py
/root/downloads/web.py-0.33/web/test.py
/root/downloads/web.py-0.33/web/utils.py
/root/downloads/web.py-0.33/web/webapi.py
/root/downloads/web.py-0.33/web/webopenid.py
/root/downloads/web.py-0.33/web/wsgi.py
/root/downloads/web.py-0.33/web/wsgiserver/__init__.py