[前言] Linux管理员大多数时候都是通过源码包编译安装软件,在安装过程中不断的遇到问题,不断解决;为了从重复的编译安装操作中解脱,很多人都会选择制作自己的RPM/DEB包,然后可以很方便的安装,但是要制作RPM或者DEB包就不得不学习如何编写SPECS或debian控制文件,如何build。最近发现了FPM这个工具,它可以让你省去阅读漫长的文档时间,直接可以制作自己的软件包。
给感兴趣的人:
目录:
1. FPM介绍
2. FPM安装
3. 编译安装Mysql
4. FPM制作RPM/DEB包
5. FPM参数详解
FPM介绍
FPM的作者是jordansissel
关于FPM的介绍
<a href="https://docs.google.com/present/view?id=0Aa9liCTsAyzRZGNtd3dkOTRfMTdmczY2azlkcg&hl=en" target="_blank">https://docs.google.com/present/view?id=0Aa9liCTsAyzRZGNtd3dkOTRfMTdmczY2azlkcg&hl=en </a>
FPM功能简单说就是将一种类型的包转换成另一种类型。
支持的源类型包:“dir”:将目录打包成所需要的类型,可以用于源码编译安装的软件包
“rpm”:对rpm进行转换
“gem”:对rubygem包进行转换
“python”:将python模块打包成相应的类型
支持的目标类型包:
“rpm”:转换为rpm包
“deb”:转换为deb包
“solaris”:转换为solaris包
“puppet”:转换为puppet模块
这里主要介绍如何将源码安装的包转换为RPM/DEB包,其他功能感兴趣的可以试试。
FPM安装
FPM的安装非常简单,安装FPM前需要先安装ruby,rubygem
[root@client1 ~]# gem install fpm
Building native extensions. This could take a while...
Successfully installed json-1.6.6
Successfully installed cabin-0.4.4
Successfully installed backports-2.3.0
Successfully installed arr-pm-0.0.7
Successfully installed clamp-0.3.1
Successfully installed fpm-0.4.6
6 gems installed
Installing ri documentation for json-1.6.6...
Installing ri documentation for cabin-0.4.4...
Installing ri documentation for backports-2.3.0...
Installing ri documentation for arr-pm-0.0.7...
Installing ri documentation for clamp-0.3.1...
Installing ri documentation for fpm-0.4.6...
Installing RDoc documentation for json-1.6.6...
Installing RDoc documentation for cabin-0.4.4...
Installing RDoc documentation for backports-2.3.0...
Installing RDoc documentation for arr-pm-0.0.7...
Installing RDoc documentation for clamp-0.3.1...
Installing RDoc documentation for fpm-0.4.6...
编译安装Mysql
下载mysql源码包,下载地址:http://dev.mysql.com/downloads/
解压源码包:
[root@client1 tmp]# unzip mysql-5.1.41.zip
编译安装:
[root@client1 tmp]# cd mysql-5.1.41
[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
[root@client1 mysql-5.1.41]# make
[root@client1 mysql-5.1.41]# make all install
安装中遇到的错误:
错误一:
checking for termcap functions library... configure: error: No curses/termcap library found
是因为没有安装ncurses包导致的
[root@client1 mysql-5.1.41]# yum list|grep ncurses*
ncurses.x86_64 5.7-3.20090208.el6 @base/$releasever
ncurses-base.x86_64 5.7-3.20090208.el6 @base/$releasever
ncurses-libs.x86_64 5.7-3.20090208.el6 @base/$releasever
ncurses-devel.i686 5.7-3.20090208.el6 base
ncurses-devel.x86_64 5.7-3.20090208.el6 base
ncurses-libs.i686 5.7-3.20090208.el6 base
ncurses-static.x86_64 5.7-3.20090208.el6 base
ncurses-term.x86_64 5.7-3.20090208.el6 base
php-pecl-ncurses.x86_64 1.0.1-1.el6 epel
[root@client1 mysql-5.1.41]# yum install ncurses ncurses-libs ncurses-devel
报错二:
../depcomp: line 571: exec: g++: not found
错误原因没有安装gcc-c++包
[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包,命令如下,具体参数解释在文章的最后:
[root@client1 mysql-5.1.41]# cd ..
[root@client1 tmp]# fpm -s dir -t rpm -v 1.0 -n mysql_waydee /opt/mysql/
/usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/deb.rb:19: warning: already initialized constant SCRIPT_MAP
/usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:23: warning: already initialized constant DIGEST_ALGORITHM_MAP
/usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:29: warning: already initialized constant COMPRESSION_MAP
Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.XPQ8av
Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.j4a8lh
Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.sH6nx3
Processing files: mysql_waydee-1.0-1.x86_64
Wrote: /tmp/package-rpm-build20120413-13147-1by0r75/RPMS/x86_64/mysql_waydee-1.0-1.x86_64.rpm
Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.9qzvuf
Created rpm {"path":"mysql_waydee-1.0-1.x86_64.rpm"}
查看制作的rpm包,并传到另一台服务器执行安装
[root@client1 tmp]# ls -l mysql_waydee-1.0-1.x86_64.rpm
-rw-r--r-- 1 root root 24893316 4月 13 15:15 mysql_waydee-1.0-1.x86_64.rpm
使用rpm命令查看生成的rpm包文件
[root@client1 tmp]# rpm -qpl mysql_waydee-1.0-1.x86_64.rpm |head -n10
/opt/mysql/bin/innochecksum
/opt/mysql/bin/msql2mysql
/opt/mysql/bin/my_print_defaults
/opt/mysql/bin/myisam_ftdump
/opt/mysql/bin/myisamchk
/opt/mysql/bin/myisamlog
/opt/mysql/bin/myisampack
/opt/mysql/bin/mysql
/opt/mysql/bin/mysql_client_test
/opt/mysql/bin/mysql_config
将生成的rpm包传输到另外一台测试服务器,并安装
[root@client1 tmp]# scp mysql_waydee-1.0-1.x86_64.rpm 192.168.2.102:/root
The authenticity of host '192.168.2.102 (192.168.2.102)' can't be established.
RSA key fingerprint is 7d:96:53:c2:ba:f3:e6:7b:b2:d2:f9:b1:3e:48:9a:88.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.2.102' (RSA) to the list of known hosts.
[email protected]'s password:
mysql_waydee-1.0-1.x86_64.rpm 100% 24MB 23.7MB/s 00:01
[root@client2 ~]# rpm -ivh mysql_waydee-1.0-1.x86_64.rpm
Preparing... ########################################### [100%]
1:mysql_waydee ########################################### [100%]
可以顺利安装,当然在制作RPM包的时候可以增加想要的dependences,这个看个人要求。
下面是将安装好的mysql包制作为DEB包,省去不少时间
[root@client1 tmp]# fpm -s dir -t deb -v 1.0 -n mysql_waydee /opt/mysql/
Created deb package {"path":"/tmp/mysql-waydee_1.0_amd64.deb"}
查看打包好的deb包
[root@client1 tmp]# ls -l mysql-waydee_1.0_amd64.deb
-rw-r--r-- 1 root root 25185038 4月 13 15:17 mysql-waydee_1.0_amd64.deb
FPM参数详解
Usage: fpm [options]
-p, --package PACKAGEFILE 管理的软件包
-n, --name PACKAGENAME 定义生成的软件包的名字
-v, --version VERSION 定义生成的软件包的版本
--iteration ITERATION (可选) 为软件包设置 iteration值 ('release' for RPM).
--epoch EPOCH (可选) 为软件包设置 epoch值
-d, —depends DEPENDENCY 设置软件包的依赖关系
--category SECTION_OR_GROUP
--provides PROVIDES
--conflicts CONFLICTS
--replaces REPLACES
--config-files PATH (optional) Treat path as a configuration file. Uses conffiles in deb or %config
in rpm. (/etc/package.conf)
-a, --architecture ARCHITECTURE
-m, --maintainer MAINTAINER
-C DIRECTORY 在搜索files前先进入该目录
-t PACKAGE_TYPE 设置目标包的类型
-s SOURCE_TYPE 设置需要转换的包类型
-S PACKAGE_SUFFIX which suffix to append to package and dependencies
--prefix PREFIX A path to prefix files with when building the target package. This may not be
necessary for all source types. For example, the 'gem' type will prefix with
your gem directory (gem env | grep -A1 PATHS:)
-e, --edit Edit the specfile before building
-x, --exclude PATTERN Exclude paths matching pattern (according to tar --exclude)
--post-install SCRIPTPATH Add a post-install action. This script will be included in the resulting package
--pre-install SCRIPTPATH Add a pre-install action. This script will be included in the resulting package
--pre-uninstall SCRIPTPATH Add a pre-uninstall action. This script will be included in the resulting package
--post-uninstall SCRIPTPATH Add a post-uninstall action. This script will be included in the resulting package
--description DESCRIPTION Add a description for this package.
--url URL Add a url for this package.
--inputs FILEPATH The path to a file containing a newline-separated list of files and dirs to package.
Pass - as the only argument to have the list of files and dirs read from STDIN (e.g.
fpm -s dir -t deb - < FILELIST)
--gem-bin-path DIRECTORY (gem source only) The directory to install gem executables
--gem-package-prefix PREFIX (gem source only) Prefix for gem packages
--gem-gem PATH_TO_GEM (gem source only) The path to the 'gem' tool (defaults to 'gem' and searches
your $PATH)
--python-bin PYTHON_BINARY_LOCATION
(python source only) The path to the python you want to run. Default is 'python'
--python-easyinstall EASY_INSTALL_PATH
(python source only) The path to your easy_install tool. Default is 'easy_install'
--python-pypi PYPI_SERVER (python source only) PyPi Server uri for retrieving packages. Default
is 'http://pypi.python.org/simple'
--python-package-prefix PREFIX
(python source only) Prefix for python packages
--deb-ignore-iteration-in-dependencies
(deb target only) For = dependencies, allow iterations on the specified
version. Default is to be specific.
--deb-pre-depends DEPENDENCY (deb target only) Add DEPENDENCY as Pre-Depends.
--deb-custom-control FILEPATH
(deb target only) Custom version of the Debian control file.
本文转自 waydee 51CTO博客,原文链接:http://blog.51cto.com/waydee/834002,如需转载请自行联系原作者