Making nginx rpm packages with FPM

Source: Internet
Author: User
Tags rpmbuild

When using the Saltstack deployment, we relied on the company's own RPM package, the compiled parameters, the scripts that were started to be customized, and then the RPM package into the company's own Yum repository. The way to make RPM package many Checkinstall spec files, FPM use is very simple, mainly introduced under


1. Installing FPM

Yum-y install ruby RubyGems ruby-devel rpm-buildgem sources-a http://ruby.taobao.org/gem sources--remove Http://rubygem S.org/gem Install FPM

2. Compile nginx and create a virtual directory

MKDIR-PV/OPT/NGINX/{ETC/RC.D/INIT.D,SYSCONFIG}TAR-ZXVF NGINX-1.6.2.TAR.GZCD nginx-1.6.2./configure--prefix=/usr/ Local/nginx--pid-path=/usr/local/nginx/nginx.pid--lock-path=/var/lock/nginx.lock--user=nginx--group=nginx-- With-http_ssl_module--with-http_dav_module--with-http_flv_module--with-http_realip_module--with-http_gzip_ Static_module--with-http_stub_status_module--with-mail--with-mail_ssl_module--with-debug-- Http-client-body-temp-path=/usr/local/nginx/client--http-proxy-temp-path=/usr/local/nginx/proxy-- http-fastcgi-temp-path=/usr/local/nginx/fastcgi--http-uwsgi-temp-path=/usr/local/nginx/uwsgi-- Http-scgi-temp-path=/usr/local/nginx/scgimakemake Install Destdir=/opt/nginx

3. View the directory structure under/opt/nginx

├── after_install.sh├── after_remove.sh├── etc│   ├── rc.d│    │   └── init.d│   │       └──  nginx│   └── sysconfig└── usr    └── local         └── nginx             ├── conf            │    ├── fastcgi.conf            │    ├── fastcgi.conf.default             │   ├── fastcgi_params             │   ├── fastcgi_params.default             │   ├── koi-utf            │    ├── koi-win            │    ├── mime.types            │    ├── mime.types.default             │   ├── nginx.conf             │   ├── nginx.conf.default             │   ├── scgi_params             │   ├── scgi_params.default             │   ├── uwsgi_params             │   ├── uwsgi_params.default             │   ├── vhost             │   └── win-utf             ├── html            │    ├── 50x.html            │    └── index.html            ├──  logs            └── sbin                 └── nginx

Here I have changed the Nginx configuration into the inside, as well as the Nginx startup script placed under the/opt/nginx/etc/rc.d/init.d/, two shell script one is to create the Nginx running user after the installation is complete, And the actions taken after uninstalling the RPM package

[Email protected] ~# cat/opt/nginx/after_install.sh#!/bin/bashuseradd www[email protected] ~# Cat/opt/nginx/after_ Remove.sh#!/bin/bashrm-rf/usr/local/nginx

The Nginx startup script is as follows:

 1 #!/bin/bash  2 # chkconfig: 2345 80 12  3 #  processname: nginx  4 # qq:455471484  5 source /etc/init.d/ functions  6  7  8 [ -r  "$SYSCONFIG"  ] &&  source  "$SYSCONFIG"   9 retval=0 10 start ()  { 11      echo -n $ "Starting nginx:"  12     daemon /usr/ local/nginx/sbin/nginx 13     retval=$? 14      echo 15     [  $RETVAL  -eq 0 ] && touch  /var/lock/subsys/nginx 16     return  $RETVAL  17 } 18  19 stop ()  { 20    echo -n $ "Stoping Nginx:"  21     daemon kill -quit  ' Cat /usr/local/nginx/nginx.pid '  22    retval=$? 23     echo 24    [  $RETVAL  -eq 0 ] & & rm -rf /var/lock/subsys/nginx 25    return  $RETVAL  26  } 27 28 restart ()  { 29    echo -n $ "Restart  Nginx: " 30    daemon /usr/local/nginx/sbin/nginx -s reload 31     retval=$? 32    echo 33    return   $RETVAL  34 35 } 36 37 38 case  "$"  in 39     start)  40       start 41        ;;  42    stop)  43       stop 44        ;;  45    restart|reload)  46       restart  47       ;;  48 esac 49 exit  $RETVAL

The contents of the virtual directory after you have finished the FPM file will be the same as inside, that is, if your company has its own profile template, you can pre-direct to the RPM package, you can use the FPM command to build. FPM provides a number of parameters that can be--help to see according to the requirements ~

4. Packaging commands:

