采用FPM工具制作RPM包

本次rpm包的制作,采用fpm工具完成,FPM非常易用,此命令可以把rpm包的安装、卸载做得更加优雅,在安装前可以做一些准备工作,安装后可以做一些收尾工作,在卸载前也可以做一些准备,比如检测一下相应的服务是否停止了,在卸载软件再做一些扫尾的工作,只要把这些定义成一个个脚本,fpm中指定相应的选项即可轻松实现。

这里涉及的参数是:
–pre-install FILE:表示安装之前所要运行的脚本
–post-install FILE:表示安装之后所要运行的脚本
–pre-uninstall FILE:表示卸载之前所要运行的脚本
–post-uninstall FILE:表示卸载之后所要运行的脚本

1、fpm工具安装

# yum -y install ruby rubygems ruby-devel rpm-build

# gem sources -a https://ruby.taobao.org/

# gem sources -r https://rubygems.org/

# gem install fpm

2、打包luajit

# mkdir /tmp/luajit

# cd /usr/local/src

# wget https://luajit.org/download/LuaJIT-2.0.4.tar.gz

# tar xvzf LuaJIT-2.0.4.tar.gz

# cd LuaJIT-2.0.4

# make PREFIX=/usr

# make install PREFIX=/usr DESTDIR=/tmp/luajit

# fpm -s dir -t rpm -n LuaJIT -v 2.0.4 –iteration 1.el7 -C /tmp/luajit/ -p /root –description ‘luajit rpm package' –url ‘https://luajit.org'

 

3、打包tengine

# mkdir /tmp/tengine

# cd /usr/local/src

# wget -O lua-nginx-module-0.9.16.tar.gz https://codeload.github.com/openresty/lua-nginx-module/tar.gz/v0.9.16

# tar xvzf lua-nginx-module-0.9.16.tar.gz

# wget https://tengine.taobao.org/download/tengine-2.1.0.tar.gz

# tar xvzf tengine-2.1.0.tar.gz

# cd tengine-2.1.0

 

# ./configure –prefix=/opt/share/nginx \

–sbin-path=/opt/sbin/nginx \

–conf-path=/opt/etc/nginx/nginx.conf \

–error-log-path=/opt/log/nginx/error.log \

–http-log-path=/opt/log/nginx/access.log \

–user=nginx \

–group=nginx \

–http-client-body-temp-path=/opt/lib/nginx/tmp/client_body \

–http-proxy-temp-path=/opt/lib/nginx/tmp/proxy \

–http-uwsgi-temp-path=/opt/lib/nginx/tmp/uwsgi \

–pid-path=/opt/run/nginx.pid \

–lock-path=/opt/lock/subsys/nginx \

–with-http_ssl_module \

–with-http_realip_module \

–with-http_addition_module \

–with-http_gzip_static_module \

–with-http_gunzip_module \

–with-http_secure_link_module \

–with-http_stub_status_module \

–with-http_sysguard_module \

–with-file-aio \

–add-module=../lua-nginx-module-0.9.16 \

–with-cc-opt='-g -O2 -fstack-protector –param=ssp-buffer-size=4 -Wformat -Werror=format-security' \

–with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro'

 

# make

# make install DESTDIR=/tmp/tengine

 

# cd /tmp/tengine/opt

# mkdir -p lib/nginx/tmp/{client_body,proxy,uwsgi}

# mkdir -p lock/subsys/nginx

 

# cd /tmp/tengine

# mkdir etc/rc.d/init.d

# cp /etc/rc.d/init.d/nginx etc/rc.d/init.d

# mkdir etc/logrotate.d

# cp /etc/logrotate.d/nginx etc/logrotate.d

# mkdir tmp

安装之前所要运行的脚本
# vim tmp/install_before.sh

#!/bin/bash
 
[[ -n `ps aux|grep ngin[x]` ]] && killall -9 nginx
[[ -e /opt/etc/nginx ]] && cp -a /opt/etc/nginx/ /opt/etc/nginx_$(date +%F_%H-%M-%S)

安装之后所要运行的脚本

# vim tmp/install_after.sh

#!/bin/bash
 
[[ -n `getent group nginx` ]] || groupadd -r nginx
[[ -n `getent passwd nginx` ]] || useradd nginx -r -g nginx -s /sbin/nologin
 
[[ -n `getent group www-data` ]] || groupadd -r www-data
[[ -n `getent passwd www-data` ]] || useradd www-data -r -g www-data -s /sbin/nologin
 
mkdir -p /data/log/nginx
 
if [[ -e /var/log/nginx ]]; then
    if [[ -L /var/log/nginx ]]; then
        rm -f /var/log/nginx && ln -s /data/log/nginx /var/log/nginx
    else
        mv /var/log/nginx/* /data/log/nginx/
        rm -rf /var/log/nginx && ln -s /data/log/nginx /var/log/nginx
    fi
else
    ln -s /data/log/nginx /var/log/nginx
fi
 
/opt/sbin/nginx -c /opt/etc/nginx/nginx.conf

打包tengine

# chmod +x tmp/*.sh

# fpm -s dir -t rpm -n tengine -v 2.1.0 –iteration 1.waf.el7 -C /tmp/tengine/ -p /root –description ‘tengine rpm package' –url ‘https://tengine.taobao.org' –pre-install /tmp/tengine/tmp/install_before.sh –post-install /tmp/tengine/tmp/install_after.sh

rpm软件包信息查看
# rpm -qp –scripts /root/tengine-2.1.0-1.waf.ele.el7.x86_64.rpm

最终的安装步骤

# yum -y install pcre pcre-devel openssl openssl-devel

# rpm -Uvh LuaJIT-2.0.4-1.el7.x86_64.rpm

# rpm -Uvh tengine-2.1.0-1.waf.el7.x86_64.rpm

下面关于RPM的文章您也可能喜欢,不妨看看:

用FPM快速制作RPM包 

RPM包创建入门 

如何在中创建RPM包? 

制作自己的rpm包

下rpm安装后的目录结构和一些配置

rpm与yum的综合性介绍与示例演示

使用FPM轻松制作RPM包

转载自:https://www.linuxidc.com/Linux/2015-11/124965.htm

声明: 除非转自他站(如有侵权,请联系处理)外,本文采用 BY-NC-SA 协议进行授权 | 智乐兔
转载请注明:转自《采用FPM工具制作RPM包
本文地址:https://www.zhiletu.com/archives-5220.html
关注公众号:智乐兔

赞赏

wechat pay微信赞赏alipay pay支付宝赞赏

上一篇
下一篇

相关文章

在线留言

你必须 登录后 才能留言!