关于FPM的介绍
https://docs.google.com/present/view?id=0Aa9liCTsAyzRZGNtd3dkOTRfMTdmczY2azlkcg&hl=en
FPM功能简单说就是将一种类型的包转换成另一种类型。
支持的源类型包:“dir”:将目录打包成所需要的类型,可以用于源码编译安装的软件包
“rpm”:对rpm进行转换
“gem”:对rubygem包进行转换
“python”:将python模块打包成相应的类型
支持的目标类型包:
“rpm”:转换为rpm包
“deb”:转换为deb包
“solaris”:转换为solaris包
“puppet”:转换为puppet模块
这里主要介绍如何将源码安装的包转换为RPM/DEB包,其他功能感兴趣的可以试试。
安装环境:
系统Centos6.5 64位,默认的ruby为1.8.7版本;
封装mysql5.6.29二进制安装包;
FPM安装
FPM的安装非常简单,安装FPM前需要先安装ruby,rubygem
# FPM是Ruby模块
yum -y install ruby rubygems ruby-devel
#移除原生的Ruby仓库, 添加淘宝的Ruby仓库:
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/
#查看系统默认的ruby源:
[root@localhost ruby-2.1.10]# gem sources -l *** CURRENT SOURCES *** http://rubygems.org/ https://gems.ruby-china.org/
#移除原生的Ruby仓库, 添加淘宝的Ruby仓库:
gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ [root@localhost ruby-2.1.10]# gem sources --remove http://rubygems.org/ http://rubygems.org/ removed from sources [root@localhost ruby-2.1.10]# gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.org/
#安装Fpm软件包
报错如下:
[root@localhost data]# 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.
#处理办法:卸载系统自带的ruby软件包版本:
yum remove ruby -y
ruby官网下载高于1.9.3的ruby软件包进行安装:
#安装编译软件gcc make
yum install gcc make -y
#编译安装三部曲:
tar zxf ruby-2.1.10.tar.gz ./configure --prefix=/usr/local/ruby2.1 make -j 4 && make install
#添加环境变量:
# cat /etc/profile.d/ruby2.1.sh export PATH=$PATH:/usr/local/ruby2.1/bin
#查看ruby版本:
[root@localhost ~]# source /etc/profile [root@localhost ~]# ruby -v ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-linux]
报错如下:
[root@localhost ruby-2.1.10]# gem install fpm -bash: /usr/bin/gem: No such file or directory
处理办法:安装依赖;
yum install rubygems
继续安装fpm报错如下:
# gem install fpm ERROR: While executing gem ... (Gem::Exception) Unable to require openssl, install OpenSSL and rebuild ruby (preferred) or use non-HTTPS sources
处理办法:安装依赖;
# yum install openssl #yum install rpm-build
当然看到这个报错的时候,第一反应openssl和rpmbuild库没装,yum install openssl rpm-build,发现报错依旧,紧接看网上的文档编译zlib,我当然没这么干。
再次安装依旧报错,处理办法:修改源:放弃https 使用http;
[root@localhost ~]# gem sources -a http://gems.ruby-china.org http://gems.ruby-china.org added to sources [root@localhost ~]# gem source --remove https://gems.ruby-china.org https://gems.ruby-china.org removed from sources [root@localhost ~]# gem source -l *** CURRENT SOURCES *** http://rubygems.org/ http://gems.ruby-china.org
#再次安装发现就没问题;这个安装很耗时,时间很久。
[root@localhost bin]# gem install fpm Fetching: archive-tar-minitar-0.5.2.gem (100%) Successfully installed archive-tar-minitar-0.5.2 Fetching: cabin-0.9.0.gem (100%) Successfully installed cabin-0.9.0 Fetching: arr-pm-0.0.10.gem (100%) Successfully installed arr-pm-0.0.10 Fetching: backports-3.6.8.gem (100%) Successfully installed backports-3.6.8 Fetching: ffi-1.9.18.gem (100%) Building native extensions. This could take a while... Successfully installed ffi-1.9.18 Fetching: childprocess-0.6.3.beta.1.gem (100%) Successfully installed childprocess-0.6.3.beta.1 Fetching: clamp-1.0.1.gem (100%) Successfully installed clamp-1.0.1 Fetching: dotenv-2.2.0.gem (100%) Successfully installed dotenv-2.2.0 Fetching: insist-1.0.0.gem (100%) Successfully installed insist-1.0.0 Fetching: mustache-0.99.8.gem (100%) Successfully installed mustache-0.99.8 Fetching: stud-0.0.22.gem (100%) Successfully installed stud-0.0.22 Fetching: pleaserun-0.0.28.gem (100%) Successfully installed pleaserun-0.0.28 Fetching: io-like-0.3.0.gem (100%) Successfully installed io-like-0.3.0 Fetching: ruby-xz-0.2.3.gem (100%) Successfully installed ruby-xz-0.2.3 Fetching: fpm-1.8.1.gem (100%) Successfully installed fpm-1.8.1 Parsing documentation for archive-tar-minitar-0.5.2 Installing ri documentation for archive-tar-minitar-0.5.2 Parsing documentation for arr-pm-0.0.10 Installing ri documentation for arr-pm-0.0.10 Parsing documentation for backports-3.6.8 Installing ri documentation for backports-3.6.8 Parsing documentation for cabin-0.9.0 Installing ri documentation for cabin-0.9.0 Parsing documentation for childprocess-0.6.3.beta.1 Installing ri documentation for childprocess-0.6.3.beta.1 Parsing documentation for clamp-1.0.1 Installing ri documentation for clamp-1.0.1 Parsing documentation for dotenv-2.2.0 Installing ri documentation for dotenv-2.2.0 Parsing documentation for ffi-1.9.18 Installing ri documentation for ffi-1.9.18 Parsing documentation for fpm-1.8.1 Installing ri documentation for fpm-1.8.1 Parsing documentation for insist-1.0.0 Installing ri documentation for insist-1.0.0 Parsing documentation for io-like-0.3.0 Installing ri documentation for io-like-0.3.0 Parsing documentation for mustache-0.99.8 Installing ri documentation for mustache-0.99.8 Parsing documentation for pleaserun-0.0.28 Installing ri documentation for pleaserun-0.0.28 Parsing documentation for ruby-xz-0.2.3 Installing ri documentation for ruby-xz-0.2.3 Parsing documentation for stud-0.0.22 Installing ri documentation for stud-0.0.22 Done installing documentation for archive-tar-minitar, arr-pm, backports, cabin, childprocess, clamp, dotenv, ffi, fpm, insist, io-like, mustache, pleaserun, ruby-xz, stud after 8 seconds 15 gems installed You have new mail in /var/spool/mail/root
二进制安装干净的Mysql环境,二进制安装速度很快:
#创建mysql数据存储目录
mkdir /data/mysqldata
#添加mysql用户和mysql组
groupadd -r mysql useradd -g mysql -r -s /sbin/nologin -M -d /data/mysqldata mysql chown -R mysql:mysql /data/mysqldata
#初始化Mysql安装Mysql:
#创建mysql启动脚本
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld chmod 777 /etc/init.d/mysqld
#修改/etc/init.d/mysqld内容,内容如下:
#basedir=/data/mysql #datadir=/data/mysqldata
#加入系统库核系统变量
ln -sv /data/mysql/include /usr/include/mysql echo '/data/mysql/lib' > /etc/ld.so.conf.d/mysql.conf ldconfig echo 'export PATH=/data/mysql/bin/:$PATH' > /etc/profile.d/mysql.sh source /etc/profile service mysqld start
如图,安装完成stopmysql服务,开始封装Mysql rpm包:
#开始封装Mysql Rpm包:
[root@localhost tmp]# fpm -s dir -t rpm -v 5.6.29 -n mysql --before-install /tmp/before.sh --after-install /tmp/after.sh --after-remove /tmp/remove.sh -d 'libaio' /data/mysql/ /data/mysqldata/ /etc/init.d/mysqld Created package {:path=>"mysql-5.6.29-1.x86_64.rpm"}
如图:
封装的时间较久
注意:运行脚本的参数一定要在封装目录之前,否则会报错的。
Fpm的参数选项:
-n 自定义软件包的名称
-C fpm去哪个目录搜寻文件
-v 生成的rpm包的版本
-d 生成的rpm包依赖什么软件,通常为-d 'name' 或者-d 'name > version'
-a 系统架构名称,如果是noarch则为'-a all'或者'-a native'
--description 软件包的描述
--conflicts 与其他什么软件包冲突n
-f 第二次打包时目录下如果有同名安装包存在,则覆盖它
-p 输出的安装包的目录,不想放在当前目录下就需要指定
--post-install 软件包安装完成之后所要运行的脚本;同--after-install
--pre-install 软件包安装完成之前所要运行的脚本;同--before-install
--post-uninstall 软件包卸载完成之后所要运行的脚本;同--after-remove
--pre-uninstall 软件包卸载完成之前所要运行的脚本;同--before-remove
#安装之前的要执行的脚本:
#安装之后要执行的脚本:
#卸载Rpm包后要执行的脚本:
#cpoy到一台全新的机器测试:
到此封装制作完成,感兴趣的朋友可以自己动手尝试下。