linux系统之rpm打包

系统环境:

[root@web01 ~]# cat /etc/redhat-release
CentOS release 5.9 (Final)
[root@web01 ~]# uname -a
Linux web01 2.6.18-348.el5 #1 SMP Tue Jan 8 17:53:53 EST 2013 x86_64 x86_64 x86_64 GNU/Linux
[root@web01 ~]# lsb_release
LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-ia32:printing-4.0-noarch

开始安装:

[root@web01 ~]# yum install -y gcc zlib zlib-devel
[root@web01 soft]# wget http://ruby.taobao.org/mirrors/ruby/ruby-1.8.7-p358.tar.gz
[root@web01 soft]# wget http://files.rubyforge.vm.bytemark.co.uk/rubygems/rubygems-1.8.24.tgz
[root@web01 soft]# wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
[root@web01 soft]# rpm -ivh epel-release-5-4.noarch.rpm
[root@web01 soft]# yum -y install rpm-build
[root@web01 soft]# tar xf ruby-1.8.7-p358.tar.gz
[root@web01 soft]# tar xf rubygems-1.8.24.tgz
[root@web01 soft]# cd ruby-1.8.7-p358
[root@web01 ruby-1.8.7-p358]# ./configure --enable-pthread
[root@web01 ruby-1.8.7-p358]# make && make install
[root@web01 ruby-1.8.7-p358]# cd ../rubygems-1.8.24
[root@web01 rubygems-1.8.24]# ruby setup.rb
[root@web01 rubygems-1.8.24]# cd ..
[root@web01 soft]# gem source -r http://rubygems.org/
[root@web01 soft]# gem source -a http://ruby.taobao.org/
[root@web01 soft]# gem sources -l
*** CURRENT SOURCES ***
http://ruby.taobao.org/
[root@web01 soft]# gem install fpm

创建rpm包

[root@web01 ~]# fpm -s dir  -t rpm -v 1.0 -n warii_mysql  /opt/mysql/
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created rpm {:path=>"warii_mysql-1.0-1.x86_64.rpm"}
[root@web01 ~]# fpm -s dir  -t rpm -v 1.0 -n warii_nginx  /opt/nginx/
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created rpm {:path=>"warii_nginx-1.0-1.x86_64.rpm"}
[root@web01 ~]# fpm -s dir  -t rpm -v 1.0 -n warii_php  /opt/php/
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created rpm {:path=>"warii_php-1.0-1.x86_64.rpm"}
[root@web01 ~]# fpm -s dir  -t rpm -v 1.0 -n warii_redis  /opt/redis/
no value for epoch is set, defaulting to nil {:level=>:warn}
no value for epoch is set, defaulting to nil {:level=>:warn}
Created rpm {:path=>"warii_redis-1.0-1.x86_64.rpm"}

为了给mysql安装后初始化数据库,我们可以使用如下脚本:

[root@web01 ~]# cat mysql_install_post-install.sh
#!/bin/bash
/usr/sbin/groupdel mysql >/dev/null 2>&1
/usr/sbin/userdel mysql >/dev/null 2>&1
/usr/sbin/groupadd mysql >/dev/null 2>&1
/usr/sbin/useradd -g mysql mysql >/dev/null 2>&1
/bin/rm -rf /opt/mysql/data/ >/dev/null 2>&1
chown -R mysql:mysql /opt/mysql/ >/dev/null 2>&1
cd /opt/mysql/
/opt/mysql/scripts/mysql_install_db --user=mysql >/dev/null 2>&1
sleep 5
rm -rf /etc/my.cnf
exit 0

然后再打包mysql

[root@web01 ~]# fpm -s dir  -t rpm -v 1.0 -n warii_mysql --post-install mysql_install_post-install.sh /opt/mysql/
[root@web02 ~]# rpm -ivh warii_mysql-1.0-1.x86_64.rpm
Preparing...                ########################################### [100%]
   1:warii_mysql            ########################################### [100%]
[root@web02 ~]# /etc/init.d/mysql start
Starting MySQL..                                           [  OK  ]

详细信息查看wiki

https://github.com/jordansissel/fpm/wiki
注意
gem包可以去http://rubygems.org/ 下载
arr-pm-0.0.8.gem  backports-2.6.2.gem  cabin-0.6.0.gem  clamp-0.3.1.gem  fpm-0.4.33.gem  json-1.7.7.gem  open4-1.3.0.gem
gem install --local


本文出自 “devops” 博客,谢绝转载!

linux系统之rpm打包,古老的榕树,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。