歡迎您光臨本站 註冊首頁

Linux--輕鬆定義自己的RPM/DEB軟體包

←手機掃碼閱讀     火星人 @ 2014-03-08 , reply:0

[前言] Linux管理員大多數時候都是通過源碼包編譯安裝軟體,在安裝過程中不斷的遇到問題,不斷解決;為了從重複的編譯安裝操作中解脫,很多人都會選擇製作自己的RPM/DEB包,然後可以很方便的安裝,但是要製作RPM或者DEB包就不得不學習如何編寫SPECS或debian控制文件,如何build.最近發現了FPM這個工具,它可以讓你省去閱讀漫長的文檔時間,直接可以製作自己的軟體包.

給感興趣的人:

RPM包製作: http://www.rpm.org/max-rpm/

DEB包製作: http://www.debian.org/doc/manuals/maint-guide/

目錄:

1. FPM介紹

2. FPM安裝

3. 編譯安裝Mysql

4. FPM製作RPM/DEB包

5. FPM參數詳解

FPM介紹

FPM的作者是jordansissel

關於FPM的介紹

https://docs.google.com/present/view?id=0Aa9liCTsAyzRZGNtd3dkOTRfMTdmczY2azlkcg&hl=en

FPM功能簡單說就是將一種類型的包轉換成另一種類型.

支持的源類型包:“dir”:將目錄打包成所需要的類型,可以用於源碼編譯安裝的軟體包

“rpm”:對rpm進行轉換

“gem”:對rubygem包進行轉換

“python”:將python模塊打包成相應的類型

支持的目標類型包:

“rpm”:轉換為rpm包

“deb”:轉換為deb包

“solaris”:轉換為solaris包

“puppet”:轉換為puppet模塊

這裡主要介紹如何將源碼安裝的包轉換為RPM/DEB包,其他功能感興趣的可以試試.

FPM安裝

FPM的安裝非常簡單,安裝FPM前需要先安裝ruby,rubygem

  1. [root@client1 ~]# gem install fpm
  2. Building native extensions. This could take a while...
  3. Successfully installed json-1.6.6
  4. Successfully installed cabin-0.4.4
  5. Successfully installed backports-2.3.0
  6. Successfully installed arr-pm-0.0.7
  7. Successfully installed clamp-0.3.1
  8. Successfully installed fpm-0.4.6
  9. 6 gems installed
  10. Installing ri documentation for json-1.6.6...
  11. Installing ri documentation for cabin-0.4.4...
  12. Installing ri documentation for backports-2.3.0...
  13. Installing ri documentation for arr-pm-0.0.7...
  14. Installing ri documentation for clamp-0.3.1...
  15. Installing ri documentation for fpm-0.4.6...
  16. Installing RDoc documentation for json-1.6.6...
  17. Installing RDoc documentation for cabin-0.4.4...
  18. Installing RDoc documentation for backports-2.3.0...
  19. Installing RDoc documentation for arr-pm-0.0.7...
  20. Installing RDoc documentation for clamp-0.3.1...
  21. Installing RDoc documentation for fpm-0.4.6...

編譯安裝Mysql

下載mysql源碼包,下載地址:http://dev.mysql.com/downloads/

解壓源碼包:

  1. [root@client1 tmp]# unzip mysql-5.1.41.zip

編譯安裝:

  1. [root@client1 tmp]# cd mysql-5.1.41
  2. [root@client1 mysql-5.1.41]# ./configure --prefix=/opt/mysql --localstatedir=/opt/var/mysql/var --with-unix-socket-path=/opt/mysql/mysql.sock --with-mysqld-user=mysql --with-plugins=archive,partition,myisam,innobase,heap,csv --with-extra-charsets=gbk,gb2312,utf8,ascii --with-charset=utf8 --with-collation=utf8_general_ci --with-big-tables --enable-assembler --enable-profiling --enable-local-infile --enable-thread-safe-client --with-fast-mutexes --with-pthread --with-zlib-dir=bundled --with-readline --without-geometry --without-embedded-server --without-debug --without-ndb-debug --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static
  3. [root@client1 mysql-5.1.41]# make
  4. [root@client1 mysql-5.1.41]# make all install

安裝中遇到的錯誤:

錯誤一:

checking for termcap functions library... configure: error: No curses/termcap library found

