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成功
相關文章
相關標籤/搜索