• RPM打包


    经常需要把一些脚本打包到rpm包中去,安装rpm后能把脚本复制到指定位置。

    这个东西写完就忘了,在这里记一下
    在rhel5里SPECS和SOURCES目录在/usr/src/redhat/下,rhel6里需要自己创建。

    yum -y install rpm-build
    mkdir -p /root/rpmbuilder/{SPECS,SOURCES}
    

    把源码包放到SOURCES目录里,在SPECS里建立一个.spec文件。
    例如:

    
    Name:   hpcweb
    Version:        1.0
    Release:        1
    Summary:this is a hpcweb test rpm!          #这些是这个rpm包的信息,rpm -qi hpcweb 可以查看到
    
    Group:  CSVT
    License:GPL
    URL:    http://www.csvt.net
    Source0: %{name}-%{version}.tar.gz          #这里必须要源码包名字匹配,例如:hpcweb-1.0.tar.gz
    BuildRoot:      /var/tmp/%{name}-buildroot  #安装或编译的临时目录
    
    %description                                #rpm包描述信息
    Installs /etc/init.d/
    Installs /usr/sbin/
    
    %prep                                       #预处理脚本,建立软件所需要的目录
    %setup -q -n %{name}-%{version}
    
    %build                                      #开始构建一个包
    echo OK!
    
    %install                                    #类似make install的意思
    rm -rf $RPM_BUILD_ROOT
    mkdir -p $RPM_BUILD_ROOT/hpcweb             #建立/root/rpmbuild/BUILDROOT/hpcweb
    install -m 755 %{SOURCE0} $RPM_BUILD_ROOT/hpcweb # %{SOURCE0}等于源码包,就是把源码包解压到/root/rpmbuild/BUILDROOT/hpcweb/下。
    
    %clean                                      #清理临时文件
    [ "$PRM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT
    
    %post                                       #定义安装完包所执行的命令
    cd /hpcweb
    tar zxvf hpcweb-1.0.tar.gz
    cp hpcweb-1.0/init.d/* /etc/init.d/
    cp hpcweb-1.0/sbin/* /usr/sbin/
    mkdir /etc/hpcweb/
    cp hpcweb-1.0/conf/* /etc/hpcweb/
    for i in nodedatacollect  nodedataredis  pym_client  pym_server  webredis; do mkdir /var/run/$i > /dev/null 2>&1; mkdir /var/lock/$i > /dev/null 2>&1; done
    
    %preun                                      #卸载rpm包后相应的操作
    
    for i in nodedatacollect  nodedataredis  pym_client  pym_server  webredis; do rm -fr /var/run/$i; rm -fr /var/lock/$i; rm -f /etc/init.d/$i; rm -f /usr/sbin/$i; rm -fr /etc/hpcweb/;done
    
    %files                                      #定义哪些文件或目录会放入rpm包中
    %defattr(-,root,root,-)
    %dir /hpcweb/*                              #把/hpcweb/放入到了rpm中
    %doc
    
    %changelog
    

    生成rpm包

    rpmbuild -ba /root/rpmbuild/SPECS/hpcweb.spec
    

    生成的rpm包在/root/rpmbuild/RPMS/中

  • 相关阅读:
    top、ps -ef、ps aux的区别及内容详解
    img2pdf 报 img2pdf.AlphaChannelError: Refusing to work on images with alpha channel 的解决方案
    Scrapy命令行调用传入自定义参数
    查询Linux CPU架构
    LeetCode 216. 组合总和 III | Python
    LeetCode 40. 组合总和 II | Python
    LeetCode 39. 组合总和 | Python
    LeetCode 77. 组合 | Python
    LeetCode 347. 前 K 个高频元素 | Python
    LeetCode 107. 二叉树的层次遍历 II | Python
  • 原文地址:https://www.cnblogs.com/baoyiluo/p/2866095.html
Copyright © 2020-2023  润新知