本次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