rpmバッグを一歩ずつ作る

14790 ワード

私达の企业の中であるソフトウェアは基本的にすべてコンパイルして、私达はインストールするたびにすべてコンパイルしなければならなくて本当にとてもいらいらして、それではどのようにしますか?では、私たちのニーズに合わせてRPMインストールパッケージを作成しましょう.まず基本的な布急についてお話しします.

  
  
  
  
  1. 1.Planning what you want              rpm 。 ? ? 
  2. 2.Gathering the software to package   ,  
  3. 3.Patch the software as need          , 。  
  4. 4.Outling any dependenies              
  5. ------------------     ------------------- 
  6. 5.Building RPMs                       RPM  
  7.     5.1 Set up the directory stucture  , RPM ,  
  8.         BUILD     
  9.         RPMS     RPM ,  
  10.         SOURCES  ,  
  11.         SPECS   SPEC  
  12.         SRMPS    SRMPS  
  13.     5.2 Place the Sources in the right directory     
  14.     5.3 Create a spec file that tell rpmbuild command what to do  spec , ,rpmbuild spec rpm  
  15.     5.4 Build the source and binary RPMS  src rpm  
  16. 6.Test RPMS  PRM  
  17. 7.Add signature for RPM   RPM  


私はやはり一貫した話で皆さんに述べましょう.まず、rpmパッケージを作る理由を確かにしましょう.通常、httpd、nginxなどのソフトウェアのために、これらのパッケージのソースコードを収集し、必要があればこれらのパッチファイルを収集し、手動でこのソフトウェアをコンパイルしてインストールします(もちろん、コンパイルする必要がなければ練習しなくてもいいです).依存するパッケージを特定して記録し、tengineのPRMパッケージを作成する準備を始めましょう.
1.rpmを作成するために普通のユーザーを設立し、rootを使用するとコードの問題によって破壊される可能性がある.

  
  
  
  
  1. useradd ibuler 
  2. su - ibuler 

2.どのディレクトリでRPMを作成するかを決定します.通常、このディレクトリはtopdirです.これはマクロプロファイルで指定する必要があります.このプロファイルはmacrofilesと呼ばれます.通常は/usr/lib/rpm/macros:/usr/lib/rpm/macros.*:~/.rpmmacrosです.これはrhel 5.8でrpmbuild--showrc|grep macrofiles 調べてみると、6.3の私はこれを使って見つけられませんが、使用は同じです.rpmbuild--showrc|grep topdirでシステムのデフォルトの作業場を表示できます. 

  
  
  
  
  1. rpmbuild --showrc | grep topdir 
  2.  
  3. -14: _builddir  %{_topdir}/BUILD 
  4. -14: _buildrootdir  %{_topdir}/BUILDROOT 
  5. -14: _rpmdir    %{_topdir}/RPMS 
  6. -14: _sourcedir %{_topdir}/SOURCES 
  7. -14: _specdir   %{_topdir}/SPECS 
  8. -14: _srcrpmdir %{_topdir}/SRPMS 
  9. -14: _topdir    %{getenv:HOME}/rpmbuild 

作業ディレクトリ(または職場)をカスタマイズしましょう

  
  
  
  
  1. vi ~/.rpmmacros 
  2. %_topdir        /home/ibuler/rpmbuild    ##  
  3.  
  4. mkdir ~/rpmbuild  

3.topdirで必要なディレクトリを作成する

  
  
  
  
  1. cd ~/rpmbuild  
  2. mkdir -pv {BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} 

4.収集したソースコードをSOURCESの下に置く

  
  
  
  
  1. cp /tmp/tengine-1.4.2.tar.gz SOURCES  ##

5.SPECSで重要なspecファイルを作成する

  
  
  
  
  1. cd SPECS 
  2. vi tengine.spec          ## ,rhel6.3  

6.rpmbuildコマンドでrpmパケットを作成します.rpmbuildコマンドはspecファイルに基づいてrpmパケットを生成します. 

  
  
  
  
  1. rpmbuild  
  2. -ba  src.rpm rpm 
  3. -bs  src rpm 
  4. -bb  rpm 
  5. -bp  pre 
  6. -bc   build  
  7. -bi  install  
  8. -bl   

一歩一歩試して、rpmbuild-bp、さらに-bc-bi大丈夫なら、rpmbuild-baはsrcパケットとバイナリパケットを生成しましょう.
7.インストールテストに問題があるかどうか、正常にインストールして運行できるかどうか、正常にアップグレードできるかどうか、アンインストールに問題があるかどうか
rootユーザーテストインストール:

  
  
  
  
  1. cd /tmp
  2. cp /home/ibuler/rpmbuild/RPMS/x86_64/tengine-1.4.2-1.el6.x86_64.rpm /tmp  
  3. rpm -ivh tengine-1.4.2-1.el6.x86_64.rpm  ##  
  4. rpm -e tengine                           ## , ,  

