FPM customized RPM package made of Nginx RPM package

Source: Internet
Author: User
Tags documentation ffi fpm mkdir openssl prepare zip aliyun
FPM customized RPM package made of Nginx RPM package

1. Install the Ruby module

# yum-y install ruby RubyGems ruby-devel

2. Add Alibaba Cloud RubyGems Warehouse, foreign resources will affect download speed

Gem sources-a http://mirrors.aliyun.com/rubygems/ 
http://mirrors.aliyun.com/rubygems/added to sources

Remove native ruby repositories

Gem Sources--remove http://rubygems.org/

3. Installing FPM

CENTOS6:
gem install json-v 1.8.3
gem install fpm-v 1.3.3

Centos7 use the following command directly:

[Root@slave02 ~]# gem install fpm Fetching:cabin-0.9.0.gem (100%)
Successfully installed cabin-0.9.0 Fetching:backports-3.8.0.gem (100%)
Successfully installed backports-3.8.0 Fetching:arr-pm-0.0.10.gem (100%)
Successfully installed arr-pm-0.0.10 Fetching:clamp-1.0.1.gem (100%)
Successfully installed clamp-1.0.1 Fetching:ffi-1.9.18.gem (100%) Building native extensions.
This could take a while ...
Successfully installed ffi-1.9.18 Fetching:childprocess-0.7.0.gem (100%)
Successfully installed childprocess-0.7.0 Fetching:archive-tar-minitar-0.5.2.gem (100%)
Successfully installed archive-tar-minitar-0.5.2 Fetching:io-like-0.3.0.gem (100%)
Successfully installed io-like-0.3.0 Fetching:ruby-xz-0.2.3.gem (100%)
Successfully installed ruby-xz-0.2.3 Fetching:stud-0.0.22.gem (100%)
Successfully installed stud-0.0.22 Fetching:mustache-0.99.8.gem (100%)
Successfully installed mustache-0.99.8 Fetching:insist-1.0.0.gem (100%) Successfully installed insist-1.0.0 FETCHING:DOTENV-2.2.1.GEM (100%)
Successfully installed dotenv-2.2.1 Fetching:pleaserun-0.0.29.gem (100%)
Successfully installed pleaserun-0.0.29 Fetching:fpm-1.8.1.gem (100%)  Successfully installed fpm-1.8.1 parsing documentation for cabin-0.9.0 installing RI documentation for cabin-0.9.0 parsing 
Documentation for backports-3.8.0 installing RI documentation for backports-3.8.0 parsing documentation for ARR-PM-0.0.10 Installing RI documentation for arr-pm-0.0.10 parsing documentation for clamp-1.0.1 installing RI documentation for CLAMP -1.0.1 parsing documentation for ffi-1.9.18 installing RI documentation for ffi-1.9.18 parsing documentation for CHILDPROC
ess-0.7.0 installing RI documentation for childprocess-0.7.0 parsing documentation for archive-tar-minitar-0.5.2 Installing RI documentation for archive-tar-minitar-0.5.2 parsing documentation for io-like-0.3.0 Installing RI documenta tion for io-like-0.3.0 parsing documentation for ruby-xz-0.2.3 installing RI documentation for ruby-xz-0.2.3 Parsing Docum ENtation for stud-0.0.22 installing RI documentation for stud-0.0.22 parsing documentation for mustache-0.99.8 installing R I documentation for mustache-0.99.8 parsing documentation for insist-1.0.0 installing RI documentation for insist-1.0.0 Pa Rsing documentation for dotenv-2.2.1 installing RI documentation for dotenv-2.2.1 parsing documentation for pleaserun-0.0. Installing RI documentation for pleaserun-0.0.29 parsing documentation for fpm-1.8.1 installing RI documentation for FP m-1.8.1 Gems installed

4. Install the Nginx on the packaging machine first

Yum install-y gcc gcc-c++ glibc make autoconf OpenSSL openssl-devel pcre pcre-devel glib glib-devel useradd
nginx-m -s/sbin/nologin
Tar XF nginx-1.12.0.tar.gz

cd nginx-1.12.0

./configure--prefix=/usr/local/nginx--user =nginx--group=nginx--with-http_ssl_module--with-http_stub_status_module--with-file-aio--with-http_dav_module-- With-pcre make

&& make install

5. Scripting
Before the package uninstall, after the uninstall script, can be written according to the situation, do not write a problem is not big. However, RPM-installed scripts are required.

mkdir/data/scripts/-P
cd/data/scripts/

# Write a script that needs to be executed after RPM installation
Vim nginx_post_install.sh

#!/bin/bash

useradd nginx-m-s/sbin/nologin
chmod +x/etc/init.d/nginx
chkconfig--add nginx
Echo ' Path=/user/local/nginx/sbin: $PATH ' >>/etc/profile.d/nginx.sh

# scripts to execute after uninstalling Nginx

# cat after_remove.sh 
#!/bin/bash
rm-rf/usr/local/nginx
rm-f/etc/rc.d/init.d/nginx

Prepare a startup script, as follows:

