歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 簡單制作RPM二進包實例

簡單制作RPM二進包實例

日期:2017/2/28 15:33:52   编辑:Linux教程

有好多朋友問到怎麼制作rpm包,可不可把其它服務器上編譯好的軟件目錄復雜到其它服務器上直接應用等等。。。這裡做個簡單的介紹,高級復雜的不會。

此方法是通過編寫spec文件,使用rpmbuild來完成一個rpm的打包。

以nginx為例進行介紹

制作平台:CentOS 5.x X86_64

四步走:

第一步:建立目錄結構

mkdir /usr/src/RedHat/{SOURCES,SPECS,BUILD,RPMS,SRPMS} -p

相關目錄介紹:

  1. /usr/src/redhat/SOURCES #存放源代碼、補丁等文件
  2. /usr/src/redhat/SPECS #存放用於管理rpm制作進程的spec文件
  3. /usr/src/redhat/BUILD #解壓後的文件存放目錄
  4. /usr/src/redhat/RPMS #存放由rpmbuild制作好的二進制包
  5. /usr/src/redhat/SRPMS #存放由rpmbuild制作好的源碼包
第二步:把源碼包放在SOURCES目錄下 cd /usr/src/redhat/SOURCES wget http://nginx.org/download/nginx-1.2.0.tar.gz 第三步:生成nginx.spec文件
  1. cd /usr/src/redhat/SPECS
  2. cat nginx.spec
  3. #
  4. # spec file for nginx
  5. # Build 2012-07-17
  6. # By opsren
  7. #
  8. Summary: High performance web server
  9. Name: Nginx
  10. Version: 1.2
  11. Release: 0.el5.ngx
  12. License: 2-clause BSD-like license
  13. Group: Applications/Server
  14. Source: http://nginx.org/download/nginx-1.2.0.tar.gz
  15. URL: http://nginx.org
  16. Distribution: Centos/Redhat
  17. Packager: qiuzhijun <[email protected]>
  18. %description
  19. Nginx ("engine x") is a high performance HTTP and reverse proxy server, as well as a mail(IMAP/POP3/SMTP) proxy server.
  20. %prep
  21. tar zxf $RPM_SOURCE_DIR/nginx-1.2.0.tar.gz
  22. %build
  23. cd nginx-1.2.0
  24. ./configure --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-http_ssl_module --with-pcre --lock-path=/var/run/nginx.lock --pid-path=/var/run/nginx.pid
  25. make
  26. %install
  27. cd nginx-1.2.0
  28. make install
  29. %preun
  30. if [ -z "`ps aux | grep nginx | grep -v grep`" ];then
  31. pkill nginx >/dev/null
  32. exit 0
  33. fi
  34. %files
  35. /usr/local/webserver/nginx
第四步:RPM包制作 首先系統要安裝好必備的制作工具:gcc、rpmbuild等
  1. yum -y install gcc rpm-build pcre-devel
  2. cd /usr/src/redhat/SPECS/
  3. rpmbuild -bb nginx.spec
通過上面這條命令,會在/usr/src/redhat/RPMS/x86_64/下面生成nginx-1.2.0-1.el5.ngx.x86_64.rpm這個文件 -bb 這個選項就是制作二進制包(build binary package only from <specfile>) 對spec文件內容進行簡單說明: spec文件是制作rpm包的核心!
  1. 以#開頭的是注釋信息;
  2. Summary:對相關軟件進行簡單描述說明
  3. Name:定義rpm包的名稱
  4. Version:定義軟件的版本號
  5. Release:發行版本
  6. License:定義許可證
  7. Group:說明軟件屬於哪種應用類型
  8. Source:軟件源碼下載地址
  9. URL:軟件相關官方站點
  10. Distribution: 發行版系列
  11. Packager: 制作人的簡單信息
  12. %description:軟件詳細描述信息
  13. %prep:軟件編譯之前的處理
  14. %build:編譯軟件
  15. %install:安裝軟件
  16. %preun:定義卸載之前的動作
  17. %files:指定要打包的軟件包,這裡是/usr/local/webserver/nginx
對於更詳細的說明請參考官方資料:http://www.rpm.org/max-rpm/ch-rpm-inside.html 下面是apache的spec文件實例:
  1. #
  2. # spec file for apache
  3. # Build 2012-07-17
  4. # By opsren
  5. #
  6. Summary: High stability web server
  7. Name: Apache
  8. Version: 2.2
  9. Release: 22.el5
  10. License: 2-clause BSD-like license
  11. Group: Applications/Server
  12. Source: http://apache.etoak.com/httpd/httpd-2.2.22.tar.gz
  13. URL: http://apache.org
  14. Distribution: Centos/Redhat
  15. Packager: qiuzhijun <[email protected]>
  16. %description
  17. Apache is a first web server
  18. %prep
  19. tar zxf $RPM_SOURCE_DIR/httpd-2.2.22.tar.gz
  20. %build
  21. cd httpd-2.2.22
  22. ./configure --prefix=/usr/local/webserver/apache --enable-so --enable-deflate --enable-headers --enable-mods-shared=all --enable-rewrite
  23. make
  24. %install
  25. cd httpd-2.2.22
  26. make install
  27. %preun
  28. if [ -z "`ps aux | grep httpd | grep -v grep`" ];then
  29. pkill httpd >/dev/null
  30. exit 0
  31. fi
  32. %files
  33. /usr/local/webserver/apache
以後對於相同或類似平台可以到其它服務器上進行rpm安裝部署。 另外還有一種rpm打包的方法:rpm_create 這是一種新的打rpm的工具,不用spec語言,只需要會簡單的shell命令,即可完成打包操作,非常方便,結合了spec語言和checkinstall,相比spec方法要簡單很多! 官方站點:http://code.google.com/p/rpmcreate/ 下載站點:wget http://rpmcreate.googlecode.com/files/rpm_create-1.7.5-9.x86_64.rpm 大家可以去官方站點參考!
Copyright © Linux教程網 All Rights Reserved