使用fpm制做rpm包

1、FPM工具安装:
系统:centos7.3
Fpm工具依赖ruby模块,首先安装相关ruby依赖包,还须要安装rpm-buildpython

yum -y install ruby rubygems ruby-devel rpm-build

而后添加阿里的ruby仓库linux

gem sources -a https://gems.ruby-china.org/

移除ruby的原生仓库apache

gem sources --remove https://rubygems.org/

查看ruby的仓库列表,以下所示则表示成功centos

gem sources

CURRENT SOURCES tomcat

https://gems.ruby-china.org/
最后安装fpm,安装可能须要等待一段时间ruby

gem install fpm

安装成功后,能够使用fpm --help来查看fpm命令的使用帮助说明bash

fpm --help

2、fpm经常使用命令参数说明
-C #指定fpm去哪一个目录查找打包的文件
-s #指定源的类型,如dir
-t #指定目标类型,如rpm包,或者deb包等
-n #指定包的名字
-v #指定包的版本号
-d #指定依赖包
-f #第二次制做rpm包若是存在同名,则覆盖
-p #输出rpm包的目录
--prefix #指定安装路径
--after-install #包安装后要运行的脚本
--before-install #包安装前要运行的脚本
--after-remove #包卸载后要运行的脚本
--before-remove #包卸载前要运行的脚本ide

3、使用fpm制做tomcat包(简单示例)
咱们先下载好最新的tomcat二进制包,解压,路径为:
/mnt/zxt/usr/local/tomcat-8.5.28
进入/mnt/zxt/目录,执行fpm命令工具

fpm -f -s dir -t rpm -n tomcat-8.5.28 -p /tmp/ --license 'BSD' -m 'zxt' --no-rpm-sign --verbose -v 0.2.2 --iteration 2.el6 -C /mnt/zxt/ --after-remove 'after_remove.sh'

而后咱们到到/tmp目录下查看生成的rpm包
-rw-r--r-- 1 root root 9593026 Mar 5 15:53 tomcat-8.5.28-0.2.2-2.el6.x86_64.rpm
安装这个tomcat包检查下
#yum -y install tomcat-8.5.28-0.2.2-2.el6.x86_64.rpm
安装完成后咱们看下/usr/local/目录下面有没有tomcat-8.5.28目录ui

ls /usr/local/

aegis apr cloudmonitor include lib64 python3.bak src
apache apr-util etc jdk-8u131-linux-x64.gz libexec sbin tomcat-8.5.28
表示已经成功安装,再卸载此包确认下tomcat-8.5.28目录会不会被删除

yum -y remove tomcat-8.5.28

发现tomcat-8.5.28目录已经被删除。after_remove.sh脚本以下:#!/bin/bashif ps -ef|grep tomcat-8.5.28 &>/dev/null;thenpid=$(ps -ef|grep tomcat-8.5.28|grep -v grep|awk {'print $2'})kill -9 $pidfirm -rf /usr/local/tomcat-8.5.28

相关文章
相关标签/搜索