FPM制做Nginx的RPM软件包

 FPM制做Nginx的rpm软件包html

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包默认安装路径linux

-------------------------------------------------------------------------------nginx

1、搭建epel源vim

-------------------------------------------------------------------------------缓存

[root@localhost yum.repos.d]# rz                            #上传163镜像源在线yum
[root@localhost yum.repos.d]# ls
a  CentOS7-Base-163.repo ruby

[root@localhost yum.repos.d]# rz                            #上传epel源bash

[root@localhost yum.repos.d]# lspost

 

a测试

epel-release-latest-7.noarch.rpm ui

CentOS7-Base-163.repo                  

[root@localhost yum.repos.d]# rpm -ivh epel-release-latest-7.noarch.rpm            #安装epel源  

[root@localhost yum.repos.d]# ls 

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            #再次重建缓存成功

--------------------------------------------------------------------------

2、安装ruby环境和gem命令FPM

--------------------------------------------------------------------------

 

[root@localhost yum.repos.d]# yum   -y   install   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       #升级到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 ***
 
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的网页
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
进行安装测试以前若是你以前安装过nginx的话须要将以前的Nginx删除干净
[root@localhost ~]# rm -rf /usr/local/nginx
[root@localhost ~]# rm -rf /usr/src/nginx
[root@localhost ~]# rm -rf /usr/local/bin/nginx                #作过软链接的话须要删除软链接
[root@localhost ~]#killall -9 nginx                                    #杀死Nginx进程
[root@localhost ~]#  userdel -r nginx                                 #删除Nginx的测试用户
[root@localhost ~]# rpm -ivh nginx-1.10.2-1.x86_64.rpm                       #安装Nginx进行测试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成功
相关文章
相关标签/搜索