工作中有如下情况需要将文件打包rpm:
- 避免重复工作,将源码程序打包为rpm
- 使用yum发布项目,项目打包为rpm
- 将自己写好的程序打包为rpm,提供给用户下载
- 其他
以前打包rpm是一个非常复杂的一件事情,自从有了fpm,打包rpm就和tar打包文件一样简单。
安装FPM
1
2
3
4
5
6
7
8
|
# 安装ruby
yum -y install ruby rubygems ruby-devel
# 添加淘宝Ruby仓库
gem sources -a http://ruby.taobao.org/
# 移除原生的Ruby仓库
gem sources --remove http://rubygems.org/
# 安装fpm
gem install fpm
|
准备需要打包目录
今天拿打包一个html文件为例子。实现用户安装rpm将会把index.html放到/data/site/www.ttlsa.com/index.html.
1
2
|
# mkdir /tmp/rpm/data/site/www.ttlsa.com/ -p
# touch /tmp/rpm/data/site/www.ttlsa.com/index.html
|
使用fpm打包目录
先拿一个最简单的例子将大家带入成功,后续在介绍相对复杂的例子。
打包rpm
1
2
3
4
|
# fpm -s dir -t rpm -n website -v 1.0.1 -C /tmp/rpm/
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created package {:path=>"website-1.0.1-1.x86_64.rpm"}
|
查看rpm内文件
1
2
|
# rpm -qpl website-1.0.1-1.x86_64.rpm
/data/site/www.ttlsa.com/index.html
|
安装rpm
1
2
3
|
# rpm -ivh website-1.0.1-1.x86_64.rpm
Preparing... ########################################### [100%]
1:website ########################################### [100%]
|
查看安装信息
1
2
3
4
|
# rpm -qa | grep website
website-1.0.1-1.x86_64
# ll /data/site/www.ttlsa.com/index.html
-rw-r--r-- 1 root root 0 Sep 12 07:50 /data/site/www.ttlsa.com/index.html
|
后续
fpm打包非常简单,更多的fpm使用方法,大家可以百度/谷歌一下。或者等凉白开后续介绍吧!
原文:http://www.ttlsa.com/linux/how-to-use-fpm-rpm/