Fpm-f-S dir-t rpm-n qding-nginx--epoch 0-v1.6.2--iteration 1.el6-c/opt/nginx/-p/root/-d ' openssl-devel '-d ' GC C '-d ' gcc-c++ '-d ' pcre-devel '-d ' zlib-devel '--verbose--category ' development/languages '--description ' Nginx applicat Ions '--url ' nginx.org '--license ' BSD '-M ' Bianji '--no-rpm-sign--after-install/opt/nginx/after_install.sh--after-re Move after_remove.sh--workdir/opt/nginx/etc usr

I use the parameter description:

FPM parameter Detailed usage: fpm [options]  -p, --package packagefile          Managed Packages   -n, --name PACKAGENAME             define the name of the generated package   -v, --version VERSION              define the version of the generated package       --iteration  ITERATION         set  iteration value for package   (' Release '  for  RPM) .      --epoch epoch                  set  epoch values for packages   -d, -depends  dependency           set the dependencies of the package   -c directory                        before you search for filesGo to this directory first   -t PACKAGE_TYPE                    set the type of target package   -s SOURCE_TYPE                     set the type of package that needs to be converted  -- after-remote  Execute script after uninstall--after-install  after installation

The

performs the following, and the output is still friendly:

fpm -f -s dir -t rpm -n qding-nginx --epoch 0 -v1.6.2 - -iteration 1.el6 -c /opt/nginx/ -p /root/ -d  ' openssl-devel '  -d  ' GCC '  -d  ' gcc-c++ '  -d  ' pcre-devel '  -d  ' zlib-devel '  --verbose --category   ' development/languages '  --description  ' nginx applications '  --url  ' nginx.org '  --license  ' BSD '  -m  ' Bianji '  --no-rpm-sign --after-install /opt/nginx/after _install.sh  --after-remove after_remove.sh --workdir /opt/nginx/ etc  Usrsetting workdir {:workdir=> "/opt/nginx/",  :level=>:info}setting from flags:  category=development/languages {:level=>:info}setting from flags: description= Nginx applications {:level=>:info}setting from flags: epoch=0 {:level=>: Info}setting from flags: iteration=1.el6 {:level=>:info}setting from flags: license=bsd {: Level=>:info}setting from flags: maintainer=bianji {:level=>:info}setting from  flags: name=qding-nginx {:level=>:info}setting from flags: url=nginx.org  {:level=>:info}setting from flags: version=1.6.2 {:level=>:info}converting  dir to rpm {:level=>:info}force flag given. overwriting package  at /root/qding-nginx-1.6.2-1.el6.x86_64.rpm {:level=>:warn}reading template {: Path=> "/usr/lib/ruby/gems/1.8/gems/fpm-1.3.3/templates/rpm.erb", :level=>:info}running  rpmbuild {:args=>["Rpmbuild",  "-bb",  "--define",  "buildroot /opt/nginx/ Package-rpm-build20150415-14369-365eos/build ", "--define ", " _topdir /opt/nginx/ Package-rpm-build20150415-14369-365eos ", "--define ",   " _sourcedir /opt/nginx/package-rpm-build20150415-14369-365eos ", "--define ", " _rpmdir /opt/ Nginx/package-rpm-build20150415-14369-365eos/rpms ", "--define ", " _tmppath /opt/nginx/", "/ Opt/nginx/package-rpm-build20150415-14369-365eos/specs/qding-nginx.spec "], :level=>:info}executing (% Prep):  /bin/sh -e /opt/nginx/rpm-tmp.ffua4s {:level=>:info}executing (%build):  /bin /sh -e /opt/nginx/rpm-tmp. Hmwmva {:level=>:info}executing (%install):  /bin/sh -e /opt/nginx/rpm-tmp. N2vnxr {:level=>:info}processing files: qding-nginx-1.6.2-1.el6.x86_64 {:level=>: Info}wrote: /opt/nginx/package-rpm-build20150415-14369-365eos/rpms/x86_64/qding-nginx-1.6.2-1.el6.x86_64. Rpm {:level=>:info}executing (%clean):  /bin/sh -e /opt/nginx/rpm-tmp.lyfwxl {:level =>:info}created package {:p ath=> "/root/qding-nginx-1.6.2-1.el6.x86_64.rpm"}

Build after successful can see qding-nginx this RPM package under/root/... Then you can use it in the Yum warehouse.

This article from "Qiu Anxiaoqiu" blog, please be sure to keep this source http://heygirl32895.blog.51cto.com/7623150/1632994

Making nginx rpm packages with FPM

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.