RPM包定制-实战
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了RPM包定制-实战相关的知识,希望对你有一定的参考价值。
Rpm-red hat包管理器
Rpm命令有五种基本功能;安装、卸载、升级、查询、验证
实战环境
[[email protected] ~]# cat /etc/redhat-release
CentOS release 6.7 (Final)
[[email protected] ~]# uname -r
2.6.32-573.el6.x86_64
[[email protected] ~]# getenforce
Disabled
[[email protected] ~]# /etc/init.d/iptables status
iptables:未运行防火墙。
###设置yum缓存#####
[[email protected] tools]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1 ?设置为1 yum后包保存下来/var/cache/yum/x86_64/6/base/packages/
######清空本机已经有的yum缓存
(find /var/cache/ -type f -name "*.rpm")
FPM常用参数
支持的源类型包
DIR 将目录打包成所需要的类型,可以用于源码编译的安装包.
RPM 对rpm进行转换
gem 对rubygem包进行转换.
python 将python模块打包成相应的类型
支持的目标类型包格式:
RPM 转换为RPM包
deb 转换为deb包
solaris 转换为solaris包
puppet 转换为puppet包
准备工作
安装FPM工具:
fpm是使用ruby语言编写的,因此系统环境需要ruby这个软件,并且版本号需要大于1.8.5
安装ruby模块
yum -y install ruby rubygems ruby-devel
- 安装ruby的模块,ruby模块需要大于1.8.5*
添加阿里云的rubygems仓库,移除原生的yum仓库
gem sources -a http://mirrors.aliyun.com/rubygems/ ##增加阿里云的仓库
gem sources --remove http://rubygems.org ##移除原有的仓库
安装FPM工具
gem install fpm -v 1.3.3
##指定安装1.3.3 版本,我们需求不大,只要能打包就足够了,没必要追求高版本
Fpm是ruby编写,因此系统吸引ruby且大于1.8.5
安装ruby
[[email protected] ~]# yum -y install ruby rubygems ruby-devel
安装fpm
[[email protected] ~]# gem sources -a http://mirrors.aliyun.com/rubygems/
http://mirrors.aliyun.com/rubygems/ added to sources
[[email protected] ~]# gem sources --remove http://rubygems.org/
http://rubygems.org/ removed from sources
报错信息
[[email protected] ~]# gem install fpm -v 1.3.3
ERROR: Error installing fpm:
json requires Ruby version >= 1.9.
[[email protected] ~]# ruby -v
ruby 1.8.7 (2013-06-27 patchlevel 374) [x86_64-linux]
遇到以上错误请先安装以下两个软件,然后继续安装fpm1.3.3:
[[email protected] ~]# gem install json -v 1.8.3
[[email protected] ~]# gem install ffi -v 1.9.18
再次安装fpm[[email protected] ~]# gem install fpm -v 1.3.3
实战-定制nginx的rpm包
[[email protected] ~]# cd /application/
[[email protected] application]# ll
[[email protected] application]# mkdir -p tools
Wget编译包
[[email protected] tools]# wget http://10.0.0.61/nginx-1.6.3.tar.gz
--2018-04-28 09:45:37-- http://10.0.0.61/nginx-1.6.3.tar.gz
正在连接 10.0.0.61:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:805253 (786K) [application/x-gzip]
正在保存至: “nginx-1.6.3.tar.gz”
100%[=====================================>] 805,253 --.-K/s in 0.08s
2018-04-28 09:45:42 (9.28 MB/s) - 已保存 “nginx-1.6.3.tar.gz” [805253/805253])
#####编译安装nginx (就安装我们上传的1.6.3版本)
yum -y install pcre-devel openssl-devel #安装必备的包
[[email protected] base]# find packages/ -type f -name "*rpm"
packages/krb5-devel-1.10.3-65.el6.x86_64.rpm
packages/libselinux-utils-2.0.94-7.el6.x86_64.rpm
packages/libss-1.41.12-23.el6.x86_64.rpm
packages/openssl-1.0.1e-57.el6.x86_64.rpm
packages/libselinux-devel-2.0.94-7.el6.x86_64.rpm
packages/libselinux-2.0.94-7.el6.x86_64.rpm
packages/zlib-devel-1.2.3-29.el6.x86_64.rpm
packages/libsepol-devel-2.0.41-4.el6.x86_64.rpm
packages/libcom_err-1.41.12-23.el6.x86_64.rpm
packages/keyutils-libs-devel-1.4-5.el6.x86_64.rpm
packages/krb5-libs-1.10.3-65.el6.x86_64.rpm
packages/pcre-devel-7.8-7.el6.x86_64.rpm
packages/e2fsprogs-1.41.12-23.el6.x86_64.rpm
packages/e2fsprogs-libs-1.41.12-23.el6.x86_64.rpm
packages/libcom_err-devel-1.41.12-23.el6.x86_64.rpm
packages/libkadm5-1.10.3-65.el6.x86_64.rpm
packages/openssl-devel-1.0.1e-57.el6.x86_64.rpm
将依赖包移动到空的目录下并打包
[[email protected] base]# find packages/ -type f -name "*rpm"|xargs cp -t /tmp/
[[email protected] ~]# cd /tmp/ && tar zcf nginx_yum.tar.gz *.rpm
编译安装nginx
[[email protected] tmp]# useradd nginx -M -s /sbin/nologin
[[email protected] tmp]# cd /application/tools/
[[email protected] tools]# tar xf nginx-1.6.3.tar.gz
[[email protected] tools]# cd nginx-1.6.3
[[email protected] nginx-1.6.3]# ./configure --prefix=/application/nginx-1.6.3 --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module
[[email protected] nginx-1.6.3]#make && make install
[[email protected] nginx-1.6.3]# ln -s /application/nginx-1.6.3/ /application/nginx
编写脚本
[[email protected] ~]# mkdir -p /server/scripts/
[[email protected] scripts]# vim nginx_rpm.sh
#!/bin/bash
useradd nginx -M -s /sbin/nologin
ln -s /application/nginx-1.6.3/ /application/nginx
* Fpm-打包**
fpm -s dir -t rpm -n nginx -v 1.6.3 -d ‘pcre-devel,openssl-devel‘ --post-install /server/scripts/nginx_rpm.sh -f /application/nginx-1.6.3
格式语法解释:
-s 指定目录源类型 –t 打包类型 rpm -n 包名称 –v 版本 –d ‘依赖包以逗号分隔多个’ --post-install 安装完程序后执行的脚本 -f 重名强制覆盖 ,可不带
整体类似tar 苹果+框
[[email protected] scripts]# fpm -s dir -t rpm -n nginx -v 1.6.3 -d ‘pcre-devel,openssl-devel‘ --post-install /server/scripts/nginx_rpm.sh -f /application/nginx-1.6.3
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created package {:path=>"nginx-1.6.3-1.x86_64.rpm"}
[[email protected] scripts]# sz nginx-1.6.3-1.x86_64.rpm
Fpm命令与rpmbuild命令关系
Fpm命令其实是对rpmbuild命令进行封装,其实底层还是rpmbuild命令,因此系统必须要有rpmbuild命令
查看rpm包信息
查看包内容:
[[email protected] scripts]# rpm -qpl nginx-1.6.3-1.x86_64.rpm
/application/nginx-1.6.3/conf/fastcgi.conf
/application/nginx-1.6.3/conf/fastcgi.conf.default
/application/nginx-1.6.3/conf/fastcgi_params
/application/nginx-1.6.3/conf/fastcgi_params.default
/application/nginx-1.6.3/conf/koi-utf
/application/nginx-1.6.3/conf/koi-win
/application/nginx-1.6.3/conf/mime.types
/application/nginx-1.6.3/conf/mime.types.default
/application/nginx-1.6.3/conf/nginx.conf
/application/nginx-1.6.3/conf/nginx.conf.default
/application/nginx-1.6.3/conf/scgi_params
/application/nginx-1.6.3/conf/scgi_params.default
/application/nginx-1.6.3/conf/uwsgi_params
/application/nginx-1.6.3/conf/uwsgi_params.default
/application/nginx-1.6.3/conf/win-utf
/application/nginx-1.6.3/html/50x.html
/application/nginx-1.6.3/html/index.html
/application/nginx-1.6.3/logs
/application/nginx-1.6.3/sbin/nginx
查看包依赖
[[email protected] scripts]# rpm -qpR nginx-1.6.3-1.x86_64.rpm
pcre-devel
openssl-devel
/bin/sh
rpmlib(PayloadFilesHavePrefix) <= 4.0-1
rpmlib(CompressedFileNames) <= 3.0.4-1
查看执行脚本,执行脚本不是以文件形式存在rpm中
[[email protected] scripts]# rpm -qp --scripts nginx-1.6.3-1.x86_64.rpm
postinstall scriptlet (using /bin/sh):
#!/bin/bash
useradd nginx -M -s /sbin/nologin
ln -s /application/nginx-1.6.3/ /application/nginx
- Fpm打包注意事项*
安装rpm包
上传两个包依赖tar包以及nginx的rpm包
[[email protected] tools]# ll -h
总用量 7.1M
-rw-r--r-- 1 root root 2.2M 4月 28 2018 nginx-1.6.3-1.x86_64.rpm
-rw-r--r-- 1 root root 5.0M 4月 28 2018 nginx_yum.tar.gz
[[email protected] tools]# pwd
/application/tools
安装报错处理
[[email protected] ~]# rpm -ivh nginx-1.6.3-1.x86_64.rpm
error: Failed dependencies:
pcre-devel is needed by nginx-1.6.3-1.x86_64
openssl-devel is needed by nginx-1.6.3-1.x86_64
解决办法:
1. yum 安装 这两个包
2. rpm -ivh openssl-devel-1.0.1e-42.e16.x86_64.rpm
rpm -ivh pcre-devel-7.8-7.e16.x86_64.rpm
以上是关于RPM包定制-实战的主要内容,如果未能解决你的问题,请参考以下文章