dir: 将目录打包成所需要的类型,可以用于源码编译安装的软件包
rpm: 对rpm进行转换
gem: 对rubygem包进行转换
python: 将Python模块打包成相应的类型
rpm: 转换为rpm包
deb: 转换为deb包
solaris: 转换为solaris包
puppet: 转换为puppet包
-s:指定源类型
-t:指定目标类型,即想要制作为什么包
-n:指定包的名字
-v:指定包的版本号
-C:指定打包的相对路径
-d:指定依赖于哪些包
-f:第二次包时目录下如果有同名安装包存在,则覆盖它;
-p:制作的rpm安装包存放路径,不想放在当前目录下就需要指定;
--post-install:软件包安装完成之后所要运行的脚本;同--offer-install
--pre-install:软件包安装完成之前所要运行的脚本;同--before-install
--post-uninstall:软件包卸载完成之后所要运行的脚本;同--offer-remove
--pre-uninstall:软件包卸载完成之前所要运行的脚本;同—before-remove
--prefix:制作好的rpm包默认安装路径;
安装FPM:
环境:centos7.2.1511
# fpm是由ruby完成,所以需要ruby环境 yum install -y ruby rubygems ruby-devel # 添加淘宝ruby源 gem sources -a http://ruby.taobao.org/ # 删除默认的ruby源 gem sources --remove # 安装fpm centos7为默认有gem centos7系统的话可能没有需要另行安装,请自行补脑 gem install fpm
测试打包一个nginx的rpm包来练手
# 创建一个单独的目录,干净 mkdir fpm && cd fpm # 下载一个nginx源码包 wget http://nginx.org/download/nginx-1.11.12.tar.gz # 正常的解压安装 tar zxf nginx-1.11.12.tar.gz cd nginx-1.11.12 # 中间为报错,缺少两个依赖包,这里先直接安装了 yum install -y pcre-devel openssl-devel ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module make && make install # 创建必要的配置文件及nginx启动文件脚本等 mkdir -p /usr/local/nginx/conf/vhosts # 在 /usr/local/nginx/conf/vhosts 添加一个虚拟主机test.conf echo /usr/local/nginx/conf/vhosts/test.conf # 在nginx.conf配置文件中的http段添加一行 include /usr/local/nginx/vhosts/*.conf
创建rpm包的执行脚本
mkdir scripts echo ‘ #!/bin/bash useradd nginx -M -s /sbin/nologin 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=/run/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/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 ln -s /usr/lib/systemd/system/nginx.service /etc/systemd/system/multi-user.target.wants/nginx.service ‘ > scripts/nginx_init.sh
打包生成rpm包
fpm -s dir -t rpm -n nginx -v 1.11.12 -d ‘pcre-devel,openssl-devel‘ --post-install /root/fpm/scripts/nginx_init.sh -f /usr/local/nginx -s 指定源的类型,此源为一个目录即/usr/local/nginx -t 指定目录类型,即想要制作什么包,有这些类型(rpm,deb,solaris,puppet) -n 指定生成的包的名字 -v 指定生成的包的版本号 -d 指定依赖于哪些包,在安装的时候,会先安装,注,需要有yum仓库源 -C 指定打包的相对路径(最好是绝对路径,这个参数一般不要使用,费劲) -p 指定生成后的rpm存放在的目录路径(不用会在执行fpm的本地生成) --post-install 指定rpm包安装之后所需要运行的脚本,最好是绝对路径 --pre-install 指定rpm包安装之前甩需要运行的脚本,最好是绝对路径 --post-uninstall 指定rpm包卸载之后所需要运行的脚本,最好是绝对路径 --pre-uninstall 指定rpm包卸载之前所需要运行的脚本,最好是绝对路径 # 此时本地目录下以生成一个rpm包 # 在别一外台机器上测试 yum install -y nginx-1.11.12.x86_64.rpm # 查看之前创建的文件是否还在 ls /usr/local/nginx/conf/vhosts test.conf # 使用systemctl启动 # 启动脚本是在打包脚本里配置的,安装完rpm包就会执行此脚本 systemctl start nginx systemctl status nginx
fpm打包相对比较简单明了
制作rpm包安装软件即省事又安心,这是想要做标准化基础的第一步;
自己维护安装包源的仓库,是运运维同学们的一个利器工具。
感谢制作者
本文出自 “浅浅的淡淡” 博客,请务必保留此出处http://cuixiang.blog.51cto.com/8204722/1910737
原文:http://cuixiang.blog.51cto.com/8204722/1910737