Making rpm package by FPM
# Software Information
# FPM github: https://github.com/jordansissel/fpm
# FPM documentation: https://fpm.readthedocs.io/en/latest/
# FPM source and destination types
Things that should workSources:gem (even autodownloaded for you) python modules (autodownload for you) pear (also downloads for you) directoriestar (.gz) archivesrpmdebnode packages (npm) pacman (ArchLinux) packagesTargets:debrpmsolarisfreebsdtardirectoriesMac OS X.pkg files (osxpkg) pacman (ArchLinux) packages
Common parameters of FPM:
-s specifies the source type
-t specifies the target type
-n specify the name of the package
-v specifies the version number of the package
-C specifies the relative path of packaging
-d specifies which packages to depend on
-- url URI adds URL (default: "http://example.com/no-uri-given")) to the package
-f if an installation package with the same name exists in the directory of the second package, overwrite it
-p: the storage path of the produced rpm installation package. You need to specify it if you don't want to put it in the current directory.
-- script to run after post-install FILE package installation is complete
Script to run before the pre-install FILE package installation is complete
Script to run after the post-uninstall FILE package has been uninstalled
Script to run before the pre-uninstall FILE package is uninstalled
-- prefix: the default installation path for finished rpm packages
-- script to run after the after-remove FILE package is uninstalled
-- script to be uninstalled before the before-remove FILE package is uninstalled
# install FPM
[root@KVM_1 ~] # yum install-y ruby rubygems ruby-devel [root@KVM_1 ~] # gem sources-- add http://gems.ruby-china.org/-- remove https://gems.ruby-china.org/[root@KVM_1 ~] # gem sources-lump gem sources * CURRENT SOURCES * * http://gems.ruby-china.org/[root@KVM_1 ~] # [root@KVM_1 ~] # gem install fpm [root@KVM_1 ~] # yum install-y rpm-build
# compile and install Nginx
[root@KVM_1 ~] # wget http://mirrors.sohu.com/nginx/nginx-1.13.0.tar.gz[root@KVM_1 ~] # tar-xf nginx-1.13.0.tar.gz [root@KVM_1 ~] # cd nginx-1.13.0/ [root@KVM_1 nginx-1.13.0] # yum install-y pcre pcre-devel openssl openssl-devel gcc-c++ [root@KVM_1 nginx-1.13.0] # useradd -s / usr/sbin/nologin-M nginx [root @ KVM_1 nginx-1.13.0] #. / configure-- with-http_stub_status_module-- with-http_ssl_module-- prefix=/usr/local/nginx-- user=nginx-- group= nginx [root @ KVM_1 nginx-1.13.0] # make & & make install [root @ KVM_1 nginx-1.13.0] # CD [root @ KVM_1 ~] # / usr/local/nginx/sbin / nginx [root@KVM_1 ~] # curl-I 192.168.174.134HTTP/1.1 200 OKServer: nginx/1.13.0Date: Wed 10 May 2017 19:52:20 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Wed, 10 May 2017 19:50:48 GMTConnection: keep-aliveETag: "59136f18-2017" Accept-Ranges: Bytes [root @ KVM_1 ~] # / usr/local/nginx/sbin/nginx-s quit
# script the commands to be executed after the package is installed
[root@KVM_1 ~] # cat / root/nginx_init.sh #! / bin/bash useradd-s / sbin/nologin-M nginx echo'[Unit] Description=nginx-high performance web serverDocumentation= http://nginx.org/en/docs/After=network.target remote-fs.target nss-lookup.target [Service] Type=forkingPIDFile=/usr/local/nginx/logs/nginx.pidExecStartPre=/usr/local/nginx/sbin/nginx-t-c / usr/local/nginx/conf/nginx.confExecStart=/usr/local/nginx/sbin/ Nginx-c / usr/local/nginx/conf/nginx.confExecReload=/bin/kill-s HUP $MAINPIDExecStop=/bin/kill-s QUIT $MAINPIDPrivateTmp=true [Install] WantedBy=multi-user.target' > / usr/lib/systemd/system/nginx.ser vice [root @ KVM_1 ~] # chmod + x / root/nginx_init.sh
# package rpm
[root@KVM_1 ~] # fpm-s dir-t rpm-n nginx-v 1.13.0While d 'pcre,pcre-devel,openssl,openssl-devel'-- post-install / root/nginx_init.sh-f / usr/local/nginx# parameters explain-s source type here is directory-t target type here is rpm-n package name here is nginx-v version number here is 1.13.0While d dependency package here is pcre,pcre-devel Script to be executed after openssl,openssl-devel--post-install installs the package here is / root/nginx_init.sh-f forced overwrite / usr/local/nginx directory to be packaged # # after packaging is completed, the rpm package [root@KVM_1 ~] # lsanaconda-ks.cfg nginx-1.13.0.tar.gz nginx_init.sh nginx-1.13.0 nginx-1.13.0-1.x86_64.rpm will be generated in the current directory
# Test
[root@KVM_1 ~] # hostnameKVM_1 [root@KVM_1 ~] # scp nginx-1.13.0-1.x86_64.rpm 192.168.174.135:/media/ [root @ KVM_1 ~] # ssh 192.168.174.135 [root @ KVM_2 ~] # hostnameKVM_2# configure YUM source [root@KVM_2 ~] # cat / etc/yum.repos.d/local.repo [local] name=localbaseurl= file:///media/gpgcheck=0enabled=1[root@KVM_ 2 ~] # mount / dev/cdrom / mnt/ [root @ KVM_2 ~] # cp / mnt/* / media/ [root @ KVM_2 ~] # cd / media/# update YUM warehouse [root@KVM_2 media] # createrepo-v. / [root@KVM_2 media] # yum makecach [root @ KVM_2 media] # yum list | grep nginxnginx.x86_64 1.13.0-1 Local pcp-pmda-nginx.x86_64 3.10.6-2.el7 local # install nginx [root @ KVM_2 media] # yum install-y nginx [root @ KVM_2 media] # systemctl start nginx [root @ KVM_2 media] # systemctl status nginx ● nginx.service-nginx-high performance web server Loaded: loaded (/ usr/lib/systemd/system/nginx.service) Disabled; vendor preset: disabled) Active: active (running) since Thu 2017-05-11 04:00:07 CST 12s ago Docs: http://nginx.org/en/docs/ Process: 4681 ExecStart=/usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf (code=exited, status=0/SUCCESS) Process: 4679 ExecStartPre=/usr/local/nginx/sbin/nginx-t-c / usr/local/nginx/conf/nginx.conf (code=exited Status=0/SUCCESS) Main PID: 4684 (nginx) CGroup: / system.slice/nginx.service ├─ 4684 nginx: master process / usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf └─ 4685 nginx: worker processMay 11 04:00:07 KVM_2 systemd [1]: Starting nginx-high performance web server...May 11 04:00:07 KVM_2 nginx [4679]: nginx: the configuration file / usr/local/ Nginx/conf/nginx.conf syntax is okMay 11 04:00:07 KVM_2 nginx [4679]: nginx: configuration file / usr/local/nginx/conf/nginx.conf test is successfulMay 11 04:00:07 KVM_2 systemd [1]: Started nginx-high performance web server.[ root @ KVM_2 media] # netstat-lntup | grep 80tcp 00 0.0.0.0 nginx 80 0.0.0.0 * LISTEN 4684/nginx: master [root@KVM_2 media] # curl-I 192.168.174.135HTTP/1.1 200 OKServer: nginx/1.13.0Date: Wed 10 May 2017 20:01:14 GMTContent-Type: text/htmlContent-Length: 612Last-Modified: Wed, 10 May 2017 20:14:24 GMTConnection: keep-aliveETag: "591374a0-2017" Accept-Ranges: bytes
# so far, nginx FPM packaging is complete.