Vim/etc/init.d/nginx #!/bin/sh # # Nginx-this script starts and stops the Nginx Daemon # # Chkconfig:-* # des Cription:nginx is an HTTP (s) server, HTTP (s) reverse \ # Proxy and IMAP/POP3 Proxy Server # PROCESSNAME:N Ginx # Config:/usr/local/nginx/conf/nginx.conf # pidfile:/usr/local/nginx/logs/nginx.pid # Source function li
Brary. .
/etc/rc.d/init.d/functions # Source Networking configuration. .
/etc/sysconfig/network # Check that networking are up. ["$NETWORKING" = "no"] && exit 0 nginx= "/usr/local/nginx/sbin/nginx" prog=$ (basename $nginx) nginx_conf_file = "/usr/local/nginx/conf/nginx.conf" Lockfile=/var/lock/subsys/nginx Make_dirs () {# Make required directories US Er= ' $nginx-v 2>&1 | grep "Configure arguments:" | Sed ' s/[^*]*--user=\ ([^]*\). */\1/g '-' If [-Z ' ' grep $user/etc/passwd ']; Then useradd-m-s/bin/nologin $user fi options= ' $nginx-v 2>&1 | grep ' Configure arguments: ' For opt in $options; do if [' Echo $opt | grep '. *-temp-path ']; Then value= ' echo $opt | Cut-d "="-F 2 ' if [!-D "$value"]; 
       Then # echo "Creating" $value mkdir-p $value && chown-r $user $value fi Fi done} start () {[-X $nginx] | | Exit 5 [-F $NGINX _conf_file] | | Exit 6 make_dirs Echo
    -N $ "Starting $prog:" Daemon $nginx-C $NGINX _conf_file retval=$?
    echo [$retval-eq 0] && touch $lockfile return $retval} stop () {echo-n $ "stopping $prog:"
    Killproc $prog-quit retval=$?
    echo [$retval-eq 0] && rm-f $lockfile return $retval} restart () {configtest | | return $?
    Stop sleep 1 start} reload () {Configtest | | return $?
    Echo-n $ "Reloading $prog:" $nginx-S reload retval=$? echo} force_reload () {restart} configtest () {$nginx-T-c $NGINX _conf_file} rh_Status () {status $prog} rh_status_q () {rh_status >/dev/null 2>&1} case "$" in start)
    Rh_status_q && exit 0 $;; Stop) rh_status_q | |
    Exit 0 $;;
    Restart|configtest) \ n; Reload) Rh_status_q | |
    Exit 7 $;;
    Force-reload) force_reload;;
    status) Rh_status;; Condrestart|try-restart) rh_status_q | |
    Exit 0;; *) echo $ "Usage: $ start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" ex It 2 Esac

6. Packaging (packaging process is actually to compile the installation of our files, directory packaging,/data/scripts/is the packaging working directory)
# Copy the Nginx startup script and the attention configuration and startup files to the package directory

Mkdir-p/data/scripts/etc/rc.d/init.d
cp/etc/init.d/nginx/data/scripts/etc/rc.d/init.d/

mkdir-p/data/ scripts/usr/local/nginx/
cp-r/usr/local/nginx//data/scripts/usr/local/nginx/

#/DATA/SCRIPTS directory Structure
[Root@master scripts]# Tree

.
├──after_remove.sh
├──etc
│   └──rc.d
│   └──init.d
│   └──nginx
├── nginx-1.12.0-1.el6.x86_64.rpm
├──nginx_post_install.sh
└──usr
└──local
└──nginx
├── Client_body_temp
├──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
│   └──win-utf
├──etc
│   └──rc.d
│   └── INIT.D
│   └──nginx
├──fastcgi_temp
├──html
│   ├──50x.html
│   └── index.html
├──logs
│   ├──access.log
│   ├──error.log
│   └──nginx.pid
├── Proxy_temp
├──sbin
│   └──nginx
├──scgi_temp
└──uwsgi_temp


# packaged, ready-to-prepare files packaged into rpm

# fpm-f-S dir-t rpm-n nginx--epoch 0-v 1.12.0--iteration 1.el6-c/data/scripts/-d ' Pcre-devel,openssl-devel,autoc Onf,glib-devel '--post-uninstall/data/scripts/nginx_post_install.sh--post-uninstall/data/scripts/after_ remove.sh--workdir/data/scripts/etc usr


Created Package {:p ath=> "nginx-1.12.0-1.el6.x86_64.rpm"}

Error:
Need executable ' rpmbuild ' to convert dir to rpm {: Level=>:error}

Solve:
Yum Install Rpm-build-y

Note: We can modify the host name before the operation, so that the packaged build host will change.

7. Install the RPM package

Yum command to install RPM packages

Yum-y Localinstall nginx-1.12.0-1.x86_64.rpm

This command automatically installs the RPM package dependencies before installing the RPM package.

 fpm Common parameters:-F: Forced override [overwrite RPM package]-N: Specified RPM package name-P: Specified RPM package file drop Location-V: Specified RPM package version-D: Specifies dependent software ([-d ' name '] or [-d ' names &G T 
Version '] Example:-d ' libstdc++ >= 4.4.3 ')-A: Specifies the system architecture, if Noarch is '-a all ' or '-a native ' [x86_64] when the software does not distinguish between 64-bit or 32-bit can be noarch -S: Specifies the data type of input (["-S Dir"] omitting data type)-M: Specifies the Packager [packager] ([-M ' user '])-C: Specifies the relative path of the package, similar to BuildRoot. For example,-c/tmp/apr/the packet path of the packaged machine is/tmp/apr/{opt,usr,etc} after installing this RPM package, the local data is/opt/,/usr/,/etc/-T: Specify what package you need to make, options available (deb,rpm, SOLARIS,ETC) Supported source types:: "dir" "rpm" "Gem" "Python" "Empty" "Tar" "Deb" "Cpan" "NPM" "osxpkg" "Pear" "Pkgin" "vir Tualenv "Zip" supported target types: "RPM" "Deb" "Solaris" "Puppet" "dir" "Osxpkg" "p5p" "puppet" "Sh" "Solaris" "Tar" "zip "--description: Package Description--conflicts: Specify conflict software--url: Specify site [Convention is the official website for adding software for example:--url" http://www.c Nblog.com/roach57 "]--verbose: Installation process verbose print--after-instal 

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.