是因為沒有安裝ncurses包導致的

  1. [root@client1 mysql-5.1.41]# yum list|grep ncurses*
  2. ncurses.x86_64 5.7-3.20090208.el6 @base/$releasever
  3. ncurses-base.x86_64 5.7-3.20090208.el6 @base/$releasever
  4. ncurses-libs.x86_64 5.7-3.20090208.el6 @base/$releasever
  5. ncurses-devel.i686 5.7-3.20090208.el6 base
  6. ncurses-devel.x86_64 5.7-3.20090208 .el6 base
  7. ncurses-libs.i686 5.7-3.20090208.el6 base
  8. ncurses-static.x86_64 5.7-3.20090208.el6 base
  9. ncurses-term.x86_64 5.7-3.20090208.el6 base
  10. php-pecl-ncurses.x86_64 1.0.1-1.el6 epel
  11. [root@client1 mysql-5.1.41]# yum install ncurses ncurses-libs ncurses-devel

報錯二:

../depcomp: line 571: exec: g : not found

錯誤原因沒有安裝gcc-c 包

  1. [root@client1 mysql-5.1.41]# yum install gcc-c

報錯三

./include/my_global.h:1099: 錯誤:對 C 內建類型 ‘bool’ 的重聲明

這個錯誤是因為先./congfigure 又裝的gcc-c 之後又make 導致的,解決方法是重新./configure,make,make install就可以恢復

FPM製作RPM/DEB包

開始打包安裝好的mysql,並轉換為rpm包,命令如下,具體參數解釋在文章的

  1. [root@client1 mysql-5.1.41]# cd ..
  2. [root@client1 tmp]# fpm -s dir -t rpm -v 1.0 -n mysql_waydee /opt/mysql/
  3. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/deb.rb:19: warning: already initialized constant SCRIPT_MAP
  4. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:23: warning: already initialized constant DIGEST_ALGORITHM_MAP
  5. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:29: warning: already initialized constant COMPRESSION_MAP
  6. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.XPQ8av
  7. Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.j4a8lh
  8. Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.sH6nx3
  9. Processing files: mysql_waydee-1.0-1.x86_64
  10. Wrote: /tmp/package-rpm-build20120413-13147-1by0r75/RPMS/x86_64/mysql_waydee-1.0-1.x86_64.rpm
  11. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.9qzvuf
  12. Created rpm {"path":"mysql_waydee-1.0-1.x86_64.rpm"}

查看製作的rpm包,並傳到另一台伺服器執行安裝

  1. [root@client1 tmp]# ls -l mysql_waydee-1.0-1.x86_64.rpm
  2. -rw-r--r-- 1 root root 24893316 413 15:15 mysql_waydee-1.0-1.x86_64.rpm

使用rpm命令查看生成的rpm包文件

  1. [root@client1 tmp]# rpm -qpl mysql_waydee-1.0-1.x86_64.rpm |head -n10
  2. /opt/mysql/bin/innochecksum
  3. /opt/mysql/bin/msql2mysql
  4. /opt/mysql/bin/my_print_defaults
  5. /opt/mysql/bin/myisam_ftdump
  6. /opt/mysql/bin/myisamchk
  7. /opt/mysql/bin/myisamlog
  8. /opt/mysql/bin/myisampack
  9. /opt/mysql/bin/mysql
  10. /opt/mysql/bin/mysql_client_test
  11. /opt/mysql/bin/mysql_config

將生成的rpm包傳輸到另外一台測試伺服器,並安裝

  1. [root@client1 tmp]# scp mysql_waydee-1.0-1.x86_64.rpm 192.168.2.102:/root
  2. The authenticity of host '192.168.2.102 (192.168.2.102)' can't be established.
  3. RSA key fingerprint is 7d:96:53:c2:ba:f3:e6:7b:b2:d2:f9:b1:3e:48:9a:88.
  4. Are you sure you want to continue connecting (yes/no)? yes
  5. Warning: Permanently added '192.168.2.102' (RSA) to the list of known hosts.
  6. root@192.168.2.102's password:
  7. mysql_waydee-1.0-1.x86_64.rpm 100% 24MB 23.7MB/s 00:01
  8. [root@client2 ~]# rpm -ivh mysql_waydee-1.0-1.x86_64.rpm
  9. Preparing... ########################################### [100%]
  10. 1:mysql_waydee ########################################### [100%]

可以順利安裝,當然在製作RPM包的時候可以增加想要的dependences,這個看個人要求.

