Linux--轻松定义自己的RPM/DEB软件包

本文涉及的产品
RDS DuckDB + QuickBI 企业套餐,8核32GB + QuickBI 专业版
RDS AI 助手,专业版
RDS Agent(兼容OpenClaw),2核4GB
简介:

     [前言] 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.  
  3. Building native extensions.  This could take a while... 
  4. Successfully installed json-1.6.6 
  5. Successfully installed cabin-0.4.4 
  6. Successfully installed backports-2.3.0 
  7. Successfully installed arr-pm-0.0.7 
  8. Successfully installed clamp-0.3.1 
  9. Successfully installed fpm-0.4.6 
  10. 6 gems installed 
  11. Installing ri documentation for json-1.6.6... 
  12. Installing ri documentation for cabin-0.4.4... 
  13. Installing ri documentation for backports-2.3.0... 
  14. Installing ri documentation for arr-pm-0.0.7... 
  15. Installing ri documentation for clamp-0.3.1... 
  16. Installing ri documentation for fpm-0.4.6... 
  17. Installing RDoc documentation for json-1.6.6... 
  18. Installing RDoc documentation for cabin-0.4.4... 
  19. Installing RDoc documentation for backports-2.3.0... 
  20. Installing RDoc documentation for arr-pm-0.0.7... 
  21. Installing RDoc documentation for clamp-0.3.1... 
  22. 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.  
  3. [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   
  4.  
  5. [root@client1 mysql-5.1.41]#  make 
  6.  
  7. [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.  
  3. ncurses.x86_64                       5.7-3.20090208.el6        @base/$releasever 
  4.  
  5. ncurses-base.x86_64                  5.7-3.20090208.el6        @base/$releasever 
  6.  
  7. ncurses-libs.x86_64                  5.7-3.20090208.el6        @base/$releasever 
  8.  
  9. ncurses-devel.i686                   5.7-3.20090208.el6        base              
  10.  
  11. ncurses-devel.x86_64                 5.7-3.20090208.el6        base              
  12.  
  13. ncurses-libs.i686                    5.7-3.20090208.el6        base              
  14.  
  15. ncurses-static.x86_64                5.7-3.20090208.el6        base              
  16.  
  17. ncurses-term.x86_64                  5.7-3.20090208.el6        base              
  18.  
  19. php-pecl-ncurses.x86_64              1.0.1-1.el6               epel  
  20.  
  21.  
  22. [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.  
  3. [root@client1 tmp]# fpm -s dir  -t rpm -v 1.0 -n mysql_waydee  /opt/mysql/ 
  4.  
  5. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/deb.rb:19: warning: already initialized constant SCRIPT_MAP 
  6.  
  7. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:23: warning: already initialized constant DIGEST_ALGORITHM_MAP 
  8.  
  9. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:29: warning: already initialized constant COMPRESSION_MAP 
  10.  
  11. Executing(%prep): /bin/sh -e /var/tmp/rpm-tmp.XPQ8av 
  12.  
  13. Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.j4a8lh 
  14.  
  15. Executing(%install): /bin/sh -e /var/tmp/rpm-tmp.sH6nx3 
  16.  
  17. Processing files: mysql_waydee-1.0-1.x86_64 
  18.  
  19. Wrote: /tmp/package-rpm-build20120413-13147-1by0r75/RPMS/x86_64/mysql_waydee-1.0-1.x86_64.rpm 
  20.  
  21. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.9qzvuf 
  22.  
  23. 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.  
  3. -rw-r--r-- 1 root root 24893316  4月 13 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.  
  3. /opt/mysql/bin/innochecksum 
  4.  
  5. /opt/mysql/bin/msql2mysql 
  6.  
  7. /opt/mysql/bin/my_print_defaults 
  8.  
  9. /opt/mysql/bin/myisam_ftdump 
  10.  
  11. /opt/mysql/bin/myisamchk 
  12.  
  13. /opt/mysql/bin/myisamlog 
  14.  
  15. /opt/mysql/bin/myisampack 
  16.  
  17. /opt/mysql/bin/mysql 
  18.  
  19. /opt/mysql/bin/mysql_client_test 
  20.  
  21. /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.  
  3. The authenticity of host '192.168.2.102 (192.168.2.102)' can't be established. 
  4.  
  5. RSA key fingerprint is 7d:96:53:c2:ba:f3:e6:7b:b2:d2:f9:b1:3e:48:9a:88. 
  6.  
  7. Are you sure you want to continue connecting (yes/no)? yes 
  8.  
  9. Warning: Permanently added '192.168.2.102' (RSA) to the list of known hosts. 
  10.  
  11. root@192.168.2.102's password:  
  12.  
  13. mysql_waydee-1.0-1.x86_64.rpm                                                                                                                  100%   24MB  23.7MB/s   00:01  
  14.  
  15.  
  16.  
  17. [root@client2 ~]# rpm -ivh mysql_waydee-1.0-1.x86_64.rpm  
  18.  
  19. Preparing...                ########################################### [100%] 
  20.  
  21.    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.  
  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.  
  5. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:23: warning: already initialized constant DIGEST_ALGORITHM_MAP 
  6.  
  7. /usr/lib/ruby/gems/1.8/gems/fpm-0.4.6/lib/fpm/package/rpm.rb:29: warning: already initialized constant COMPRESSION_MAP 
  8.  
  9. 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.  
  3. -rw-r--r-- 1 root root 25185038  4月 13 15:17 mysql-waydee_1.0_amd64.deb 

 

FPM参数详解

 
 
  1. Usage: fpm [options] 
  2.  
  3. -p, --package PACKAGEFILE        管理的软件包 
  4.  
  5. -n, --name PACKAGENAME           定义生成的软件包的名字 
  6.  
  7. -v, --version VERSION            定义生成的软件包的版本 
  8.  
  9.     --iteration ITERATION        (可选) 为软件包设置 iteration值 ('release' for RPM). 
  10.  
  11.     --epoch EPOCH                (可选) 为软件包设置 epoch值 
  12.  
  13. -d, —depends DEPENDENCY     设置软件包的依赖关系 
  14.  
  15.     --category SECTION_OR_GROUP 
  16.  
  17.     --provides PROVIDES 
  18.  
  19.     --conflicts CONFLICTS 
  20.  
  21.     --replaces REPLACES 
  22.  
  23.     --config-files PATH          (optional) Treat path as a configuration file. Uses conffiles in deb or %config 
  24.  
  25.                                  in rpm. (/etc/package.conf) 
  26.  
  27. -a, --architecture ARCHITECTURE 
  28.  
  29. -m, --maintainer MAINTAINER 
  30.  
  31. -C DIRECTORY                    在搜索files前先进入该目录 
  32.  
  33. -t PACKAGE_TYPE                 设置目标包的类型 
  34.  
  35. -s SOURCE_TYPE                   设置需要转换的包类型 
  36.  
  37. -S PACKAGE_SUFFIX                which suffix to append to package and dependencies 
  38.  
  39.     --prefix PREFIX              A path to prefix files with when building the target package. This may not be 
  40.  
  41.                                  necessary for all source types. For example, the 'gem' type will prefix with 
  42.  
  43.                                  your gem directory (gem env | grep -A1 PATHS:) 
  44.  
  45. -e, --edit                       Edit the specfile before building 
  46.  
  47. -x, --exclude PATTERN            Exclude paths matching pattern (according to tar --exclude) 
  48.  
  49.     --post-install SCRIPTPATH    Add a post-install action. This script will be included in the resulting package 
  50.  
  51.     --pre-install SCRIPTPATH     Add a pre-install action. This script will be included in the resulting package 
  52.  
  53.     --pre-uninstall SCRIPTPATH   Add a pre-uninstall action. This script will be included in the resulting package 
  54.  
  55.     --post-uninstall SCRIPTPATH  Add a post-uninstall action. This script will be included in the resulting package 
  56.  
  57.     --description DESCRIPTION    Add a description for this package. 
  58.  
  59.     --url URL                    Add a url for this package. 
  60.  
  61.     --inputs FILEPATH            The path to a file containing a newline-separated list of files and dirs to package. 
  62.  
  63.                                  Pass - as the only argument to have the list of files and dirs read from STDIN (e.g. 
  64.  
  65.                                  fpm -s dir -t deb - < FILELIST) 
  66.  
  67.     --gem-bin-path DIRECTORY     (gem source only) The directory to install gem executables 
  68.  
  69.     --gem-package-prefix PREFIX  (gem source only) Prefix for gem packages 
  70.  
  71.     --gem-gem PATH_TO_GEM        (gem source only) The path to the 'gem' tool (defaults to 'gem' and searches 
  72.  
  73.                                  your $PATH) 
  74.  
  75.     --python-bin PYTHON_BINARY_LOCATION 
  76.  
  77.                                  (python source only) The path to the python you want to run. Default is 'python' 
  78.  
  79.     --python-easyinstall EASY_INSTALL_PATH 
  80.  
  81.                                  (python source only) The path to your easy_install tool. Default is 'easy_install' 
  82.  
  83.     --python-pypi PYPI_SERVER    (python source only) PyPi Server uri for retrieving packages. Default 
  84.  
  85.                                  is 'http://pypi.python.org/simple' 
  86.  
  87.     --python-package-prefix PREFIX 
  88.  
  89.                                  (python source only) Prefix for python packages 
  90.  
  91.     --deb-ignore-iteration-in-dependencies 
  92.  
  93.                                  (deb target only) For = dependencies, allow iterations on the specified 
  94.  
  95.                                  version.  Default is to be specific. 
  96.  
  97.     --deb-pre-depends DEPENDENCY (deb target only) Add DEPENDENCY as Pre-Depends. 
  98.  
  99.     --deb-custom-control FILEPATH 
  100.  
  101.                                  (deb target only) Custom version of the Debian control file. 









本文转自 waydee 51CTO博客,原文链接:http://blog.51cto.com/waydee/834002,如需转载请自行联系原作者
相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
8月前
|
存储 Linux 开发工具
Linux环境下使用Buildroot配置软件包
使用Buildroot可以大大简化嵌入式Linux系统的开发和维护工作,但它需要对Linux系统和交叉编译有深入的理解。通过上述步骤,可以有效地配置和定制软件包,为特定的嵌入式应用构建高效、稳定的系统。
962 11
|
算法 安全 Ubuntu
Linux下的软件包管理器有哪些
Linux下的软件包管理器有哪些
869 5
|
人工智能 安全 Linux
Alpine Linux设定指定的软件包安装源
以上就是如何为Alpine Linux设置特定的软件包的安装源的全部流程。这个过程非常简洁、明了,希望你在使用过程中能够找到乐趣。这个过程不仅可以提供你需要的软件,还可以根据你的网络条件和地域性需求进行调整,使你的Alpine Linux系统达到最佳性能。
1334 24
|
缓存 Ubuntu Linux
Linux中yum、rpm、apt-get、wget的区别,yum、rpm、apt-get常用命令,CentOS、Ubuntu中安装wget
通过本文,我们详细了解了 `yum`、`rpm`、`apt-get`和 `wget`的区别、常用命令以及在CentOS和Ubuntu中安装 `wget`的方法。`yum`和 `apt-get`是高层次的包管理器,分别用于RPM系和Debian系发行版,能够自动解决依赖问题;而 `rpm`是低层次的包管理工具,适合处理单个包;`wget`则是一个功能强大的下载工具,适用于各种下载任务。在实际使用中,根据系统类型和任务需求选择合适的工具,可以大大提高工作效率和系统管理的便利性。
1787 25
|
存储 Ubuntu 前端开发
Linux软件包管理工具概览
在Linux系统中,dpkg、apt、rpm、yum和dnf是几种常见的包管理工具,它们分别属于不同的Linux发行版或家族,并有着各自的诞生顺序和特点。下面将按照这些工具的诞生顺序,并结合Debian、Red Hat、CentOS、Ubuntu和Kali等系统,进行详细的介绍。
490 4
|
Kubernetes Linux 测试技术
|
存储 缓存 Linux
【Linux】另一种基于rpm安装yum的方式
通过本文的方法,您可以在离线环境中使用RPM包安装YUM并进行必要的配置。这种方法适用于无法直接访问互联网的服务器或需要严格控制软件源的环境。通过配置本地YUM仓库,确保了软件包的安装和更新可以顺利进行。希望本文能够为您在特定环境中部署YUM提供实用的指导。
2379 0
|
Ubuntu Linux 数据库
在Linux中,如何进行软件包升级?
在Linux中,如何进行软件包升级?
|
Linux 开发工具 存储
Linux软件包管理
Linux软件包管理
331 0
|
安全 数据挖掘 Linux
Linux命令rpm深度解析
`rpm`是Linux下的软件包管理器,用于安装、升级、卸载和查询`.rpm`包,常见于Red Hat系Linux。它管理依赖、维护软件信息数据库,支持版本控制和安全验证。常用命令如`-i`安装,`-U`升级,`-e`卸载,`-q`查询。安装时用`-v`和`-h`可查看详细信息和进度。注意依赖关系、权限和签名验证,最佳实践包括使用仓库、定期更新和备份数据。