centos浅谈之rpm和rpmbuild

分类:CentOS教程 阅读:25173 次

一、简介

RPM(Red Hat Package Manager)是用于 Linux 分发版(distribution)的最常见的软件包管理器。RPM包命名方式:name-version-release.architecture.rpm。RPM有五种基本的操作功能:安装、卸载、升级、查询和验证。这五种基本功能的实现仅仅需要用rpm + 选项 + rpm包就能轻易地实现。

如果想发布rpm格式的源码包或者是二进制包,就要使用rpmbuild工具(rpm最新打包工具)。rpmbuild根据本地源码包的成功编译安装而写了spec文件(该文件要以.spec结束)。

二、详解

1、RPM

(1)rpm二进制包(.rpm文件)

常用命令组合:

  1. -ivh:安装显示安装进度--install--verbose--hash
  2. -Uvh:升级软件包--Update;
  3. -qpl:列出RPM软件包内的文件信息[QueryPackagelist];
  4. -qpi:列出RPM软件包的描述信息[QueryPackageinstallpackage(s)];
  5. -qf:查找指定文件属于哪个RPM软件包[QueryFile];
  6. -Va:校验所有的RPM软件包,查找丢失的文件[ViewLost];
  7. -e:删除包

1)安装:

rpm -i your-package.rpm(your-package.rpm是rpm包的文件名),安装过程中可能出现下面的警告或者提示:.. conflict with ... ,则可能是要安装的包里有一些文件可能会覆盖现有的文件,缺省时这样的情况下是无法正确安装的可以用rpm-i--force强制安装即可。若出现... is needed by ...和... is not installed ... 此包需要的一些软件你没有安装可以用rpm-i--nodeps可以忽略所有依赖关系和文件问题,什么包都能安装上,但这种强制安装的软件包不能保证完全发挥功能 。

2)查询:

