1. 程式人生 > >fpm定制nginx-rpm包

fpm定制nginx-rpm包

定制 fpm

實驗環境介紹:

[[email protected] ~]# uname -r

2.6.32-573.el6.x86_64

[[email protected] ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)


打包之前需要在測試機上先安裝 nginx 服務

安裝過程如下

[[email protected] ~]# useradd -s /sbin/nologin/ -M nginx

[[email protected] ~]# yum -y install pcre-devel openssl-devel

[[email protected] ~]# tar zxf nginx-1.6.2.tar.gz

[[email protected] ~]# cd nginx-1.6.2

[[email protected] ~]# ./configure \

--user=nginx \

--group=nginx \

--prefix=/application/nginx-1.6.2 \

--with-http_stub_status_module \

--with-http_ssl_module

[[email protected] nginx-1.6.2]# make && make install

[[email protected] nginx-1.6.2]# ln -s /application/nginx-1.6.2/ /application/nginx


fpm 制作開始

通過 yum 安裝依賴包

[[email protected] ~]# yum -y install ruby rubygems ruby-devel


更換 yum 源

[[email protected] ~]# gem sources -a http://mirrors.aliyun.com/rubygems/

[[email protected] ~]# gem sources --remove http://rubygems.org/

[[email protected] ~]# gem sources --list

[[email protected] ~]# gem install fpm -v 1.3.3

-v 指定要安裝的 fpm 版本,也可以不指定。直接執行 gem install fpm


寫一個腳本,只需要寫入添加的 nginx 用戶和創建軟連接的命令即可

[[email protected] ~]# vim nginx_fpm.sh

#!/bin/bash

useradd -s /sbin/nologin/ -M nginx

ln -s /application/nginx-1.6.2/ /application/nginx


執行打包命令

[[email protected] ~]# fpm -s dir -t rpm -n nginx -v 1.6.2 -d ‘pcre-devel,openssl-devel‘ --post-install /root/nginx_fpm.sh -f /application/nginx-1.6.2/

-s:指定源類型

-t:執行目標類型

-n:執行包的名字

-v:指定包的版本號

-d:指定依賴於哪些包

--post-install:軟件安裝完要運行的腳本

-f:第二次包時目錄下如果有同名安裝包存在,則覆蓋它


在一臺新機器上測試一下剛才的 rpm 包

使用 yum -y localinstall 命令可以自行解決安裝問題

[[email protected] ~]# yum -y localinstall nginx-1.6.2-1.x86_64.rpm


啟動 nginx 服務成功

[[email protected] ~]# /application/nginx/sbin/nginx

[[email protected] ~]# lsof -i :80

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

nginx 1842 root 6u IPv4 14884 0t0 TCP *:http (LISTEN)

nginx 1843 nginx 6u IPv4 14884 0t0 TCP *:http (LISTEN)

本文出自 “LULU” 博客,請務必保留此出處http://aby028.blog.51cto.com/5371905/1942380

fpm定制nginx-rpm包