FPM打包工具使用
author:headsen chen
date: 2019-01-19 14:57:09
个人原创博客,转自请注明出处和作者,否则追究法律责任
1,安装依赖和语言包
yum -y install ruby rubygems ruby-devel gcc
2,添加阿里云的Rubygems仓库,外国的源慢
gem sources -a http://mirrors.aliyun.com/rubygems/
3,移除原生的Ruby仓库
gem sources --remove http://rubygems.org/
4,安装fpm
gem install fpm
此时报错:
[root@ops-rpmbuild01 ~]# gem install fpm Building native extensions. This could take a while... Building native extensions. This could take a while... ERROR: Error installing fpm: ruby-xz requires Ruby version >= 1.9.3.
5,解决办法是 先安装rvm,再把ruby版本提升至2.3.3
yum -y install curl
curl -L get.rvm.io | bash -s stable
curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
再次运行:
curl -L get.rvm.io | bash -s stable
source /usr/local/rvm/scripts/rvm
检测rvm是否安装成功:
rvm -v
![](https://img2018.cnblogs.com/blog/1220594/201901/1220594-20190119151454828-1082206620.png)
安装一个版本的ruby
rvm install 2.2.3
设置一个默认的ruby版本
rvm use 2.3.3
ruby --version
![](https://img2018.cnblogs.com/blog/1220594/201901/1220594-20190119152300682-220848330.png)
6,再次安装fpm
gem install fpm
7,fpm的参数
# fpm -h #查看命令的帮助,下面对常用的参数进行简单的说明 # -s:指定源类型 # -t:指定目标类型 # -n:指定名字 # -v:指定版本号 # -C:指定打包的相对路径 # -d:指定依赖于哪些包 # -f:第二次打包时目录下如果有同名安装包存在,则覆盖它 # -p:输出的安装包的目录,不想放在当前目录下就需要指定 # --post-install 软件包安装完成之后所要运行的脚本;同--after-install # --pre-install 软件包安装完成之前所要运行的脚本;同--before-install
8,通过源码包安装Nginx并 启动
yum install -y pcre-devel openssl-devel rpm -qa pcre-devel openssl-devel mkdir -p /home/oldboy/tools cd /home/oldboy/tools wget -q http://nginx.org/download/nginx-1.10.2.tar.gz tar fx nginx-1.10.2.tar.gz cd nginx-1.10.2 useradd www ./configure --user=www --group=www --prefix=/application/nginx-1.10.2 --with-http_stub_status_module --with-http_ssl_module make && make install ln -s /application/nginx-1.10.2 /application/nginx /application/nginx/sbin/nginx lsof -i:80
9,fpm打包实例
[root@localhost mnt]# fpm -s dir -t rpm -n nginx -v 1.0.0.2 -C /application/nginx-1.10.2 -f Created package {:path=>"nginx-1.0.0.2-1.x86_64.rpm"} [root@localhost mnt]# ls install_after.sh nginx nginx-1.0.0.2-1.x86_64.rpm remove_after.sh