FPM制作Nginx的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包默认安装路径
-------------------------------------------------------------------------------
一、搭建epel源
-------------------------------------------------------------------------------
[root@localhost yum.repos.d]# rz #上传163镜像源在线yum
[root@localhost yum.repos.d]# ls
a CentOS7-Base-163.repo
[root@localhost yum.repos.d]# rz #上传epel源
[root@localhost yum.repos.d]# ls
a
epel-release-latest-7.noarch.rpm
CentOS7-Base-163.repo
[root@localhost yum.repos.d]# rpm -ivh epel-release-latest-7.noarch.rpm #安装epel源
[root@localhost yum.repos.d]# ls
a
CentOS7-Base-163.repo
epel-release-latest-7.noarch.rpm
epel-testing.repo
epel.repo
[root@localhost yum.repos.d]# yum -y clean all #清除缓存
[root@localhost yum.repos.d]# yum makecache #重建yum缓存
Cannot retrieve metalink for repository: epel/x86_64. Please verify its path and try again 报错
[root@localhost yum.repos.d]# vim epel.repo #修改epel文件
将所有baseurl 开启
将所有 metalink 注释掉
[root@localhost yum.repos.d]# yum -y clean all #再次清除缓存
[root@localhost yum.repos.d]# yum makecache #再次重建缓存成功
--------------------------------------------------------------------------
二、安装ruby环境和gem命令FPM
--------------------------------------------------------------------------
[root@localhost ~]# gem update --system #升级rubygems版本
Updating rubygems-update
Fetching: rubygems-update-3.0.6.gem (100%)
ERROR: Error installing rubygems-update:
rubygems-update requires Ruby version >= 2.3.0.
ERROR: While executing gem ... (NoMethodError)
undefined method `version' for nil:NilClass
#升级失败提示我们升级到2.3.0版本
[root@localhost ~]# gem install rubygems-update -v 2.3.0 #升级到2.3.0版本
Updating rubygems-update
Fetching: rubygems-update-3.0.6.gem (100%)
ERROR: Error installing rubygems-update:
rubygems-update requires Ruby version >= 2.3.0.
ERROR: While executing gem ... (NoMethodError)
undefined method `version' for nil:NilClass
[root@localhost ~]# gem install rubygems-update -v 2.3.0
Fetching: rubygems-update-2.3.0.gem (100%)
Successfully installed rubygems-update-2.3.0
Parsing documentation for rubygems-update-2.3.0
Installing ri documentation for rubygems-update-2.3.0
1 gem installed
[root@localhost ~]# gem update --system #在升级rubygems版本
RubyGems system software updated
--------------------------------------------------------------------------------------------
[root@localhost ~]# gem sources -a http://mirrors.aliyun.com/rubygems/ #添加国内源
source http://mirrors.aliyun.com/rubygems/ already present in the cache
[root@localhost ~]# gem sources --remove https://rubygems.org/ #删除国外源(因为国外源下载较为缓慢,所以需要国内源的帮助)
https://rubygems.org/ removed from sources
[root@localhost ~]# gem sources -l #查看源
*** CURRENT SOURCES ***
[root@localhost ~]# gem install fpm #安装fpm软件
Installing ri documentation for fpm-1.11.0
14 gems installed
---------------------------------------------------------------
[root@localhost ~]# vim nginx.sh
#!/bin/bash
useradd -M -s /sbin/nologin nginx
ln -s /usr/local/nginx/sbin/nginx /sbin/
echo www.crushlinux.com > /usr/local/nginx/html/index.html #将自己想要添加的内容写入到Nginx的网页
nginx
-----------------------------------------------------------
[root@localhost ~]# fpm -s dir -t rpm -n nginx -v 1.10.2 -d 'pcre-devel,zlib-devel' -f --post-install /root/nginx.sh /usr/local/nginx #生成rpm包
Need executable 'rpmbuild' to convert dir to rpm {:level=>:error} #出现这个报错,需要安装rpm-build的安装包
[root@localhost ~]# yum -y install rpm-build #安装
#生成rpm包
[root@localhost ~]# fpm -s dir -t rpm -n nginx -v 1.10.2 -d 'pcre-devel,zlib-devel' -f --post-install /root/nginx.sh /usr/local/nginx
Created package {:path=>"nginx-1.10.2-1.x86_64.rpm"}
[root@localhost ~]# ls
= anaconda-ks.cfg nginx-1.10.2-1.x86_64.rpm nginx.sh
Preparing... ################################# [100%]
Updating / installing...
1:nginx-1.10.2-1 ################################# [100%]
warning: %post(nginx-1.10.2-1.x86_64) scriptlet failed, exit status 1
成功