FPM简介(定制rpm包)

FPM简介

fpm是生成rpm包的工具。rpm包的制作,采用fpm工具完成,FPM非常易用,此命令可以把rpm包的安装、卸载做得更加优雅,在安装前可以做一些准备工作,安装后可以做一些收尾工作,在卸载前也可以做一些准备,比如检测一下相应的服务是否停止了,在卸载软件再做一些扫尾的工作,只要把这些定义成一个个脚本,fpm中指定相应的选项即可轻松实现。
FPM的github: https://github.com/jordansissel/fpm

FPM安装

gem sources –a http://mirrors.aliyun.com/rubygems/
gem sources --remove http://rubygems.org/
gem install fpm -v 1.4.0
yum -y install ruby rubygems ruby-devel gcc

1. 准备操作

 1.1准备好nginx的安装包,统一放在/application/tools/目录下

/home/oldboy/tools
cd /application/tools/
wget http://nginx.org/download/nginx-1.6.3.tar.gz

1.2开启yum缓存,这样yum下载的包都会在本地保存

sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf

1.3清空本机已有的yum缓存

find /var/cache/ -type f -name "*rpm" | xargs rm –f

2.编译安装nginx

2.1更改为国内yum源:

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

2.2安装相关依赖

 yum install pcre-devel openssl-devel –y

2.3打包rpm包, 并下载到本地: 

[root@backup tmp]# find /var/cache/ -type f -name "*rpm"|xargs cp -t /tmp/
[root@backup tmp]# ls /tmp/
keyutils-libs-devel-1.4-5.el6.x86_64.rpm    libselinux-2.0.94-7.el6.x86_64.rpm        openssl-1.0.1e-48.el6_8.1.x86_64.rpm
krb5-devel-1.10.3-57.el6.x86_64.rpm         libselinux-devel-2.0.94-7.el6.x86_64.rpm  openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm
krb5-libs-1.10.3-57.el6.x86_64.rpm          libselinux-utils-2.0.94-7.el6.x86_64.rpm  pcre-devel-7.8-7.el6.x86_64.rpm
libcom_err-devel-1.41.12-22.el6.x86_64.rpm  libsepol-devel-2.0.41-4.el6.x86_64.rpm    zlib-devel-1.2.3-29.el6.x86_64.rpm
[root@backup tmp]#
[root@backup tmp]# cd /tmp/ && tar zcf nginx_yum.tar.gz *.rpm
[root@backup tmp]# ls nginx_yum.tar.gz 
nginx_yum.tar.gz
[root@backup tmp]#
[root@backup tmp]# sz nginx_yum.tar.gz

2.4安装nginx

cd /home/oldboy/tools/
useradd nginx -M -s /sbin/nologin
tar xf nginx-1.6.3.tar.gz
cd nginx-1.6.3
./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
ln -s /application/nginx-1.6.3/ /application/nginx

2.5编写脚本

mkdir -p /server/scripts/ 
cd /server/scripts/
cat nginx_rpm.sh 

#!/bin/bash
useradd nginx -M -s /sbin/nologin
ln -s /application/nginx-1.6.3/ /application/nginx

2.6使用fpm制作rmp包

fpm -s dir -t rpm -n nginx -v 1.6.3 -d 'pcre-devel,openssl-devel' --post-install /server/scripts/nginx_rpm.sh -f /application/nginx-1.6.3/
sz nginx-1.6.3-1.x86_64.rpm

2.7检查制作好的rpm包

[root@db01 scripts]# rpm -qpi nginx-1.6.3-1.x86_64.rpm 
Name        : nginx                        Relocations: / 
Version     : 1.6.3                             Vendor: root@m01
Release     : 1                             Build Date: 2016年06月29日 星期三 07时13分07秒
Install Date: (not installed)               Build Host: m01
Group       : default                       Source RPM: nginx-1.6.3-1.src.rpm
Size        : 5252902                          License: unknown
Signature   : (none)
Packager    : <root@m01>
URL         : http://example.com/no-uri-given
Summary     : no description given
Description :
no description given
[root@db01 scripts]# rpm -qp --scripts  nginx-1.6.3-1.x86_64.rpm     
postinstall scriptlet (using /bin/sh):
#!/bin/bash
useradd nginx -M -s /sbin/nologin
ln -s /application/nginx-1.6.3/ /application/nginx
[root@db01 scripts]#

3. 安装rpm包

3.1 找一台需要安装nginx的机器,上传前面制作好的:nginx-1.6.3-1.x86_64.rpm和nginx_yum.tar.gz 到新的机器。

[root@grewan tools]# ls -l
总用量 6564
-rw-r--r-- 1 root root 2273452 6月  29 07:13 nginx-1.6.3-1.x86_64.rpm
-rw-r--r-- 1 root root 4442091 6月  29 06:57 nginx_yum.tar.gz
[root@grewan tools]#

3.2解压nginx_yum.tar.gz,把所有的依赖包放到同一个目录下,使用rpm 明确一起安装:

[root@grewan tools]# tar xf nginx_yum.tar.gz 
[root@grewan tools]# ls
keyutils-libs-devel-1.4-5.el6.x86_64.rpm    libselinux-devel-2.0.94-7.el6.x86_64.rpm  openssl-1.0.1e-48.el6_8.1.x86_64.rpm
krb5-devel-1.10.3-57.el6.x86_64.rpm         libselinux-utils-2.0.94-7.el6.x86_64.rpm  openssl-devel-1.0.1e-48.el6_8.1.x86_64.rpm
krb5-libs-1.10.3-57.el6.x86_64.rpm          libsepol-devel-2.0.41-4.el6.x86_64.rpm    pcre-devel-7.8-7.el6.x86_64.rpm
libcom_err-devel-1.41.12-22.el6.x86_64.rpm  nginx-1.6.3-1.x86_64.rpm                  zlib-devel-1.2.3-29.el6.x86_64.rpm
libselinux-2.0.94-7.el6.x86_64.rpm          nginx_yum.tar.gz
[root@grewan tools]#

3.3开始安装

[root@grewan tools]# rpm -Uvh --aid *rpm 
Preparing...                ########################################### [100%]
   1:libselinux             ########################################### [  8%]
   2:krb5-libs              ########################################### [ 15%]
   3:openssl                ########################################### [ 23%]
   4:zlib-devel             ########################################### [ 31%]
   5:pcre-devel             ########################################### [ 38%]
   6:libsepol-devel         ########################################### [ 46%]
   7:libselinux-devel       ########################################### [ 54%]
   8:libcom_err-devel       ########################################### [ 62%]
   9:keyutils-libs-devel    ########################################### [ 69%]
  10:krb5-devel             ########################################### [ 77%]
  11:openssl-devel          ########################################### [ 85%]
  12:nginx                  ########################################### [ 92%]
  13:libselinux-utils       ########################################### [100%]
[root@grewan tools]#

3.4查看安装结果

[root@grewan tools]# ls /application/nginx
conf  html  logs  sbin
[root@grewan tools]#

3.5定制LNMP的RPM包思路 

1. 编译安装好nginx,php,mysql,此处有一个问题,就是php的大部分依赖环境是通过yum安装的,但有一个libiconv-1.14.tar.gz包需要编译安装,安装时已经指定了安装目录,只需一同打包即可。
2. 还有一个问题,就是mysql这个目录比较大,用fpm打包耗时比较长,平时我们有可能需要对nginx或php做优化,这样又得重新打包。因此我们可以将mysql分离出来,分别打包,只需要在制作nginx+php的rpm包时添加mysql依赖即可。

原文地址:https://www.cnblogs.com/Carr/p/7396105.html