rpm -qa 将列出所有安装过的包 ,rpm-qa|grephttpd #[搜索指定rpm包是否安装]--all搜索*httpd*
rpm-qlhttpd #[搜索rpm包]--list所有文件安装目录
which mysql #查找rpm包中的文件安装到那里去了
rpm-qpiLinux-1.4-6.i368.rpm #[查看rpm包]--query--package--installpackage信息
rpm-qpfLinux-1.4-6.i368.rpm #[查看rpm包]--file
rpm-qpRfile.rpm       #[查看包]依赖关系
查找rpm中包含哪些文件:一个没有安装过的软件包,使用rpm -qlp *.rpm;一个已经安装的软件包,可以使用rpm -ql *.rpm 。
获取关于一个软件包的信息:一个没有安装过的软件包,使用rpm -qlp *.rpm ;一个已经安装过的软件包,使用rpm -qi *.rpm。

  1. %definelivearches%{ix86}x86_64ppcppc64
  2. %define_libdir%{_prefix}/lib
  3. Summary:Graphicalsysteminstaller
  4. Name:anaconda
  5. Version:13.21.176
  6. Release:1%{?dist}
  7. License:GPLv2+
  8. Group:Applications/System
  9. URL:http://fedoraproject.org/wiki/Anaconda
  10. #TogenerateSource0do:
  11. #gitclonehttp://git.fedorahosted.org/git/anaconda.git
  12. #gitcheckout-barchive-branchanaconda-%{version}-%{release}
  13. #./autogen.sh
  14. #./configure
  15. #makedist
  16. Source0:%{name}-%{version}.tar.bz2
  17. Patch1000:anaconda-centos-installclass.patch
  18. Patch1001:anaconda-centos-upgrade-from-centos.patch
  19. Patch1002:anaconda-centos-droprepos.patch
  20. BuildRoot:%{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u}-n)
  21. #Versionsofrequiredcomponents(donesowemakesurethebuildrequires
  22. #matchtherequiresversionsofthings).
  23. %definedmver1.02.17-6
  24. %definegettextver0.11
  25. %definegenisoimagever1.1.9-4
  26. %defineintltoolver0.31.2-3
  27. %definelibnlver1.0
  28. %definelibselinuxver1.6
  29. %definepykickstartver1.74.8
  30. %definerpmpythonver4.2-0.61
  31. %defineslangver2.0.6-2
  32. %defineyumver2.9.2
  33. %definepartedver1.8.1
  34. %definepypartedver3.0
  35. %definesyscfgdatever1.9.48
  36. %definepythonpyblockver0.45-2
  37. %definee2fsver1.41.0
  38. %definenmver1:0.7.1-3.git20090414
  39. %definedbusver1.2.3
  40. %definecreaterepover0.4.7
  41. %defineyumutilsver1.1.11-3
  42. %defineiscsiver6.2.0.870-3
  43. %definepythoncryptsetupver0.0.6
  44. %definemehver0.8
  45. %definesckeyboardver1.3.1
  46. %definelibblkid2.17.1-1
  47. %definefcoeutilsver1.0.12-3.20100323git
  48. %defineisomd5sumver1.0.6
  49. BuildRequires:audit-libs-devel
  50. BuildRequires:bzip2-devel
  51. BuildRequires:device-mapper-devel>=%{dmver}
  52. BuildRequires:e2fsprogs-devel>=%{e2fsver}
  53. BuildRequires:elfutils-devel
  54. BuildRequires:gettext>=%{gettextver}
  55. BuildRequires:gtk2-devel
  56. BuildRequires:intltool>=%{intltoolver}
  57. BuildRequires:isomd5sum-devel>=%{isomd5sumver}
  58. BuildRequires:libarchive-devel
  59. BuildRequires:libX11-devel
  60. BuildRequires:libXt-devel
  61. BuildRequires:libXxf86misc-devel
  62. BuildRequires:libblkid-devel>=%{libblkid}
  63. BuildRequires:libcurl-devel
  64. BuildRequires:libnl-devel>=%{libnlver}
  65. BuildRequires:libselinux-devel>=%{libselinuxver}
  66. BuildRequires:libsepol-devel
  67. BuildRequires:libxml2-python
  68. BuildRequires:newt-devel
  69. BuildRequires:pango-devel
  70. BuildRequires:pykickstart>=%{pykickstartver}
  71. BuildRequires:python-devel
  72. BuildRequires:python-urlgrabber>=3.9.1-5
  73. BuildRequires:rpm-devel
  74. BuildRequires:rpm-python>=%{rpmpythonver}
  75. BuildRequires:slang-devel>=%{slangver}
  76. BuildRequires:xmlto
  77. BuildRequires:yum>=%{yumver}
  78. BuildRequires:zlib-devel
  79. BuildRequires:NetworkManager-devel>=%{nmver}
  80. BuildRequires:NetworkManager-glib-devel>=%{nmver}
  81. BuildRequires:dbus-devel>=%{dbusver}
  82. BuildRequires:system-config-keyboard>=%{sckeyboardver}
  83. %ifarch%livearches
  84. BuildRequires:desktop-file-utils
  85. %endif
  86. BuildRequires:iscsi-initiator-utils-devel>=%{iscsiver}
  87. %ifarchs390s390x
  88. BuildRequires:s390utils-devel
  89. %endif
  90. Requires:python-meh>=%{mehver}
  91. Requires:policycoreutils
  92. Requires:rpm-python>=%{rpmpythonver}
  93. Requires:comps-extras
  94. Requires:parted>=%{partedver}
  95. Requires:pyparted>=%{pypartedver}
  96. Requires:yum>=%{yumver}
  97. Requires:libxml2-python
  98. Requires:python-urlgrabber>=3.9.1-5
  99. Requires:system-logos
  100. Requires:pykickstart>=%{pykickstartver}
  101. Requires:system-config-date>=%{syscfgdatever}
  102. Requires:device-mapper>=%{dmver}
  103. Requires:device-mapper-libs>=%{dmver}
  104. Requires:dosfstools
  105. Requires:e2fsprogs>=%{e2fsver}
  106. Requires:gzip
  107. Requires:xz
  108. Requires:libarchive
  109. %ifarch%{ix86}x86_64ia64
  110. Requires:dmidecode
  111. %endif
  112. Requires:python-pyblock>=%{pythonpyblockver}
  113. Requires:libuser-python
  114. Requires:newt-python
  115. Requires:authconfig
  116. Requires:system-config-firewall-base
  117. Requires:cryptsetup-luks
  118. Requires:python-cryptsetup>=%{pythoncryptsetupver}
  119. Requires:mdadm
  120. Requires:lvm2
  121. Requires:util-linux-ng>=2.15.1
  122. Requires:system-config-keyboard>=%{sckeyboardver}
  123. Requires:dbus-python
  124. Requires:cracklib-python
  125. Requires:python-nss
  126. Requires:tigervnc-server
  127. %ifarch%livearches
  128. Requires:usermode
  129. Requires:zenity
  130. %endif
  131. Requires:createrepo>=%{createrepover}
  132. Requires:squashfs-tools
  133. Requires:genisoimage>=%{genisoimagever}
  134. %ifarch%{ix86}x86_64
  135. Requires:syslinux>=3.73
  136. Requires:makebootfat
  137. Requires:device-mapper
  138. %endif
  139. %ifarchs390s390x
  140. Requires:openssh
  141. %endif
  142. Requires:isomd5sum
  143. Requires:yum-utils>=%{yumutilsver}
  144. Requires:NetworkManager>=%{nmver}
  145. Requires:dhclient
  146. Requires:anaconda-yum-plugins
  147. Requires:libselinux-python>=%{libselinuxver}
  148. Requires:fcoe-utils>=%{fcoeutilsver}
  149. %ifarch%{sparc}
  150. Requires:elftoaoutpiggyback
  151. %endif
  152. Obsoletes:anaconda-images<=10
  153. Provides:anaconda-images=%{version}-%{release}
  154. Obsoletes:anaconda-runtime<%{version}-%{release}
  155. Provides:anaconda-runtime=%{version}-%{release}
  156. Obsoletes:booty
  157. %description
  158. Theanacondapackagecontainstheprogramwhichwasusedtoinstallyour
  159. system.Thesefilesareoflittleuseonanalreadyinstalledsystem.
  160. %prep
  161. %setup-q
  162. %patch1000-p1
  163. %patch1001-p1
  164. %patch1002-p1
  165. %build
  166. %configure--disable-static
  167. %{__make}%{?_smp_mflags}
  168. %install
  169. %{__rm}-rf%{buildroot}
  170. %{__make}installDESTDIR=%{buildroot}
  171. find%{buildroot}-typef-name"*.la"|xargs%{__rm}
  172. %ifarch%livearches
  173. desktop-file-install--vendor=""--dir=%{buildroot}%{_datadir}/applications%{buildroot}%{_datadir}/applications/liveinst.desktop
  174. %else
  175. %{__rm}-rf%{buildroot}%{_bindir}/liveinst%{buildroot}%{_sbindir}/liveinst
  176. %endif
  177. %find_lang%{name}
  178. %clean
  179. %{__rm}-rf%{buildroot}
  180. %ifarch%livearches
  181. %post
  182. update-desktop-database&>/dev/null||:
  183. %endif
  184. %ifarch%livearches
  185. %postun
  186. update-desktop-database&>/dev/null||:
  187. %endif
  188. %files-f%{name}.lang
  189. %defattr(-,root,root)
  190. %docCOPYING
  191. %docdocs/command-line.txt
  192. %docdocs/install-methods.txt
  193. %docdocs/mediacheck.txt
  194. %docdocs/anaconda-release-notes.txt
  195. /lib/udev/rules.d/70-anaconda.rules
  196. %{_sbindir}/anaconda
  197. %ifarchi386i486i586i686x86_64
  198. %{_sbindir}/gptsync
  199. %{_sbindir}/showpart
  200. %endif
  201. %{_datadir}/anaconda
  202. %{_prefix}/lib/anaconda
  203. %{_prefix}/lib/anaconda-runtime
  204. %ifarch%livearches
  205. %{_bindir}/liveinst
  206. %{_sbindir}/liveinst
  207. %config(noreplace)%{_sysconfdir}/pam.d/*
  208. %config(noreplace)%{_sysconfdir}/security/console.apps/*
  209. %{_sysconfdir}/X11/xinit/xinitrc.d/*
  210. %{_datadir}/applications/*.desktop
  211. %{_datadir}/icons/hicolor/*
  212. %endif
  213. %changelog
  214. *SatJun232012KaranbirSingh<kbsingh@centos.org>-13.21.176.1.el6.centos
  215. -BuildforCentOS-6.3

三、总结

(1)IBM官方网站中rpm包的使用讲解的很全面,参看http://www.ibm.com/developerworks/cn/linux/management/package/rpm/part1/和rpmbuild的spec文件的解析参看http://www.ibm.com/developerworks/cn/linux/l-rpm/。

(2)rpm和rpmbuild内容众多丰富,该博客总结部分内容,以便使用时能快速查找到。

(3)若有读者想沟通交流的,可发信息到邮箱yang.ao@i-soft.com.cn。