基于FPM制作nginx RPM包

环境

系统 其它
CentOS 7.5 需提前配置好epel

配置

[root@localhost ~]# yum clean all && yum makecache 
#重建yum元数据

FPM安装

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

[root@localhost ~]# gem sources -a http://mirrors.aliyun.com/rubygems/
#添加阿里云的ruby仓库
http://mirrors.aliyun.com/rubygems/ added to sources
[root@localhost ~]# gem sources -l
*** CURRENT SOURCES ***

https://rubygems.org/
http://mirrors.aliyun.com/rubygems/

[root@localhost ~]# gem sources --remove https://rubygems.org/
#移除原生ruby仓库(在国外,速度慢)
https://rubygems.org/ removed from sources
[root@localhost ~]# gem sources -l
*** CURRENT SOURCES ***

http://mirrors.aliyun.com/rubygems/

[root@localhost ~]# gem update --system
#升级rubygems版本,可能会提示“ERROR:  Error installing rubygems-update:rubygems-update requires Ruby version >= 2.3.0.”

[root@localhost ~]# gem install rubygems-update -v 2.3.0
#升级rubygems的版本

[root@localhost ~]# gem update --system
#再次升级

[root@localhost ~]# gem install fpm
#安装FPM包,比较慢

[root@localhost ~]# ls
nginx-1.14.2.tar.gz

[root@localhost ~]# tar zxf nginx-1.14.2.tar.gz -C /usr/src/
[root@localhost ~]# cd /usr/src/nginx-1.14.2/
[root@localhost nginx-1.14.2]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module && make && make install
#编译安装nginx
  • 创建软件包安装完成之后要运行的脚本
[root@localhost nginx-1.14.2]# vim nginx.sh
    #!/bin/bash
    useradd -M -s /sbin/nologin nginx
    #创建运行的用户
    ln -s /usr/local/nginx/sbin/nginx /sbin/
    #链接二进制文件
    echo success > /usr/local/nginx/html/index.html
    #测试页面
    nginx
    #启动服务
  • 将nginx源码包打成rpm类型
[root@localhost ~]# yum install -y rpm-build
#会用到该工具

[root@localhost ~]# fpm -s dir -t rpm -n nginx -v 1.14.2 -d 'pcre-devel,zlib-devel' -f --post-install /root/nginx.sh /usr/local/nginx/
#-s表示源类型是一个目录,即/usr/local/nginx
#-t目标类型是rpm包
#-n包的名字
#-v包的版本号
#-d所依赖的包
#-f第二次包时目录下如果有同名安装包存在,则覆盖它
#--post-install软件包安装完成之后要运行的脚本

[root@localhost ~]# ls
nginx-1.14.2-1.x86_64.rpm

[root@localhost ~]# rpm -ivh nginx-1.14.2-1.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...
   1:nginx-1.14.2-1                   ################################# [100%]

[root@localhost ~]# netstat -lnpt | grep nginx
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      64244/nginx: master 

over……

猜你喜欢

转载自www.cnblogs.com/joinbestgo/p/10767063.html