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镜像源
. waiting to receive.**B0100000023be50
[root@localhost yum.repos.d]# ls
brk CentOS7-Base-163.repo
[root@localhost yum.repos.d]# yum makecache 重建yum缓存
[root@localhost yum.repos.d]# cd brk/
[root@localhost brk]# mv CentOS-Base.repo ../ #将CentOS-Base.repo移动出来
[root@localhost brk]# cd ..
[root@localhost yum.repos.d]# ls
brk CentOS7-Base-163.repo CentOS-Base.repo
[root@localhost yum.repos.d]# yum -y install epel-release #安装epel源
[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 makecache #再次重建缓存成功
二、安装ruby环境和gem命令FPM
[root@localhost yum.repos.d]# yum install -y ruby rubygems ruby-devel
[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
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
#在升级rubygems版本
[root@localhost ~]# gem update --system
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 ***
http://mirrors.aliyun.com/rubygems/
[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
-----------------------------------------------------------------------------------------------
[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
进行安装测试
[root@localhost ~]# rpm -ivh nginx-1.10.2-1.x86_64.rpm
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
成功