一.FPM的介紹:
1.FPM項目地址:("https://github.com/jordansissel/fpm")
2.FPM是一個打包工具[ruby的一個模塊]
二.FPM的安裝:
1.安裝依賴包:
[CentOS類系統]
yum -y groupinstall "Development Tools"
yum -y install ruby ruby-devel rubygems gcc openssl-devel
2.安裝FPM:
*添加淘寶的Ruby倉庫
gem sources --add http://ruby.taobao.org/
*移除原生的Ruby倉庫
gem sources --remove http://rubygems.org/
*安裝fpm
gem install arr-pm fpm
3.shell腳本化安裝FPM:
[root@localhost ~]# cat fpm_install.sh
#!/bin/bash
Fpm_Install(){
cat <<EOF
Install Fpm packages
Fpm is based on ruby,Frist you need to install ruby and Install Fpm after that.
EOF
yum -y install ruby rubygems ruby-devel gcc openssl-devel
gem sources --add https://ruby.taobao.org/
gem sources --remove http://rubygems.org/
gem install arr-pm fpm
}
Fpm_Install
三.FPM常用參數:
-f :強制覆蓋[覆蓋同名rpm包]
-n :指定的rpm包名
-p :指定的rpm包文件放置位置
-v :指定的rpm包版本
-d :指定依賴的軟件 ( [-d 'name'] or [-d 'name > version'] 例子: -d 'libstdc++ >= 4.4.3')
-a :指定系統架構,如果是noarch則為'-a all' 或者 '-a native' [x86_64] 當軟件不區分64位或32位的時候可以 noarch
-s :指定INPUT的數據類型 (["-s dir"] 省略數據類型)
-m :指定打包人員[Packager] ([ -m 'user'])
-C :指定打包的相對路徑,類似於buildroot. 譬如-C /tmp/apr/ 而打包機器的數據包路徑是/tmp/apr/{opt,usr,etc} 那安裝這個rpm包后,在本地的數據就是/opt/,/usr/,/etc/
-t :指定需要制作成什么包,可選項有(deb,rpm,solaris,etc)
支持的源類型::
"dir" "rpm" "gem" "python" "empty" "tar" "deb" "cpan" "npm" "osxpkg" "pear" "pkgin" "virtualenv" "zip"
支持的目標類型:
"rpm" "deb" "solaris" "puppet" "dir" "osxpkg" "p5p" "puppet" "sh" "solaris" "tar" "zip"
--description :軟件包描述
--conflicts :指定沖突軟件
--url :指定站點[慣例都是添加軟件的官網 例如: --url "http://www.cnblog.com/roach57" ]
--verbose :安裝過程詳細打印
--after-install :包安裝之后執行的腳本 也可寫作 --post-install FILE
--before-install :包安裝之前執行的腳本
--after-remove :包卸載之后執行的腳本
--before-remove :包卸載之前執行的腳本
--after-upgrade :包更新之后執行的腳本[僅支持 deb 和 rpm 這兩種包]
--before-upgrade :包更新之前執行的腳本
--iteration :發布序號[就是rpm包里面的release]
--epoch :紀元 [不知道干嘛用的]
--no-rpm-sign :不使用rpm簽名 Signature
--license :證書許可 [可選項有 'BSD(開源軟件)' 'GPLv2(自由軟件)' 'MIT' 'Public Domain(公共域)' 'Distributable(貢獻)' 'commercial(商業)' 'Share(共享)等',一般的開發都寫'BSD'或'GPL']
--vendor :供應商名稱 [ --vendor 'roach57@163.com']
--no-depends :代表沒有任何依賴包,和-d是對立的,不能共用
--config-files :指定配置文件,可以指定目錄[遞歸]
--directories :指定包目錄
--category :軟件所屬的類別[這是個什么軟件]下面有個對應的表格:
[參考這個文件 /usr/share/doc/rpm-x.x.x/GROUPS ]
Amusements/Games [娛樂/游戲]
Amusements/Graphics [娛樂/圖形]
Applications/Archiving [應用/文檔]
Applications/Communications [應用/通訊]
Applications/Databases [應用/數據庫]
Applications/Editors [應用/編輯器]
Applications/Emulators [應用/仿真器]
Applications/Engineering [應用/工程]
Applications/File [應用/文件]
Applications/Internet [應用/因特網]
Applications/Multimedia [應用/多媒體]
Applications/Productivity [應用/產品]
Applications/Publishing [應用/印刷]
Applications/System [應用/系統]
Applications/Text [應用/文本]
Development/Debuggers [開發/調試器]
Development/Languages [開發/語言]
Development/Libraries [開發/函數庫]
Development/System [開發/系統]
Development/Tools [開發/工具]
Documentation [文檔]
System Environment/Base [系統環境/基礎]
System Environment/Daemons [系統環境/守護]
System Environment/Kernel [系統環境/內核]
System Environment/Libraries [系統環境/函數庫]
System Environment/Shells [系統環境/接口]
User Interface/Desktops [用戶界面/桌面]
User Interface/X [用戶界面/X窗口]
User Interface/X Hardware Support [用戶界面/X硬件支持]
四.RPM包的組成格式:
roach-1.0.1-57.el6.x86_64.rpm
| | | | |
軟件名稱| | | |
版本號 | | |
發布號 | |
硬件平台 |
擴展名
例子備注:
roach :軟件名稱
1.0.1 :軟件版本號
57.el6 :發布號主要是對軟件存在的bug或漏洞進行修補,在軟件功能上並沒有變化,el6指的是rhel6系統中發布
x86_64 :指64位的PC架構,另外還有'i386' 'i686' 等32位的PC架構,noarch是指不區分硬件架構
rpm :擴展名
五.RPM包制作實例:
1.實例一[用源碼包自定義RPM包]:
以Nginx為例:
* 解壓nginx的tar包:
[root@localhost nginx]# tar -zxf nginx-1.6.2.tar.gz
* 進入到解壓目錄中進行預編譯:
[root@localhost nginx]# cd nginx-1.6.2
[root@localhost nginx-1.6.2]# ./configure \
--prefix=/usr/local/nginx \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \
--http-scgi-temp-path=/var/tmp/nginx/scgi \
--with-pcre \
--with-debug \
* 編譯
[root@localhost nginx-1.6.2]# make -j24 //使用多核編譯
[root@localhost nginx-1.6.2]# mkdir -p /temp/fpm_install/
* 安裝到指定的目錄中:
[root@localhost nginx-1.6.2]# make -j24 install DESTDIR=/temp/fpm_install/
[root@localhost nginx-1.6.2]# ll /temp/fpm_install/
total 16
drwxr-xr-x. 4 root root 4096 Jan 11 08:22 etc
drwxr-xr-x. 2 root root 4096 Jan 11 08:37 tmp
drwxr-xr-x. 4 root root 4096 Jan 11 08:20 usr
drwxr-xr-x. 4 root root 4096 Jan 11 08:20 var
[root@localhost nginx-1.6.2]# cd /temp/fpm_install/tmp
[root@localhost nginx-1.6.2]# cat install_after.sh
#!/bin/bash
source /etc/rc.d/init.d/functions
groupadd -r nginx
useradd -r -g nginx nginx
exit $?
[root@localhost nginx-1.6.2]# cat remove_after.sh
#!/bin/bash
source /etc/rc.d/init.d/functions
rm -rf /usr/local/nginx
rm -rf /etc/nginx
userdel nginx
exit $?
* 制作RPM包:
[root@localhost nginx-1.6.2]# fpm -f -s dir \
-t rpm \
-n nginx \
-v 1.6.2 \
--iteration 1.el6 \
-C /temp/fpm_install/ \
-p /temp/nginx_rpm/ \
--description 'nginx1.6.2_rpm' \
--url 'http://nginx.org/en/' \
--after-install /temp/fpm_install/tmp/install_after.sh \
--after-remove /temp/fpm_install/tmp/remove_after.sh
[root@localhost nginx-1.6.2]# cd /temp/nginx_rpm/;ls
nginx-1.6.2-1.el6.x86_64.rpm
2.實例二[簡單的軟件包制作]:
* 創建測試目錄:
[root@localhost install_rpm]# mkdir /temp/install_rpm
[root@localhost install_rpm]# cd /temp/install_rpm
* 創建測試用的文件和腳本:
[root@localhost install_rpm]# tree roach
roach
├── roach_test
└── tmp
├── mk_dir.sh
└── rm_dir.sh
[root@localhost install_rpm]# cat roach/roach_test
this is the test file!
[root@localhost tmp]# cat mk_dir.sh
#!/bin/bash
source /etc/rc.d/init.d/functions
mkdir -p /temp/roach
exit $?
[root@localhost install_rpm]# cat roach/tmp/mk_file.sh //安裝rpm后執行的腳本
#!/bin/bash
source /etc/rc.d/init.d/functions
cd /temp/roach/
touch {1..10}
exit $?
[root@localhost install_rpm]# cat roach/tmp/rm_dir.sh //卸載完后執行的腳本
#!/bin/bash
source /etc/rc.d/init.d/functions
rm -rf /temp/roach
rm -rf /roach
exit $?
* 制作一個屬於自己的RPM包:
[root@localhost install_rpm]# mkdir -p /temp/roach_rpm
[root@localhost install_rpm]# fpm -f -s dir \
-t rpm \
-n roach \
-v 1.0.1 \
--iteration 1.el6 \
-C /temp/install_rpm/ \
-p /temp/roach_rpm/ \
--description 'roach_test_1.0.1.rpm' \
--url 'http://www.cnblogs.com/roach57' \
--before-install /temp/install_rpm/roach/tmp/mk_dir.sh \
--after-install /temp/install_rpm/roach/tmp/mk_file.sh \
--after-remove /temp/install_rpm/roach/tmp/rm_dir.sh \
--license 'BSD' \
--verbose \
--category 'Application/File' \
-m 'roach' \
--vendor 'roach57@163.com'
* 查看生成的RPM包的信息:
[root@localhost install_rpm]# cd /temp/roach_rpm;ls
roach-1.0.1-1.el6.x86_64.rpm
[root@localhost roach_rpm]# rpm -qp --scripts roach-1.0.1-1.el6.x86_64.rpm
preinstall scriptlet (using /bin/sh):
#!/bin/bash
source /etc/rc.d/init.d/functions
mkdir -p /temp/roach
exit $?
postinstall scriptlet (using /bin/sh):
#!/bin/bash
source /etc/rc.d/init.d/functions
cd /temp/roach/
touch {1..10}
exit $?
postuninstall scriptlet (using /bin/sh):
#!/bin/bash
source /etc/rc.d/init.d/functions
rm -rf /temp/roach
rm -rf /roach
exit $?
[root@localhost roach_rpm]# rpm -qpi roach-1.0.1-1.el6.x86_64.rpm
Name : roach Relocations: /
Version : 1.0.1 Vendor: roach57@163.com
Release : 1.el6 Build Date: Thu 14 Jan 2016 05:44:17 AM EST
Install Date: (not installed) Build Host: localhost
Group : Application/File Source RPM: roach-1.0.1-1.el6.src.rpm
Size : 259 License: BSD
Signature : (none)
Packager : roach
URL : http://www.cnblogs.com/roach57
Summary : roach_test_1.0.1.rpm
Description :
roach_test_1.0.1.rpm
* 安裝rpm包:
[root@localhost roach_rpm]# rpm -ivh roach-1.0.1-1.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:roach ########################################### [100%]
[root@localhost roach_rpm]# tree /roach; tree /temp/roach
/roach
├── roach_test
└── tmp
├── mk_dir.sh
├── mk_file.sh
└── rm_dir.sh
1 directory, 4 files
/temp/roach
├── 1
├── 10
├── 2
├── 3
├── 4
├── 5
├── 6
├── 7
├── 8
└── 9
0 directories, 10 files
* 指定目錄安裝RPM:
[root@localhost roach_rpm]# rpm -ivh roach-1.0.1-1.el6.x86_64.rpm --prefix=/temp
Preparing... ########################################### [100%]
1:roach ########################################### [100%]
[root@localhost tmp]# tree /temp/roach
/temp/roach
├── 1
├── 10
├── 2
├── 3
├── 4
├── 5
├── 6
├── 7
├── 8
├── 9
├── roach_test
└── tmp
├── mk_dir.sh
├── mk_file.sh
└── rm_dir.sh
1 directory, 14 files
* 卸載rpm包:
[root@localhost roach_rpm]# rpm -e roach-1.0.1-1.el6.x86_64
* 實例二完結!
3.FPM運行報錯解決方法如下:
注: 如果正常按照gem去安裝,如果調用fpm失敗,可能是因為cabin的版本有問題[報錯如下]:
[root@localhost ~]# fpm
/usr/lib/ruby/gems/1.8/gems/cabin-0.8.0/lib/cabin/mixins/logger.rb:12:in 'included': undefined method 'options' for #<Cabin::Subscriber:0x7f2580131b48> (NoMethodError)
from /usr/lib/ruby/gems/1.8/gems/cabin-0.8.0/lib/cabin/channel.rb:105:in 'call'
解決方法如下:
卸載當前cabin版本:
[root@localhost ~]# gem uninstall cabin
用舊版本的cabin:
[root@localhost ~]# gem install cabin -v 0.7.2
六.RPM包信息:
1.查看RPM包中的腳本信息:
[root@localhost ~]# rpm -qp --scripts roach-1.0.1-57.el6.x86_64.rpm
postinstall scriptlet (using /bin/sh):
#!/bin/bash
source /etc/rc.d/init.d/functions
cd temp/roach/
for i in {1..10};do
touch $i
done
exit 0
postuninstall scriptlet (using /bin/sh):
#!/bin/bash
source /etc/rc.d/init.d/functions
rm -rf temp/roach
exit 0
2.查看RPM包目錄結構:
[root@localhost ~]# rpm -qpl roach-1.0.1-57.el6.x86_64.rpm
/temp/roach/tmp/mk_dir.sh
/temp/roach/tmp/rm_dir.sh
/temp/roach/roach_test
3.RPM包驗證:
[root@localhost ~]# rpm -K roach-1.0.1-57.el6.x86_64.rpm
roach-1.0.1-57.el6.x86_64.rpm: sha1 md5 OK
4.查看RPM包的屬性:
[root@localhost ~]# rpm -qpi roach-1.0.1-57.el6.x86_64.rpm
Name : roach Relocations: /
Version : 1.0.1 Vendor: roach57@163.com
Release : 57.el6 Build Date: Thu 14 Jan 2016 01:16:33 AM EST
Install Date: (not installed) Build Host: localhost
Group : Application/File Source RPM: roach-1.0.1-57.el6.src.rpm
Size : 205 License: BSD
Signature : (none)
Packager : roach
URL : http://www.cnblogs.com/roach57
Summary : roach5.7_rpm
Description :
roach5.7_rpm
七.RPM包的使用:
1.rpm的安裝:
* rpm默認安裝時默認的根目錄就是系統的'/':
* rpm手動指定安裝時的根目錄[ --prefix=/temp/roach]:
[root@localhost ~]# rpm -ivh roach-1.0.1-57.el6.x86_64.rpm --prefix=/temp/roach
2.rpm的卸載:
[指定卸載的軟件時,省略最后的擴展名.rpm]
[root@localhost ~]# rpm -e roach-1.0.1-57.el6.x86_64
八.注意:
CentOS5和CentOS6之間的rpm包不能混用,因為他們之間的glibc版本不同,動態庫鏈接不上。
九.參考文檔:
https://github.com/jordansissel/fpm/wiki
http://zhaochj.blog.51cto.com/368705/1658496
http://blog.sina.com.cn/s/blog_704836f40101fscj.html
http://www.xiaomastack.com/2014/11/02/scribe-rpm/