Linux系統下想要制作RPM包,可以使用FPM工具來完成。FPM工具不僅能讓RPM包制作變得更簡單,還能幫助用戶做一些收尾的工作。下面就來介紹一下Linux系統下使用FPM制作RPM包的方法。
這裡涉及的參數是:
--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
以上就是Linux系統下使用FPM制作RPM包的方法了,這樣一來就可以用RPM包來打包和安裝網絡上的軟件了,還不趕快去試一下。