fpm 制作rpm,fpm 打包 rpm

需要工具:

Ruby 版本>=2.3,Gem,Fpm

一般liunx centos 系统都会小于2.3版本,需要升级或重新装ruby。

ruby 安装

ruby 下载地址:https://www.ruby-lang.org/en/

tar -zxvf ruby-2.4.10.tar.gz
cd ruby-2.4.10

执行 ./configure

[xxxxx@xxxxx ruby-2.4.10]$ ./configure 
checking for ruby... /usr/bin/ruby
config.guess already exists
config.sub already exists
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
......
.....
Configuration summary for ruby version 2.4.10

   * Installation prefix: /usr/local
   * exec prefix:         ${prefix}
   * arch:                x86_64-linux
   * site arch:           ${arch}
   * RUBY_BASE_NAME:      ruby
   * ruby lib prefix:     ${libdir}/${RUBY_BASE_NAME}
   * site libraries path: ${rubylibprefix}/${sitearch}
   * vendor path:         ${rubylibprefix}/vendor_ruby
   * target OS:           linux
   * compiler:            gcc
   * with pthread:        yes
   * enable shared libs:  no
   * dynamic library ext: so
   * CFLAGS:              ${optflags} ${debugflags} ${warnflags}
   * LDFLAGS:             -L. -fstack-protector -rdynamic \
                          -Wl,-export-dynamic
   * optflags:            -O3 -fno-fast-math
   * debugflags:          -ggdb3
   * warnflags:           -Wall -Wextra -Wno-unused-parameter \
                          -Wno-parentheses -Wno-long-long \
                          -Wno-missing-field-initializers \
                          -Wno-tautological-compare \
                          -Wno-parentheses-equality \
                          -Wno-constant-logical-operand -Wno-self-assign \
                          -Wunused-variable -Wimplicit-int -Wpointer-arith \
                          -Wwrite-strings -Wdeclaration-after-statement \
                          -Wimplicit-function-declaration \
                          -Wdeprecated-declarations \
                          -Wno-packed-bitfield-compat \
                          -Wsuggest-attribute=noreturn \
                          -Wsuggest-attribute=format
   * strip command:       strip -S -x
   * install doc:         yes
   * man page type:       doc

执行 make

[xxxx@xxxx ruby-2.4.10]$ make
    CC = gcc
    LD = ld
    LDSHARED = gcc -shared
    CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -std=gnu99 
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT -fPIE
    CPPFLAGS =   -I. -I.ext/include/x86_64-linux -I./include -I. -I./enc/unicode/9.0.0
    DLDFLAGS = -Wl,--compress-debug-sections=zlib -fstack-protector -pie  
    SOLIBS = 
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
making dummy probes.h
file2lastrev.rb: does not seem to be under a vcs: ......
....

执行make install

installing extension headers: /usr/local/include/ruby-2.4.0/x86_64-linux
installing extension scripts: /usr/local/lib/ruby/2.4.0
installing extension scripts: /usr/local/lib/ruby/site_ruby/2.4.0
installing extension scripts: /usr/local/lib/ruby/vendor_ruby/2.4.0
installing extension headers: /usr/local/include/ruby-2.4.0/ruby
installing default gems:      /usr/local/lib/ruby/gems/2.4.0 (build_info, cache, doc, extensions, gems, specifications)
                              bigdecimal 1.3.2
                              io-console 0.4.6
                              json 2.0.4
                              openssl 2.0.9
                              psych 2.2.2
                              rdoc 5.0.1
installing bundle gems:       /usr/local/lib/ruby/gems/2.4.0 (build_info, cache, doc, extensions, gems, specifications)
                              did_you_mean 1.1.0
                              minitest 5.10.1
                              net-telnet 0.1.1
                              power_assert 0.4.1
                              rake 12.0.0
                              test-unit 3.2.3
                              xmlrpc 0.2.1
installing rdoc:              /usr/local/share/ri/2.4.0/system
installing capi-docs:         /usr/local/share/doc/ruby
[xxxx@xxxx ruby-2.4.10]$ ruby -v

ruby 版本升级

rvm安装

[xxxxx~]$ curl -sSL https://get.rvm.io | bash -s stable
curl: (7) Failed to connect to 2600:3c03::f03c:91ff:fedb:6957: 网络不可达

浏览器打开https://get.rvm.io 拷贝 内容保存为 rvm-installer.sh

sh  rvm-installer.sh


提示 -bash: rvm: 未找到命令

source /home/xxxx/.rvm/scripts/rvm

xxxx 为运行sh rvm-installer.sh 中的安装路径

ruby升级

使用 rvm list known列出可以安装的ruby版本

