自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

如何在CentOS/RedHat下,實現(xiàn)根據源碼包創(chuàng)建rpm包

系統(tǒng) Linux
有時你可能需要獲取一個開源應用的源碼包,但是可能沒有無法通過該應用的RPM文件來安裝到系統(tǒng)。在這種情況下,你既可以編譯源碼安裝,也可以以源碼包來創(chuàng)建一個rpm包文件,實現(xiàn)安裝應用的功能。

如何在CentOS/RedHat下實現(xiàn)根據源碼包創(chuàng)建rpm包

有時你可能需要獲取一個開源應用的源碼包,但是可能沒有無法通過該應用的RPM文件來安裝到系統(tǒng)。

在這種情況下,你既可以編譯源碼安裝,也可以以源碼包來創(chuàng)建一個rpm包文件,實現(xiàn)安裝應用的功能。

同樣存在一種情況即你想要創(chuàng)建一個你自己開發(fā)的自定義的RPM包。

這篇指南解釋了如何提高源碼來創(chuàng)建一個rpm包。

為了創(chuàng)建rpm包,你將需要源碼包(通常為一個壓縮文件,其內也包含了SPEC文件)。

SPEC文件包含以下說明:如何創(chuàng)建rpm包,包內包含的文件,安裝的路徑。

RPM將展現(xiàn)創(chuàng)建過程中的測試過程。

執(zhí)行spec文件中的prep塊中定義的系統(tǒng)命令和宏命令。

檢測文件列表的內容

執(zhí)行spec文件中的build塊中定義的系統(tǒng)命令和宏命令。在這一步中文件列表中的宏命令也被執(zhí)行。

創(chuàng)建二進制包文件

創(chuàng)建源碼包文件

一旦RPM執(zhí)行了上述步驟,將創(chuàng)建二進制的包文件和源碼包文件。

二進制包文件包含所有安裝或卸載包的額外信息的源文件。

通常安裝包的所有選項都是有平臺差異的。二進制包文件包含為一個特殊結構而編譯的完整應用或函數(shù)庫。源碼包通常包含原始壓縮的tar文件,spec文件和創(chuàng)建二進制包時相關的補丁。

讓我們使用tar文件來看看如何創(chuàng)建一個簡單的源和二進制RPM包。

如果你對rpm包比較陌生,你應該首先去理解在CentOS/Redhat上如何使用rpm命令安裝,升級和卸載包。

1. 安裝rpm-build包

為了創(chuàng)建基于spec文件的rpm文件,我們需要使用rpmbuild命令。

rpmbuild命令是rpm-build包的一部分。安裝過程如下。

  1. # yum install rpm-build 

rpm-build依賴下面的幾個包。如果你還未安裝,就趕緊自動安裝這些包。

  1. elfutils-libelf 
  2. rpm 
  3. rpm-libs 
  4. rpm-python 

 

2. RPM創(chuàng)建目錄

rpm-build命令會在build階段自動創(chuàng)建下列目錄結構。

  1. # ls -lF /root/rpmbuild/drwxr-xr-x. 2 root root 4096 Feb  4 12:21 BUILD/drwxr-xr-x. 2 root root 4096 Feb  4 12:21 BUILDROOT/drwxr-xr-x. 2 root root 4096 Feb  4 12:21 RPMS/drwxr-xr-x. 2 root root 4096 Feb  4 12:21 SOURCES/drwxr-xr-x. 2 root root 4096 Feb  4 12:21 SPECS/drwxr-xr-x. 2 root root 4096 Feb  4 12:21 SRPMS/ 

注意:上述的目錄結構對CentOS和Redhat是都適用。你也可以使用/usr/local/redhat命令,但是你想要在build階段修改topdir參數(shù)。如果你使用的是SuSE企業(yè)版Linux,使用 /usr/src/packages目錄。

如果你想使用你自己的命令結構來代替/root/rpmbuild,你可以使用下列選擇:

使用-buildroot選擇,并在rpmbuild階段定義自定義的目錄。

在rpmrc文件或rpmmacros文件中定義topdir參數(shù)

3. 下載源碼tar文件

接著,下載你想要創(chuàng)建的包的源碼tar文件,并保存在SOURCES目錄下。

