您现在的位置是:首页 > 文章详情

Linux FPM制作RMP包

日期:2018-05-01点击:390

一.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 <

        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 # (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/

原文链接:https://yq.aliyun.com/articles/661020
关注公众号

低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。

持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。

转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。

文章评论

共有0条评论来说两句吧...

文章二维码

扫描即可查看该文章

点击排行

推荐阅读

最新文章