2021-05-12 14:32:11
採用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 http://ruby.taobao.org/
# gem sources -r https://rubygems.org/
# gem install fpm
2、打包luajit
# mkdir /tmp/luajit
# cd /usr/local/src
# wget http://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 'http://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 http://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 'http://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包 http://www.linuxidc.com/Linux/2015-04/116465.htm
RPM包建立入門 http://www.linuxidc.com/Linux/2015-02/113559.htm
如何在Linux中建立RPM包? http://www.linuxidc.com/Linux/2012-05/60278.htm
製作自己的rpm包 http://www.linuxidc.com/Linux/2013-06/86435.htm
Linux 下rpm安裝後的目錄結構和一些設定 http://www.linuxidc.com/Linux/2013-06/85761.htm
rpm與yum的綜合性介紹與範例演示 http://www.linuxidc.com/Linux/2013-05/84480.htm
RedHat Linux---rpm 命令詳解 http://www.linuxidc.com/Linux/2013-03/81971.htm
使用FPM輕鬆製作RPM包 http://www.linuxidc.com/linux/2014-06/103019.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-11/124965.htm
相關文章