在這個例子中,我使用的是icecase開源軟件的源碼包,這時一個流多媒體服務器軟件。但是這些步驟在創(chuàng)建其他rpm包時都是相同。你只需要下載你想要的軟件的源碼包即可。

  1. # cd /root/rpmbuild/SOURCES/# wget http://downloads.xiph.org/releases/icecast/icecast-2.3.3.tar.gz# ls -l-rw-r--r--. 1 root root 1161774 Jun 11  2012 icecast-2.3.3.tar.gz 

4. 創(chuàng)建spec文件

在這一步中,我們通過創(chuàng)建一個spec文件來定義創(chuàng)建過程。這個spec文件通常包含下列8個不同的塊:

  • Preamble – preamable塊包含了被創(chuàng)建包的信息和定義相關依賴。通常它是一些行,以標簽信息開頭,后接冒號,而后是一些說明信息。
  • %prep – 在這一個塊中,我們將為創(chuàng)建過程準備軟件。在此過程中,任何先前的創(chuàng)建都被刪除,而源文件(. tar)文件被擴展,等等。 一個更關鍵的事情是要了解可用的有預定義宏命令,可以執(zhí)行各種快捷選項來構建rpm包。當您嘗試創(chuàng)建一個復雜的包時,您可能正在使用這個宏命令。在下面的示例中,我使用了一個名為% setup的宏,它刪除了先前的創(chuàng)建,解壓源文件并更改文件的權限。您還可以在% prep部分中使用sh腳本執(zhí)行此操作,但是% setup宏使用預定義的sh腳本簡化了流程。
  • %description – 描述塊通常包含對包的描述信息
  • %build – 這個是真正執(zhí)行build指令的塊。通常是一個sh腳本。
  • %install – %install塊也是作為sh腳本來執(zhí)行的,就像%prep和%build塊。這時安裝階段的步驟
  • %files –這個塊包含了這個包的一系列文件。不在此塊中的文件將不可用。要求是完整的路徑,并且在此塊中你可以設置文件的屬性和權限。
  • %clean – 這個塊是為了清理那些不是應用正常創(chuàng)建區(qū)域的其他文件。舉個例子來說:如果應用在創(chuàng)建過程中在/tmp目錄下創(chuàng)建了一個臨時目錄結構,它將不會被移除;但是如果在該塊中定義了,那么在正確安裝后臨時目錄將被移除。

