欢迎光临
我们一直在努力

fpm定制nginx-rpm包

实验环境介绍:

[root@nginx ~]# uname -r

2.6.32-573.el6.x86_64

[root@nginx ~]# cat /etc/redhat-release

CentOS release 6.7 (Final)

打包之前需要在测试机上先安装 nginx 服务

安装过程如下

[root@nginx ~]# useradd -s /sbin/nologin/ -M nginx

[root@nginx ~]# yum -y install pcre-devel openssl-devel

[root@nginx ~]# tar zxf nginx-1.6.2.tar.gz

[root@nginx ~]# cd nginx-1.6.2

[root@nginx ~]# ./configure \

–user=nginx \

–group=nginx \

–prefix=/application/nginx-1.6.2 \

–with-http_stub_status_module \

–with-http_ssl_module

[root@nginx nginx-1.6.2]# make && make install

[root@nginx nginx-1.6.2]# ln -s /application/nginx-1.6.2/ /application/nginx


fpm 制作开始

通过 yum 安装依赖包

[root@nginx ~]# yum -y install ruby rubygems ruby-devel

更换 yum 源

[root@nginx ~]# gem sources -a http://mirrors.aliyun.com/rubygems/

[root@nginx ~]# gem sources –remove http://rubygems.org/

[root@nginx ~]# gem sources –list

[root@nginx ~]# gem install fpm -v 1.3.3

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

写一个脚本,只需要写入添加的 nginx 用户和创建软连接的命令即可

[root@nginx ~]# vim nginx_fpm.sh

#!/bin/bash

useradd -s /sbin/nologin/ -M nginx

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

执行打包命令

[root@nginx ~]# 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 命令可以自行解决安装问题

[root@lvs1 ~]# yum -y localinstall nginx-1.6.2-1.x86_64.rpm

启动 nginx 服务成功

[root@lvs1 ~]# /application/nginx/sbin/nginx

[root@lvs1 ~]# 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)

赞(0)
【声明】:本博客不参与任何交易,也非中介,仅记录个人感兴趣的主机测评结果和优惠活动,内容均不作直接、间接、法定、约定的保证。访问本博客请务必遵守有关互联网的相关法律、规定与规则。一旦您访问本博客,即表示您已经知晓并接受了此声明通告。