制作RPM包之FPM
大约 2 分钟
FPM工具
- 官网: https://github.com/jordansissel/fpm
- FPM-dockerfile: https://github.com/aosolao/FPM-dockerfile
安装ruby和gem
## 安装ruby环境和gem命令
yum -y install ruby rubygems ruby-devel rpm-build gcc
## 查看当前源
gem source list
## 添加国内源
gem sources --add http://mirrors.aliyun.com/rubygems/
#gem sources --add https://gems.ruby-china.com/ --remove https://rubygems.org/
## 移除国外源
gem sources --remove https://rubygems.org/
## 更新gem版本
gem update --system
FPM使用
## 安装FPM工具
gem install fpm
#gem install fpm -v 1.4.0
## 开启yum缓存
sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf
## fpm打包Nginx
fpm -s dir -t rpm -n nginx -v 1.6.1 -d 'pcre-devel,openssl-devel' --post-install /opt/nginx_rpm.sh -f /opt/nginx/
## fpm相对路径打包
fpm -s dir -t rpm -n opt -v 1.1.1.1 -d 'gcc,gcc+' -C ../opt/
## 使用fpm将生成包指定到/tmp下
fpm -s dir -t rpm -n ansible-v 1.1.1.1 -d 'gcc,gcc+' -f ansible-p /tmp/
## 制作RPM包
fpm -s dir -t $PACKAGE -f -n $NAME -v $VERSION -a $PACKAGE_ARCH \
--prefix=/ \
--after-install /scripts/after-install.sh \
--after-upgrade /scripts/after-upgrade.sh \
--before-remove /scripts/before-remove.sh \
--after-remove /scripts/after-remove.sh \
--config-files /etc --config-files /opt/cloudserver/etc \
--config-files /opt/cloudserver/openresty/nginx/conf \
--config-files /opt/cloudserver/app/cloud/conf \
--iteration $BUILD_NUMBER \
--license private \
--vendor "$URL" \
--maintainer "$URL" \
--description "$DESC" \
--url "$URL" $EXTRA_ARGS $DEPS \
$(ls -d {usr,etc,opt} 2>/dev/null)
使用docker制作
- Dockerfile 请见: https://github.com/aosolao/FPM-dockerfile
- 构建好的镜像请见: https://hub.docker.com/r/aosolao/fpm
docker run -d \
-v /fpm-build/ng:/fpm-build/ng \
-v /fpm-build/rpm:/fpm-build/rpm \
aosolao/fpm:v1 \
fpm -s dir \
-t rpm \
-n nginx-wangsu \
-v 1.16.0 \
--iteration 1.el7 \
-C /fpm-build/ng \
-p /fpm-build/rpm \
--description 'Wangsu Nginx rpm For Centos7' \
--url 'www.wangsucloud.com' \
-d 'jemalloc >= 3.5.0,glibc >= 2.16' \
-m 'laihehui<laihh@wangsu.com>' \
--post-install /fpm-build/ng/tmp/install_after.sh \
--post-uninstall /fpm-build/ng/tmp/remove_after.sh
查看rpm包信息
## 查看rpm执行的脚本
rpm -qp --scripts nginx-1.6.1-1.x86_64.rpm
## 查看rpm包的依赖
rpm -qpR nginx-1.6.1-1.x86_64.rpm
## 查看rpm包中的内容
rpm -qpl nginx-1.6.1-1.x86_64.rpm
F&Q安装遇到问题
1.Need executable 'rpmbuild' to convert dir to rpm {:level=>:error}
## 解决方法
yum install -y rpm-build
2.如果里面有gcc make
的错误
## 解决方法
yum install -y gcc