#软件信息
#FPM github :https://github.com/jordansissel/fpm
#FPM documentation :https://fpm.readthedocs.io/en/latest/
#FPM源类型与目标类型
Things that should work Sources: gem (even autodownloaded for you) python modules (autodownload for you) pear (also downloads for you) directories tar(.gz) archives rpm deb node packages (npm) pacman (ArchLinux) packages Targets: deb rpm solaris freebsd tar directories Mac OS X .pkg files (osxpkg) pacman (ArchLinux) packages
FPM常用参数:
-s 指定源类型
-t 指定目标类型
-n 指定包的名字
-v 指定包的版本号
-C 指定打包的相对路径
-d 指定依赖于哪些包
--url URI 给该包添加URL (default: "http://example.com/no-uri-given")
-f 第二次包时目录下如果有同名安装包存在,则覆盖它;
-p :制作的rpm安装包存放路径,不想放在当前目录下就需要指定;
--post-install FILE 软件包安装完成之后所要运行的脚本;
--pre-install FILE 软件包安装完成之前所要运行的脚本;
--post-uninstall FILE 软件包卸载完成之后所要运行的脚本;
--pre-uninstall FILE 软件包卸载完成之前所要运行的脚本;
--after-remove FILE 软件包卸载完成后要运行的脚本
--before-remove FILE 软件包卸载完成前要卸载的脚本
#安装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 -l *** CURRENT SOURCES *** http://gems.ruby-china.org/ [root@KVM_1 ~]# [root@KVM_1 ~]# gem install fpm [root@KVM_1 ~]# yum install -y rpm-build
#编译安装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.134 HTTP/1.1 200 OK Server: Nginx/1.13.0 Date: Wed, 10 May 2017 19:52:20 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Wed, 10 May 2017 19:50:48 GMT Connection: keep-alive ETag: "59136f18-264" Accept-Ranges: bytes [root@KVM_1 ~]# /usr/local/Nginx/sbin/Nginx -s quit
#编写软件包安装后要执行的命令的脚本
[root@KVM_1 ~]# cat /root/Nginx_init.sh #!/bin/bash useradd -s /sbin/nologin -M Nginx echo '[Unit] Description=Nginx - high performance web server Documentation=http://Nginx.org/en/docs/ After=network.target remote-fs.target nss-lookup.target [Service] Type=forking PIDFile=/usr/local/Nginx/logs/Nginx.pid ExecStartPre=/usr/local/Nginx/sbin/Nginx -t -c /usr/local/Nginx/conf/Nginx.conf ExecStart=/usr/local/Nginx/sbin/Nginx -c /usr/local/Nginx/conf/Nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s QUIT $MAINPID PrivateTmp=true [Install] WantedBy=multi-user.target ' > /usr/lib/systemd/system/Nginx.service [root@KVM_1 ~]#chmod +x /root/Nginx_init.sh
#打包rpm
[root@KVM_1 ~]# fpm -s dir -t rpm -n Nginx -v 1.13.0 -d 'pcre,pcre-devel,openssl,openssl-devel' --post-install /root/Nginx_init.sh -f /usr/local/Nginx #参数解释 -s 源类型 此处为 目录 -t 目标类型 此处为 rpm -n 软件包名 此处为 Nginx -v 版本号 此处为 1.13.0 -d 依赖包 此处为 pcre,pcre-devel,openssl,openssl-devel --post-install 安装软件包后要执行的脚本 此处为 /root/Nginx_init.sh -f 强制覆盖 /usr/local/Nginx 要被打包的目录 # #打包完成后会在当前目录生成 rpm包 [root@KVM_1 ~]# ls anaconda-ks.cfg Nginx-1.13.0.tar.gz Nginx_init.sh Nginx-1.13.0 Nginx-1.13.0-1.x86_64.rpm
#测试
[root@KVM_1 ~]# hostname KVM_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 ~]# hostname KVM_2 #配置YUM源 [root@KVM_2 ~]# cat /etc/yum.repos.d/local.repo [local] name=local baseurl=file:///media/ gpgcheck=0 enabled=1 [root@KVM_2 ~]# mount /dev/cdrom /mnt/ [root@KVM_2 ~]# cp /mnt/* /media/ [root@KVM_2 ~]# cd /media/ #更新YUM仓库 [root@KVM_2 media]# createrepo -v ./ [root@KVM_2 media]# yum makecache [root@KVM_2 media]# yum list | grep Nginx Nginx.x86_64 1.13.0-1 local pcp-pmda-Nginx.x86_64 3.10.6-2.el7 local #安装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 process May 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 ok May 11 04:00:07 KVM_2 Nginx[4679]: Nginx: configuration file /usr/local/Nginx/conf/Nginx.conf test is successful May 11 04:00:07 KVM_2 systemd[1]: Started Nginx - high performance web server. [root@KVM_2 media]# netstat -lntup | grep 80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 4684/Nginx: master [root@KVM_2 media]# curl -I 192.168.174.135 HTTP/1.1 200 OK Server: Nginx/1.13.0 Date: Wed, 10 May 2017 20:01:14 GMT Content-Type: text/html Content-Length: 612 Last-Modified: Wed, 10 May 2017 20:14:24 GMT Connection: keep-alive ETag: "591374a0-264" Accept-Ranges: bytes
#至此Nginx FPM 打包完成
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。