下面是將安裝好的mysql包製作為DEB包,省去不少時間

  1. [root@client1 tmp]# fpm -s dir -t deb -v 1.0 -n mysql_waydee /opt/mysql/
  2. /usr/lib/ruby/gems/ 1.8/gems/fpm-0.4.6/lib/fpm/package/deb.rb:19: warning: already initialized constant SCRIPT_MAP
  3. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:23: warning: already initialized constant DIGEST_ALGORITHM_MAP
  4. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:29: warning: already initialized constant COMPRESSION_MAP
  5. Created deb package {"path":"/tmp/mysql-waydee_1.0_amd64.deb"}

查看打包好的deb包

  1. [root@client1 tmp]# ls -l mysql-waydee_1.0_amd64.deb
  2. -rw-r--r-- 1 root root 25185038 413 15:17 mysql-waydee_1.0_amd64.deb

FPM參數詳解

  1. Usage: fpm [options]
  2. -p, --package PACKAGEFILE 管理的軟體包
  3. -n, --name PACKAGENAME 定義生成的軟體包的名字
  4. -v, --version VERSION 定義生成的軟體包的版本
  5. --iteration ITERATION (可選) 為軟體包設置 iteration值 ('release' for RPM).
  6. --epoch EPOCH (可選) 為軟體包設置 epoch值
  7. -d, —depends DEPENDENCY 設置軟體包的依賴關係
  8. --category SECTION_OR_GROUP
  9. --provides PROVIDES
  10. --conflicts CONFLICTS
  11. --replaces REPLACES
  12. --config-files PATH (optional) Treat path as a configuration file. Uses conffiles in deb or %config
  13. in rpm. (/etc/package.conf)
  14. -a, --architecture ARCHITECTURE
  15. -m, --maintainer MAINTAINER
  16. -C DIRECTORY 在搜索files前先進入該目錄
  17. -t PACKAGE_TYPE 設置目標包的類型
  18. -s SOURCE_TYPE 設置需要轉換的包類型
  19. -S PACKAGE_SUFFIX which suffix to append to package and dependencies
  20. --prefix PREFIX A path to prefix files with when building the target package. This may not be
  21. necessary for all source types. For example, the 'gem' type will prefix with
  22. your gem directory (gem env | grep -A1 PATHS:)
  23. -e, --edit Edit the specfile before building
  24. -x, --exclude PATTERN Exclude paths matching pattern (according to tar --exclude)
  25. --post-install SCRIPTPATH Add a post-install action. This script will be included in the resulting package
  26. --pre-install SCRIPTPATH Add a pre-install action. This script will be included in the resulting package
  27. --pre-uninstall SCRIPTPATH Add a pre-uninstall action. This script will be included in the resulting package
  28. --post-uninstall SCRIPTPATH Add a post-uninstall action. This script will be included in the resulting package
  29. --description DESCRIPTION Add a description for this package.
  30. --url URL Add a url for this package.
  31. --inputs FILEPATH The path to a file containing a newline-separated list of files and dirs to package.
  32. Pass - as the only argument to have the list of files and dirs read from STDIN (e.g.
  33. fpm -s dir -t deb - < FILELIST)
  34. --gem-bin-path DIRECTORY (gem source only) The directory to install gem executables
  35. --gem-package-prefix PREFIX (gem source only) Prefix for gem packages
  36. --gem-gem PATH_TO_GEM (gem source only) The path to the 'gem' tool (defaults to 'gem' and searches
  37. your $PATH)
  38. --python-bin PYTHON_BINARY_LOCATION
  39. (python source only) The path to the python you want to run. Default is 'python'
  40. --python-easyinstall EASY_INSTALL_PATH
  41. (python source only) The path to your easy_install tool. Default is 'easy_install'
  42. --python-pypi PYPI_SERVER (python source only) PyPi Server uri for retrieving packages. Default
  43. is 'http://pypi.python.org/simple'
  44. --python-package-prefix PREFIX
  45. (python source only) Prefix for python packages
  46. --deb-ignore-iteration-in-dependencies
  47. (deb target only) For = dependencies, allow iterations on the specified
  48. version. Default is to be specific.
  49. --deb-pre-depends DEPENDENCY (deb target only) Add DEPENDENCY as Pre-Depends.
  50. --deb-custom-control FILEPATH
  51. (deb target only) Custom version of the Debian control file.

本文出自 「Waydee的博客」 博客,請務必保留此出處http://waydee.blog.51cto.com/4677242/834002


[火星人 ] Linux--輕鬆定義自己的RPM/DEB軟體包已經有681次圍觀

http://coctec.com/docs/linux/show-post-46138.html