定制rpm包

来源:互联网 发布:木子软件 官网 编辑:程序博客网 时间:2024/05/16 10:23

1. 安装软件的方式

2017年9月16日 15:01:50   by:wentao

编译安装

优点:
  • 可以定制安装目录
  • 可以按需开启功能
  • 可以定制,不需要网络,可以选择软件版本
缺点:
  • 需要合适的编译参数
  • MySQL,PHP编译时间过长
  • 慢,复杂

yum安装方式

优点:
  • 全自动化安装
  • 简单,便捷
  • 不需要依赖,自动解决依赖问题
缺点:
  • 自主性太差
  • 需要网络,网络不好下载不了
  • 没办法定制软件功能,存放位置固定。存放在系统的各个目录

二进制安装方式

优点:
  • 简单,快
缺点:
  • 不能定制,包容量大

2. fpm打包工具

 支持的源类型,可以从什么类型打包。
 
dir         将目录打包成所需要的类型,可以用于源码编译安装的软件包
rpm         对rpm进行转换
gem         对rubygem包进行转换
python      将python模块打包成相应的类型
支持的目标类型
 
rpm         转换为rpm包
deb         转换为deb包
solaris     转换为solaris包
puppet      转换为puppet模块

3. 安装fpm

 
fpm是ruby写的,因此系统环境需要ruby,且ruby版本号大于1.8.5。
# 安装ruby模块
yum -y install ruby rubygems ruby-devel
# 查看当前使用的rubygems仓库
gem sources list
# 添加淘宝的Rubygems仓库,外国的源慢,移除原生的Ruby仓库
gem sources --add http://gems.ruby-china.org --remove http://rubygems.org/
# 安装fpm,gem从rubygem仓库安装软件类似yum从yum仓库安装软件。首先安装低版本的json,高版本的json需要ruby2.0以上,然后安装低版本的fpm,够用。
gem install json -v 1.8.3
gem install fpm -v 1.3.3
# 上面的2步安装仅适合CentOS6系统,CentOS7系统一步搞定,即gem install fpm
查看版本号
 
[root@web03 ~]# fpm --help
Intro:
  This is fpm version 1.3.3
....
常用参数:
 
-s          指定源类型
-t          指定目标类型,即想要制作为什么包
-n          指定包的名字
-v          指定包的版本号
-C          指定打包的相对路径  Change directory to here before searching forfiles
-d          指定依赖于哪些包
-f          第二次打包时目录下如果有同名安装包存在,则覆盖它
-p          输出的安装包的目录,不想放在当前目录下就需要指定
--post-install      软件包安装完成之后所要运行的脚本;同--after-install
--pre-install       软件包安装完成之前所要运行的脚本;同--before-install
--post-uninstall    软件包卸载完成之后所要运行的脚本;同--after-remove
--pre-uninstall     软件包卸载完成之前所要运行的脚本;同--before-remove

定制nginx软件包

正常编译安装nginx
 
#!/bin/bash
useradd  -M -u 909 -s /sbin/nologin www
ln -s /application/nginx-1.10.3/ /application/nginx
 
[root@web03 scripts]# fpm -s dir -t rpm -n nginx -v 1.10.3 -d 'pcre-devel,openssl-devel' --post-install /server/scripts/nginx_rpm.sh -f /application/nginx-1.10.3/


定制PHP安装包


 
./configure --prefix=/application/php-5.5.32 --with-mysql=mysqlnd --with-pdo-mysql=mysqlnd  --with-iconv-dir=/usr/local/libiconv  --with-freetype-dir --with-jpeg-dir --with-png-dir   --with-zlib  --with-libxml-dir=/usr  --enable-xml  --disable-rpath  --enable-bcmath  --enable-shmop  --enable-sysvsem  --enable-inline-optimization  --with-curl  --enable-mbregex  --enable-fpm  --enable-mbstring  --with-mcrypt  --with-gd  --enable-gd-native-ttf  --with-openssl  --with-mhash  --enable-pcntl   --enable-sockets   --with-xmlrpc  --enable-soap  --enable-short-tags  --enable-static  --with-xsl  --with-fpm-user=www  --with-fpm-group=www --enable-ftp --enable-opcache=no^C

定制sersync安装包

解压sersync.zip
 
 unzip sersync_installdir_64bit.zip 
将软件移动到/usr/local
 
 mv sersync_installdir_64bit/sersync  /usr/local
修改sersync的执行权限
 
chmod u+x /usr/local/sersync/bin/sersync
编辑安装脚本/server/scripts/sersync_install.sh 
 
#!/bin/bash
#date: 2017/09/19
#author: wen
chkconfig --add sersyncd
chkconfig --level 3 sersyncd on
编辑服务管理脚本:/etc/init.d/sersyncd
 
 #/bin/bash
#date: 2017/09/18  23:56
#author: wen
#des: sersync start 
#chkconfig: 235 57 89
. /etc/init.d/functions
if [ $# -ne 1 ];then
    echo "Usage:$0 {start|stop|restart|status}"
    exit 2
fi
message (){
if [ $? -eq 0 ];then
    action  "$message"      /bin/true
else
    action  "$message  "      /bin/false
fi
}
start () {
    /usr/local/sersync/bin/sersync -dro /usr/local/sersync/conf/confxml.xml &> /dev/null
    serpid=$(pidof sersync)
    echo $serpid >/var/run/sersync.pid
    message="sersync is runing"
}
stop() {
    message="sersync is stop"
    kill -9 $(cat /var/run/sersync.pid)
}
restart (){
    message="sersync is restart"
    stop
    sleep 2
    start
}
stat () {
   if [`ps -ef|grep sersync|wc -l` -lt 2 ];then
        echo "sersync is running"
   else
        echo "sersync is stopping"
   fi
}
case $1 in
start)
    start
    message;;
stop)
    stop
    message;;
restart)
    restart
    message;;
status)
    stat
    message;;
*)
    echo "Usage:$0 {stop|start|restart|status}"
esac
对管理sersync服务脚本授权:
 
chmod u+x /etc/init.d/sersync
打成rpm包
 
fpm -s dir -t rpm -n sersync -v 1.1 -d 'inotify-tools' --post-install /server/scripts/sersync_install.sh -f /usr/local/sersync /etc/init.d/sersyncd 



原创粉丝点击