下面是icecast.spec文件

  1. # cat /root/rpmbuild/SPECS/icecast.specName:           icecast 
  2. Version:        2.3.3Release:        0Summary:        Xiph Streaming media server that supports multiple formats. 
  3. Group:          Applications/Multimedia 
  4. License:        GPL 
  5. URL:            http://www.icecast.org/ 
  6. Vendor:         Xiph.org Foundation team@icecast.org 
  7. Source:         http://downloads.us.xiph.org/releases/icecast/%{name}-%{version}.tar.gz 
  8. Prefix:         %{_prefix} 
  9. Packager:   Karthik 
  10. BuildRoot:      %{_tmppath}/%{name}-root 
  11.  
  12. %description 
  13. Icecast is a streaming media server which currently supports Ogg Vorbisand MP3 audio streams. It can be used to create an Internet radio 
  14. station or a privately running jukebox and many things in between
  15. It is very versatile in that new formats can be added relatively 
  16. easily and supports open standards for commuincation and interaction. 
  17.  
  18. %prep 
  19. %setup -q -n %{name}-%{version} 
  20.  
  21. %build 
  22. CFLAGS="$RPM_OPT_FLAGS" ./configure --prefix=%{_prefix} --mandir=%{_mandir} --sysconfdir=/etc 
  23.  
  24. make 
  25.  
  26. %install 
  27. "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 
  28.  
  29. make DESTDIR=$RPM_BUILD_ROOT install 
  30. rm -rf $RPM_BUILD_ROOT%{_datadir}/doc/%{name
  31.  
  32. %clean 
  33. "$RPM_BUILD_ROOT" != "/" ] && rm -rf $RPM_BUILD_ROOT 
  34.  
  35. %files 
  36. %defattr(-,root,root) 
  37. %doc README AUTHORS COPYING NEWS TODO ChangeLog 
  38. %doc doc/*.html 
  39. %doc doc/*.jpg 
  40. %doc doc/*.css 
  41. %config(noreplace) /etc/%{name}.xml 
  42. %{_bindir}/icecast 
  43. %{_prefix}/share/icecast/* 
  44.  
  45. %changelog 
  46.  
  47. In this file, under % prep section you may noticed the macro “%setup -q -n %{name}-%{version}”. This macro executes the following command in the background. 
  48.  
  49. cd /usr/src/redhat/BUILD 
  50. rm -rf icecast 
  51. gzip -dc /usr/src/redhat/SOURCES/icecast-2.3.3.tar.gz | tar -xvvf - 
  52. if [ $? -ne 0 ]; then 
  53.   exit $? 
  54. fi 
  55. cd icecast 
  56. cd /usr/src/redhat/BUILD/icecast 
  57. chown -R root.root . 
  58. chmod -R a+rX,g-w,o-w . 

 

在% build部分中,您將看到帶有配置選項的CFLAGS,它定義了在RPM安裝期間可以使用的選項和前綴選項,強制目錄用于安裝和sysconfig目錄,系統(tǒng)文件需要在該目錄下復制。

在這一行中,您將看到make實用程序,它決定需要編譯的文件列表,并適當?shù)鼐幾g它們。

在%安裝部分中,“make install”的%安裝下面的行用于從前面的步驟中編譯的二進制文件,并安裝或將它們復制到適當?shù)奈恢?,這樣它們就可以被訪問。

5. 使用rpmbuild命令創(chuàng)建rpm文件

一旦SPEC文件準備好,您就可以開始使用rpm - b命令來構建rpm了。b選項用于執(zhí)行構建過程的所有階段。如果您在這個階段看到任何錯誤,那么您需要在再次嘗試之前解決它。錯誤通常是庫依賴項,您可以在需要時下載并安裝它。

  1. # cd /root/rpmbuild/SPECS# rpmbuild -ba icecast.specExecuting(%prep): /bin/sh -e /var/tmp/rpm-tmp.Kohe4t 
  2. + umask 022 
  3. + cd /root/rpmbuild/BUILD 
  4. + cd /root/rpmbuild/BUILD 
  5. + rm -rf icecast-2.3.3 
  6. + /usr/bin/gzip -dc /root/rpmbuild/SOURCES/icecast-2.3.3.tar.gz 
  7. + /bin/tar -xf - 
  8. + STATUS=0 
  9. '[' 0 -ne 0 ']'+ cd icecast-2.3.3 
  10. + /bin/chmod -Rf a+rX,u+w,g-w,o-w . 
  11. + exit 0 
  12. Executing(%build): /bin/sh -e /var/tmp/rpm-tmp.ynm7H7 
  13. + umask 022 
  14. + cd /root/rpmbuild/BUILD 
  15. + cd icecast-2.3.3 
  16. + CFLAGS='-O2 -g'+ ./configure --prefix=/usr --mandir=/usr/share/man --sysconfdir=/etc 
  17. checking for a BSD-compatible install... /usr/bin/install -c 
  18. checking whether build environment is sane... yes 
  19. checking for a thread-safe mkdir -p... /bin/mkdir -p 
  20. checking for gawk... gawk 
  21. checking whether make sets $(MAKE)... yes 
  22. checking whether to enable maintainer-specific portions of Makefiles... no 
  23. checking for gcc... gcc 
  24. .. 
  25. .. 
  26. .. 
  27. Wrote: /root/rpmbuild/SRPMS/icecast-2.3.3-0.src.rpm 
  28. Wrote: /root/rpmbuild/RPMS/x86_64/icecast-2.3.3-0.x86_64.rpm 
  29. Executing(%clean): /bin/sh -e /var/tmp/rpm-tmp.dzahrv 
  30. + umask 022 
  31. + cd /root/rpmbuild/BUILD 
  32. + cd icecast-2.3.3 
  33. '[' /root/rpmbuild/BUILDROOT/icecast-2.3.3-0.x86_64 '!=' / ']'+ rm -rf /root/rpmbuild/BUILDROOT/icecast-2.3.3-0.x86_64 
  34. + exit 0 

 

注意:如果你使用的是SuSE linux,如果rpmbuild工具不可用,試試使用“rpm -ba” 去創(chuàng)建rpm包。

在安裝過程中,你可能會注意到如下錯誤信息:

錯誤1: XSLT配置文件未被找到

  1. checking for xslt-config... noconfigure: error: XSLT configuration could not be founderror: Bad exit status from /var/tmp/rpm-tmp.8J0ynG (%build) 
  2. RPM build errors: 
  3.     Bad exit status from /var/tmp/rpm-tmp.8J0ynG (%build) 

 

解決方法1: 安裝libxstl-devel

  1. yum install libxstl-devel 

將同時安裝如下依賴包:

  • libgcrypt
  • libgcrypt-devel
  • libgpg-error-devel

錯誤2: libvorbis錯誤

  1. checking for libvorbis... configure: error: must have Ogg Vorbis v1.0 or above installederror: Bad exit status from /var/tmp/rpm-tmp.m4Gk3f (%build) 

解決方法2: 安裝libvorbis-devel

  1. yum install libvorbis-devel 

將同時安裝如下依賴包:

  • libogg
  • libogg-devel
  • libvorbis

6. 驗證源和二進制RPM包

一旦rpmbuild命令成功運行結束,你可以在下列命令下驗證源碼rpm包和二進制rpm包文件。

  1. # ls -l /root/rpmbuild/SRPMS/-rw-r--r-- 1 root root 1162483 Aug 25 15:46 icecast-2.3.3-0.src.rpm# ls -l /root/rpmbuild/RPMS/x86_64/-rw-r--r--. 1 root root 349181 Feb  4 12:54 icecast-2.3.3-0.x86_64.rpm7. Install the RPM File to Verify 

作為***的步驟,你可以安裝二進制包來驗證是否成功安裝,以及所有的依賴都被滿足。

  1. # rpm -ivvh /root/rpmbuild/RPMS/x86_64/icecast-2.3.3-0.x86_64.rpmD: ============== /root/rpmbuild/RPMS/x86_64/icecast-2.3.3-0.x86_64.rpmD: loading keyring from pubkeys in /var/lib/rpm/pubkeys/*.keyD: couldn't find any keys in /var/lib/rpm/pubkeys/*.keyD: loading keyring from rpmdbD: opening  db environment /var/lib/rpm cdb:mpool:joinenvD: opening  db index       /var/lib/rpm/Packages rdonly mode=0x0D:  read h#     210 Header sanity check: OKD: added key gpg-pubkey-c105b9de-4e0fd3a3 to keyringD: Using legacy gpg-pubkey(s) from rpmdbD: Expected size:       349181 = lead(96)+sigs(180)+pad(4)+data(348901)D:   Actual size:       349181D: ========== relocationsD:      added binary package [0]D: found 0 source and 1 binary packagesD: ========== +++ icecast-2.3.3-0 x86_64/linux 0x2.. 
  2. .. 

 

安裝完成后可以驗證是否成功。

 

  1. # rpm -qa icecasticecast-2.3.3-0.x86_64  

 

責任編輯:龐桂玉 來源: 運維派
相關推薦

2011-05-04 09:11:30

RPM包Linux

2018-07-19 09:20:47

LinuxArchLinuxRPM包

2014-08-19 09:33:29

FedoraCentOSRPM

2010-01-11 10:23:14

linuxrpm包

2010-06-02 13:05:14

Sendmail 安裝

2010-02-22 18:35:01

2010-03-02 17:19:56

Linux telne

2019-11-05 10:55:05

RPM包RPMLinux

2017-04-08 19:45:27

Linux命令安裝

2015-07-21 11:43:14

CentosRPM

2019-11-05 10:18:04

RPM包RPMLinux

2010-01-13 10:02:21

LinuxRPM軟件包

2010-01-14 09:48:05

CentOS VSFT

2016-11-09 09:10:55

CentOSRPMFedora

2022-10-17 06:34:28

FedoraLinuxRPM Fusion

2022-08-01 22:19:35

Ubuntu命令

2013-11-25 17:08:49

Linux命令RPM選項

2010-07-01 17:52:41

UML包圖

2010-01-14 13:17:42

CentOS安裝

2015-03-23 13:15:55

yumRPM
點贊
收藏

51CTO技術棧公眾號