[xxxxx rubies]$ rvm install 2.4
Searching for binary rubies, this might take some time.
No binary rubies available for: centos/7/x86_64/ruby-2.4.10.
Continuing with compilation. Please read 'rvm help mount' to get more information on binary rubies.
Checking requirements for centos.
Requirements installation successful.
Installing Ruby from source to: /home/xxxx/.rvm/rubies/ruby-2.4.10, this may take a while depending on your cpu(s)...
ruby-2.4.10 - #downloading ruby-2.4.10, this may take a while depending on your connection...
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:--  0:00:17 --:--:--     0curl: (7) Failed to connect to 2a04:4e42:36::434: 网络不可达
There was an error(7).
Checking fallback: https://ftp.ruby-lang.org/pub/ruby/2.4/ruby-2.4.10.tar.bz2
No fallback URL could be found, try increasing timeout with:

    echo "export rvm_max_time_flag=20" >> ~/.rvmrc

There has been an error fetching the ruby interpreter. Halting the installation.

下载 https://ftp.ruby-lang.org/pub/ruby/2.4/ruby-2.4.10.tar.bz2 拷贝到 /home/xxxx/.rvm/rubies/
解压 执行 ./configure

[xxxxx@xxxxx ruby-2.4.10]$ ./configure 
checking for ruby... /usr/bin/ruby
config.guess already exists
config.sub already exists
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-pc-linux-gnu
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
.....
.....
Configuration summary for ruby version 2.4.10
......
   * strip command:       strip -S -x
   * install doc:         yes
   * man page type:       doc

执行 make

[xxxx@xxxx ruby-2.4.10]$ make
    CC = gcc
    LD = ld
    LDSHARED = gcc -shared
    CFLAGS = -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wno-tautological-compare -Wno-parentheses-equality -Wno-constant-logical-operand -Wno-self-assign -Wunused-variable -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wdeclaration-after-statement -Wimplicit-function-declaration -Wdeprecated-declarations -Wno-packed-bitfield-compat -Wsuggest-attribute=noreturn -Wsuggest-attribute=format -std=gnu99 
    XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -fexcess-precision=standard -DRUBY_EXPORT -fPIE
    CPPFLAGS =   -I. -I.ext/include/x86_64-linux -I./include -I. -I./enc/unicode/9.0.0
    DLDFLAGS = -Wl,--compress-debug-sections=zlib -fstack-protector -pie  
    SOLIBS = 
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright © 2015 Free Software Foundation, Inc.
本程序是自由软件;请参看源代码的版权声明。本软件没有任何担保;
包括没有适销性和某一专用目的下的适用性担保。
making dummy probes.h
file2lastrev.rb: does not seem to be under a vcs: ......
....
[xxx@xxxx ruby-2.4.10]$ rvm install 2.4
Already installed ruby-2.4.10.
To reinstall use:

    rvm reinstall ruby-2.4.10

fpm 安装

 gem install fpm

有时会卡住 gem install fpm 需要更换gem 源

gem sources --add http://mirrors.aliyun.com/rubygems/ --remove https://rubygems.org/  

安装成功如下

[ ~]# gem install fpm
Fetching: stud-0.0.23.gem (100%)
Successfully installed stud-0.0.23
Fetching: dotenv-2.7.6.gem (100%)
Successfully installed dotenv-2.7.6
Fetching: insist-1.0.0.gem (100%)
....
....
Done installing documentation for stud, dotenv, insist, mustache, clamp, cabin, pleaserun, io-like, ffi, ruby-xz, childprocess, arr-pm, backports, json, fpm after 28 seconds
15 gems installed

制作rpm包

以zookeeper 为例
下载个zookeeper-3.5.6.tar.gz 的包,解压后修改名称为zookeeper(修改名称非必要),拷贝到opt下(当然也可以是其他目录)

[xxx bin]# cd /opt/
[xxx opt]# ls
cni  containerd  rh  zookeeper
[xxx opt]# fpm -s dir -t rpm -n zookeeper -v 3.5.6    -f  /opt/zookeeper/
Doing `require 'backports'` is deprecated and will not load any backport in the next major release.
Require just the needed backports instead, or 'backports/latest'.
Created package {:path=>"zookeeper-3.5.6-1.x86_64.rpm"}
FPM常用参数:
-s:指定源类型
-t:指定目标类型,即想要制作为什么包
-n:指定包的名字
-v:指定包的版本号
-C:指定打包的相对路径
-d:指定依赖于哪些包
-f:第二次包时目录下如果有同名安装包存在,则覆盖它;
-p:制作的rpm安装包存放路径,不想放在当前目录下就需要指定;
--post-install:软件包安装完成之后所要运行的脚本;同--offer-install
--pre-install:软件包安装完成之前所要运行的脚本;同--before-install
--post-uninstall:软件包卸载完成之后所要运行的脚本;同--offer-remove
--pre-uninstall:软件包卸载完成之前所要运行的脚本;同—before-remove
--prefix:制作好的rpm包默认安装路径;

你可能感兴趣的:(fpm 制作rpm,fpm 打包 rpm)