8.rpmパッケージに署名して問題がなければ、悪意のある変更を防ぐ   ##これは先に書かないで、少し遅くなったので、後で補充します.
これでプロセス全体が完了します.その中で最も重要なspecのフォーマットについてお話しします.まず、最も簡単で、最も実現しやすいものについてお話しします.

  
  
  
  
  1. vi tengine.spec 
  2.  
  3. ### 0.define section               # ,  
  4. ### %define nginx_user nginx       # , nginx_user nginx,%{nginx_user}  
  5.  
  6. ### 1.The introduction section      #  
  7.  
  8. Name:           tengine            # tar  
  9. Version:        1.4.2              # , tar  
  10. Release:        1%{?dist}          # , rpm 
  11. Summary:        tengine from TaoBao  # , 50  
  12.  
  13. Group:          System Environment/Daemons  # , less /usr/share/doc/rpm-4.8.0/GROUPS   
  14. License:        GPLv2                       # ,GPL BSD   
  15. URL:            http://laoguang.blog.51cto.com   #  
  16. Packager:       Laoguang <ibuler@qq.com> 
  17. Vendor:         TaoBao.com 
  18. Source0:        %{name}-%{version}.tar.gz   
  19. # source, , , ,  
  20. #patch0:            a.patch                 # ,  
  21. BuildRoot:      %_topdir/BUILDROOT         
  22. # make install  , , , ,
  23. # , file  
  24. BuildRequires:  gcc,make                           #  
  25. Requires:       pcre,pcre-devel,openssl,chkconfig  # ,  bash >= 1.1.1 
  26. %description                                       # ,  
  27. It is a Nginx from Taobao.                         #  
  28.  
  29. ###  2.The Prep section  , source cd  
  30.  
  31. %prep                                              #  
  32. %setup -q                                          # cd 
  33. # patch0 -p1                                       # ,  
  34.  
  35. ###  3.The Build Section  ,  
  36. %build 
  37. ./configure \                                      #./configure  %configure  
  38.   --prefix=/usr \                                  #  
  39.   --sbin-path=/usr/sbin/nginx \ 
  40.   --conf-path=/etc/nginx/nginx.conf \ 
  41.   --error-log-path=/var/log/nginx/error.log \ 
  42.   --http-log-path=/var/log/nginx/access.log \ 
  43.   --pid-path=/var/run/nginx/nginx.pid  \ 
  44.   --lock-path=/var/lock/nginx.lock \ 
  45.   --user=nginx \ 
  46.   --group=nginx \ 
  47.   --with-http_ssl_module \ 
  48.   --with-http_flv_module \ 
  49.   --with-http_stub_status_module \ 
  50.   --with-http_gzip_static_module \ 
  51.   --http-client-body-temp-path=/var/tmp/nginx/client/ \ 
  52.   --http-proxy-temp-path=/var/tmp/nginx/proxy/ \ 
  53.   --http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \ 
  54.   --http-uwsgi-temp-path=/var/tmp/nginx/uwsgi \ 
  55.   --http-scgi-temp-path=/var/tmp/nginx/scgi \ 
  56.   --with-pcre 
  57. make %{?_smp_mflags}          #make : make  
  58.  
  59. ###  4.Install section    
  60. %install                                
  61. rm -rf %{buildroot}                # ,  
  62. make install DESTDIR=%{buildroot} 
  63. #DESTDIR , ,%{buildroot}  
  64.  
  65. ###  4.1 scripts section #  
  66. %pre        #rpm  
  67. if [ $1 == 1 ];then    #$1==1  ,2 ,0  
  68.         /usr/sbin/useradd -r nginx 2> /dev/null 
  69. fi 
  70. %post       #  
  71.  
  72. %preun      #  
  73. if [ $1 == 0 ];then 
  74.         /usr/sbin/userdel -r nginx 2> /dev/null 
  75. fi 
  76. %postun     #  
  77.  
  78. ###  5.clean section  , buildroot 
  79.  
  80. %clean 
  81. rm -rf %{buildroot} 
  82.      
  83. ###  6.file section   
  84. %files  
  85. %defattr (-,root,root,0755)   # , ,  
  86. /etc/           # %{rootbuild} , ,       
  87. /usr/ 
  88. /var/ 
  89.      
  90. ###  7.chagelog section    
  91. %changelog 
  92. *  Fri Dec 29 2012 laoguang <ibuler@qq.com> - 1.0.14-1 
  93. - Initial version 

ここまでtengieのrmpができて、暇を見つけて続けて、今眠くなりました.寝ました.
 
この記事は、「Free Linux,Share Linux」ブログから掲載されています.http://laoguang.blog.51cto.com/6013350/1103628