第 1 章 rpm 包的制作
1.1 fpm 的概念介绍
FPM 功能简单说就是将一种类型的包转换成另一种类型
1.1.1. 支持的源类型
类型 | 说明 |
dir?? | 将目录打包成所需要的类型,可以用于源码编译安装的软件包 |
rpm?? | 对 rpm 进行转换 |
gem?? | 对 rubygem 包进行转换 |
python | 将 python 模块打包成相应的类型 |
1.1.2 支持的目标类型包
类型 | 说明 |
rpm??? | 转换为 rpm 包 |
deb??? | 转换为 deb 包 |
solaris | 转换为 solaris 包 |
puppet | 转换为 puppet 模块 |
1.2 fpm 的安装与使用
1.2.1 1.4.1? 安装 FPM 工具
fpm 是 Ruby 写的, 因此系统环境需要 Ruby, 且 Ruby 版本号大于 1.8.5
1.2.1.1 安装环境 Ruby
- [[email protected] SOURCES] # yum -y install Ruby RubyGems Ruby-devel
- [[email protected] SOURCES] # [[email protected] ~]# rpm -qa Ruby RubyGems Ruby-devel
1.2.2 查看当前使用的 Ruby 仓库
- [[email protected] SOURCES] # Gem sources list
- *** CURRENT SOURCES ***
- ?
- https://rubygems.org/
1.2.2.1 由于是外国源, 下载比较慢, 所以更新为阿里云
[[email protected] SOURCES] # Gem sources -a http://mirrors.aliyun.com/rubygems/
1.2.3 安装 fpm,Gem 从 rubygem 仓库安装软件类似 yum 从 yum 仓库安装软件. 首先安装低版本的 JSON, 高版本的 JSON 需要 ruby2.0 以上, 然后安装低版本的 fpm, 够用.
- [[email protected] SOURCES] # Gem install JSON -v 1.8.3
- [[email protected] SOURCES] # Gem install fpm -v 1.3.3
注意: 如果是 centos7, 可以使用 Gem install fpm
1.3 fpm 工具 rpm 包制作 nginx 服务 (Redis,PHP,MySQL 都是可以使用的)
1.3.1 下载安装包
[[email protected] sbin] # wget http://nginx.org/download/nginx-1.16.1.tar.gz
1.3.2 下载 nginx 所需要的依赖软件
[[email protected] SOURCES] # yum install -y pcre-devel openssl-devel
1.3.3 解压软件程序 进入到软件源码目录编译安装
- [[email protected] tools] # tar xf nginx-1.16.1.tar.gz
- [[email protected] tools] # cd nginx-1.16.1/
- [[email protected] nginx-1.16.1] # ./configure --prefix=/application/nginx-1.16.1 --with-http_ssl_module --with-http_stub_status_module
- [[email protected] nginx-1.16.1] # make && make install
- [[email protected] nginx-1.16.1] # ln -s /application/nginx-1.16.1 /application/nginx
1.3.4 编辑脚本文件
- [[email protected] scripts] # cat /server/scripts/nginx_post_install.sh
- #!/bin/bash
- useradd nginx -M -s /sbin/nologin
- ln -s /application/nginx/sbin/*/usr/local/sbin/
- ln -sf /application/nginx-1.16.1 /application/nginx
- [[email protected] scripts] #
1.3.5 制作 rpm 包
[[email protected] scripts] # fpm -s dir -t rpm -n nginx -v 1.16.1 -d 'pcre-devel,openssl-devel' --post-install /server/scripts/nginx_post_install.sh -f /application/nginx-1.16.1/
1.3.5.1 fpm 包制作的参数解析
参数 | 参数说明 |
-s | 指定源类型 |
-t | 指定目标类型,即想要制作为什么包 |
-n | 指定包的名字 |
-v | 指定包的版本号 |
-C | 指定打包的相对路径? |
-d | 指定依赖于哪些包 |
-f | 第二次打包时目录下如果有同名安装包存在,则覆盖它 |
-p | 输出的安装包的目录,不想放在当前目录下就需要指定 |
--post-install? | 软件包安装完成之后所要运行的脚本;同 --after-install |
--pre-install?? | 软件包安装完成之前所要运行的脚本;同 --before-install |
--post-uninstall | 软件包卸载完成之后所要运行的脚本;同 --after-remove |
--pre-uninstall | 软件包卸载完成之前所要运行的脚本;同 --before-remove |
1.4 测试安装包是否正常
1.4.1 将安装包通过 scp 发送到其他服务器上
[[email protected] scripts] # scp -r nginx-1.16.1-1.x86_64.rpm 172.16.1.51:/root/
1.4.2 在 172.16.1.51 服务器上开始安装使用
1.4.2.1 首先查看 nginx 发现版本是多少
- [[email protected] ~] # nginx -V???????????????????? 发现没有 nginx 服务
- -bash: /usr/local/sbin/nginx: No such file or directory
- [[email protected] ~] #
1.4.3 安装 nginx
[[email protected] ~] # yum -y install nginx-1.16.1-1.x86_64.rpm
1.4.3.1 查看 nginx 服务是否正常
- [[email protected] ~] # nginx -V
- nginx version: nginx/1.16.1
- built by gcc 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
- built with OpenSSL 1.0.2k-fips 26 Jan 2017
- TLS SNI support enabled
- configure arguments: --prefix=/application/nginx-1.16.1 --with-http_ssl_module --with-http_stub_status_module
1.4.3.2 nginx 服务是否能正常打开
- [[email protected] ~] # /application/nginx/sbin/nginx
- [[email protected] ~] # ps -ef | grep nginx
- root 6219 1 0 22:27 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
- nobody 6220 6219 0 22:27 ? 00:00:00 nginx: worker process
- root 6222 5047 0 22:27 pts/1 00:00:00 grep --color=auto nginx
1.4.3.3 web 网站是否能打开
1.5 rpm 包的查看
- [[email protected] ~] #rpm2cpio nginx-1.16.1-1.x86_64.rpm | cpio -div
- ./application/nginx-1.16.1/conf/fastcgi.conf
- ./application/nginx-1.16.1/conf/fastcgi.conf.default
- ./application/nginx-1.16.1/conf/fastcgi_params
- ./application/nginx-1.16.1/conf/fastcgi_params.default
- ./application/nginx-1.16.1/conf/koi-utf
- ./application/nginx-1.16.1/conf/koi-win
- ./application/nginx-1.16.1/conf/mime.types
- ./application/nginx-1.16.1/conf/mime.types.default
- ./application/nginx-1.16.1/conf/nginx.conf
- ./application/nginx-1.16.1/conf/nginx.conf.default
- ./application/nginx-1.16.1/conf/scgi_params
- ./application/nginx-1.16.1/conf/scgi_params.default
- ./application/nginx-1.16.1/conf/uwsgi_params
- ./application/nginx-1.16.1/conf/uwsgi_params.default
- ./application/nginx-1.16.1/conf/win-utf
- ./application/nginx-1.16.1/html/50x.HTML
- ./application/nginx-1.16.1/HTML/index.HTML
- ./application/nginx-1.16.1/logs
- ./application/nginx-1.16.1/sbin/nginx
- 11643 blocks
来源: http://www.bubuko.com/infodetail-3333602.html