2021-05-12 14:32:11
Linux下使用FPM封裝製作RPM包
關於FPM的介紹
FPM功能簡單說就是將一種型別的包轉換成另一種型別。
支援的源型別包:“dir”:將目錄打包成所需要的型別,可以用於原始碼編譯安裝的軟體包
“rpm”:對rpm進行轉換
“gem”:對rubygem包進行轉換
“Python”:將python模組打包成相應的型別
支援的目標型別包:
“rpm”:轉換為rpm包
“deb”:轉換為deb包
“solaris”:轉換為solaris包
“puppet”:轉換為puppet模組
這裡主要介紹如何將原始碼安裝的包轉換為RPM/DEB包,其他功能感興趣的可以試試。
安裝環境:
系統CentOS 6.5 64位元,預設的ruby為1.8.7版本;
封裝mysql5.6.29二進位制安裝包;
FPM安裝
FPM的安裝非常簡單,安裝FPM前需要先安裝ruby,rubygem
# FPM是Ruby模組
yum -y install ruby rubygems ruby-devel
#移除原生的Ruby倉庫, 新增淘寶的Ruby倉庫:
gem sources --add https://gems.ruby-china.org/ --remove
https://rubygems.org/
#檢視系統預設的ruby源:
[root@localhost ruby-2.1.10]# gem sources -l
*** CURRENT SOURCES ***
http://rubygems.org/
https://gems.ruby-china.org/
#移除原生的Ruby倉庫, 新增淘寶的Ruby倉庫:
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
[root@localhost ruby-2.1.10]# gem sources --remove http://rubygems.org/
http://rubygems.org/ removed from sources
[root@localhost ruby-2.1.10]# gem sources -l
*** CURRENT SOURCES ***
https://gems.ruby-china.org/
#安裝Fpm軟體包
報錯如下:
[root@localhost data]# gem install fpm #時間較久,然後還報了錯
Building native extensions. This could take a while...
Building native extensions. This could take a while...
ERROR: Error installing fpm:
ruby-xz requires Ruby version >= 1.9.3.
#處理辦法:解除安裝系統自帶的ruby軟體包版本:
yum remove ruby -y
ruby官網下載高於1.9.3的ruby軟體包進行安裝:
#安裝編譯軟體gcc make
yum install gcc make -y
#編譯安裝三部曲:
tar zxf ruby-2.1.10.tar.gz
./configure --prefix=/usr/local/ruby2.1
make -j 4 && make install
#新增環境變數:
# cat /etc/profile.d/ruby2.1.sh
export PATH=$PATH:/usr/local/ruby2.1/bin
#檢視ruby版本:
[root@localhost ~]# source /etc/profile
[root@localhost ~]# ruby -v
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-linux]
報錯如下:
[root@localhost ruby-2.1.10]# gem install fpm
-bash: /usr/bin/gem: No such file or directory
處理辦法:安裝依賴;
yum install rubygems
繼續安裝fpm報錯如下:
# gem install fpm
ERROR: While executing gem ... (Gem::Exception)
Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
處理辦法:安裝依賴;
# yum install openssl
#yum install rpm-build
當然看到這個報錯的時候,第一反應openssl和rpmbuild庫沒裝,yum install openssl rpm-build,發現報錯依舊,緊接看網上的文件編譯zlib,我當然沒這麼乾。
再次安裝依舊報錯,處理辦法:修改源:放棄https 使用http;
[root@localhost ~]# gem sources -a http://gems.ruby-china.org
http://gems.ruby-china.org added to sources
[root@localhost ~]# gem source --remove https://gems.ruby-china.org
https://gems.ruby-china.org removed from sources
[root@localhost ~]# gem source -l
*** CURRENT SOURCES ***
http://rubygems.org/
http://gems.ruby-china.org
#再次安裝發現就沒問題;這個安裝很耗時,時間很久。
[root@localhost bin]# gem install fpm
Fetching: archive-tar-minitar-0.5.2.gem (100%)
Successfully installed archive-tar-minitar-0.5.2
Fetching: cabin-0.9.0.gem (100%)
Successfully installed cabin-0.9.0
Fetching: arr-pm-0.0.10.gem (100%)
Successfully installed arr-pm-0.0.10
Fetching: backports-3.6.8.gem (100%)
Successfully installed backports-3.6.8
Fetching: ffi-1.9.18.gem (100%)
Building native extensions. This could take a while...
Successfully installed ffi-1.9.18
Fetching: childprocess-0.6.3.beta.1.gem (100%)
Successfully installed childprocess-0.6.3.beta.1
Fetching: clamp-1.0.1.gem (100%)
Successfully installed clamp-1.0.1
Fetching: dotenv-2.2.0.gem (100%)
Successfully installed dotenv-2.2.0
Fetching: insist-1.0.0.gem (100%)
Successfully installed insist-1.0.0
Fetching: mustache-0.99.8.gem (100%)
Successfully installed mustache-0.99.8
Fetching: stud-0.0.22.gem (100%)
Successfully installed stud-0.0.22
Fetching: pleaserun-0.0.28.gem (100%)
Successfully installed pleaserun-0.0.28
Fetching: io-like-0.3.0.gem (100%)
Successfully installed io-like-0.3.0
Fetching: ruby-xz-0.2.3.gem (100%)
Successfully installed ruby-xz-0.2.3
Fetching: fpm-1.8.1.gem (100%)
Successfully installed fpm-1.8.1
Parsing documentation for archive-tar-minitar-0.5.2
Installing ri documentation for archive-tar-minitar-0.5.2
Parsing documentation for arr-pm-0.0.10
Installing ri documentation for arr-pm-0.0.10
Parsing documentation for backports-3.6.8
Installing ri documentation for backports-3.6.8
Parsing documentation for cabin-0.9.0
Installing ri documentation for cabin-0.9.0
Parsing documentation for childprocess-0.6.3.beta.1
Installing ri documentation for childprocess-0.6.3.beta.1
Parsing documentation for clamp-1.0.1
Installing ri documentation for clamp-1.0.1
Parsing documentation for dotenv-2.2.0
Installing ri documentation for dotenv-2.2.0
Parsing documentation for ffi-1.9.18
Installing ri documentation for ffi-1.9.18
Parsing documentation for fpm-1.8.1
Installing ri documentation for fpm-1.8.1
Parsing documentation for insist-1.0.0
Installing ri documentation for insist-1.0.0
Parsing documentation for io-like-0.3.0
Installing ri documentation for io-like-0.3.0
Parsing documentation for mustache-0.99.8
Installing ri documentation for mustache-0.99.8
Parsing documentation for pleaserun-0.0.28
Installing ri documentation for pleaserun-0.0.28
Parsing documentation for ruby-xz-0.2.3
Installing ri documentation for ruby-xz-0.2.3
Parsing documentation for stud-0.0.22
Installing ri documentation for stud-0.0.22
Done installing documentation for archive-tar-minitar, arr-pm, backports, cabin, childprocess, clamp, dotenv, ffi, fpm, insist, io-like, mustache, pleaserun, ruby-xz, stud after 8 seconds
15 gems installed
You have new mail in /var/spool/mail/root
二進位制安裝乾淨的Mysql環境,二進位制安裝速度很快:
#建立mysql資料儲存目錄
mkdir /data/mysqldata
#新增mysql使用者和mysql組
groupadd -r mysql
useradd -g mysql -r -s /sbin/nologin -M -d /data/mysqldata mysql
chown -R mysql:mysql /data/mysqldata
#初始化Mysql安裝Mysql:
#建立mysql啟動指令碼
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 777 /etc/init.d/mysqld
#修改/etc/init.d/mysqld內容,內容如下:
#basedir=/data/mysql
#datadir=/data/mysqldata
#加入系統庫核系統變數
ln -sv /data/mysql/include /usr/include/mysql
echo '/data/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
echo 'export PATH=/data/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh
source /etc/profile
service mysqld start
如圖,安裝完成stopmysql服務,開始封裝Mysql rpm包:
#開始封裝Mysql Rpm包:
[root@localhost tmp]# fpm -s dir -t rpm -v 5.6.29 -n mysql --before-install /tmp/before.sh --after-install /tmp/after.sh --after-remove /tmp/remove.sh -d 'libaio' /data/mysql/ /data/mysqldata/ /etc/init.d/mysqld
Created package {:path=>"mysql-5.6.29-1.x86_64.rpm"}
如圖:
封裝的時間較久
注意:執行指令碼的引數一定要在封裝目錄之前,否則會報錯的。
Fpm的引數選項:
-n 自定義軟體包的名稱
-C fpm去哪個目錄搜尋檔案
-v 生成的rpm包的版本
-d 生成的rpm包依賴什麼軟體,通常為-d 'name' 或者-d 'name > version'
-a 系統架構名稱,如果是noarch則為'-a all'或者'-a native'
--description 軟體包的描述
--conflicts 與其他什麼軟體包衝突n
-f 第二次打包時目錄下如果有同名安裝包存在,則覆蓋它
-p 輸出的安裝包的目錄,不想放在當前目錄下就需要指定
--post-install 軟體包安裝完成之後所要執行的指令碼;同--after-install
--pre-install 軟體包安裝完成之前所要執行的指令碼;同--before-install
--post-uninstall 軟體包解除安裝完成之後所要執行的指令碼;同--after-remove
--pre-uninstall 軟體包解除安裝完成之前所要執行的指令碼;同--before-remove
#安裝之前的要執行的指令碼:
#安裝之後要執行的指令碼:
#解除安裝Rpm包後要執行的指令碼:
#cpoy到一台全新的機器測試:
到此封裝製作完成,感興趣的朋友可以自己動手嘗試下。
本文永久更新連結地址:http://www.linuxidc.com/Linux/2017-03/142184.htm
相關文章