方法一:
    如果没有downloadonly插件,就是用以下命令安装

    1. yum install yum-plugin-downloadonly
    1. yum install --downloadonly --downloaddir=<directory> <package-name>
    1. yum install --downloadonly --downloaddir=/data/package xxx xxx xxx

    例子:

    1. yum install --downloadonly --downloaddir=/root/mypackages/ nginx

    终端输出:

    1. Loaded plugins: fastestmirror
    2. base | 3.6 kB 00:00:00
    3. epel/x86_64/metalink | 5.7 kB 00:00:00
    4. epel | 4.7 kB 00:00:00
    5. extras | 3.4 kB 00:00:00
    6. updates | 3.4 kB 00:00:00
    7. (1/3): updates/7/x86_64/primary_db | 3.6 MB 00:00:01
    8. (2/3): epel/x86_64/updateinfo | 848 kB 00:00:02
    9. (3/3): epel/x86_64/primary_db | 6.1 MB 00:03:08
    10. Loading mirror speeds from cached hostfile
    11. * base: mirrors.cn99.com
    12. * epel: mirrors.ustc.edu.cn
    13. * extras: mirrors.cn99.com
    14. * updates: mirrors.cn99.com
    15. Resolving Dependencies
    16. --> Running transaction check
    17. ---> Package nginx.x86_64 1:1.12.2-1.el7 will be installed
    18. --> Processing Dependency: nginx-all-modules = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64
    19. --> Processing Dependency: nginx-filesystem = 1:1.12.2-1.el7 for package: 1:nginx-1.12.2-1.el7.x86_64
    20. --> Processing Dependency: libcrypto.so.10(OPENSSL_1.0.2)(64bit) for package: 1:nginx-1.12.2-1.el7.x86_64
    21. --> Processing Dependency: nginx-filesystem for package: 1:nginx-1.12.2-1.el7.x86_64
    22. --> Processing Dependency: libprofiler.so.0()(64bit) for package: 1:nginx-1.12.2-1.el7.x86_64
    23. --> Running transaction check
    24. ---> Package gperftools-libs.x86_64 0:2.4-8.el7 will be installed
    25. --> Processing Dependency: libunwind.so.8()(64bit) for package: gperftools-libs-2.4-8.el7.x86_64
    26. ---> Package nginx-all-modules.noarch 1:1.12.2-1.el7 will be installed
    27. --> Processing Dependency: nginx-mod-http-geoip = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
    28. --> Processing Dependency: nginx-mod-http-image-filter = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
    29. --> Processing Dependency: nginx-mod-http-perl = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
    30. --> Processing Dependency: nginx-mod-http-xslt-filter = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
    31. --> Processing Dependency: nginx-mod-mail = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
    32. --> Processing Dependency: nginx-mod-stream = 1:1.12.2-1.el7 for package: 1:nginx-all-modules-1.12.2-1.el7.noarch
    33. ---> Package nginx-filesystem.noarch 1:1.12.2-1.el7 will be installed
    34. ---> Package openssl-libs.x86_64 1:1.0.1e-42.el7.9 will be updated
    35. --> Processing Dependency: openssl-libs(x86-64) = 1:1.0.1e-42.el7.9 for package: 1:openssl-1.0.1e-42.el7.9.x86_64
    36. ---> Package openssl-libs.x86_64 1:1.0.2k-8.el7 will be an update
    37. --> Running transaction check
    38. ---> Package libunwind.x86_64 2:1.2-2.el7 will be installed
    39. ---> Package nginx-mod-http-geoip.x86_64 1:1.12.2-1.el7 will be installed
    40. --> Processing Dependency: GeoIP for package: 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64
    41. --> Processing Dependency: libGeoIP.so.1()(64bit) for package: 1:nginx-mod-http-geoip-1.12.2-1.el7.x86_64
    42. ---> Package nginx-mod-http-image-filter.x86_64 1:1.12.2-1.el7 will be installed
    43. --> Processing Dependency: gd for package: 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
    44. --> Processing Dependency: libgd.so.2()(64bit) for package: 1:nginx-mod-http-image-filter-1.12.2-1.el7.x86_64
    45. ---> Package nginx-mod-http-perl.x86_64 1:1.12.2-1.el7 will be installed
    46. ---> Package nginx-mod-http-xslt-filter.x86_64 1:1.12.2-1.el7 will be installed
    47. --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.11)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
    48. --> Processing Dependency: libxslt.so.1(LIBXML2_1.0.18)(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
    49. --> Processing Dependency: libexslt.so.0()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
    50. --> Processing Dependency: libxslt.so.1()(64bit) for package: 1:nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64
    51. ---> Package nginx-mod-mail.x86_64 1:1.12.2-1.el7 will be installed
    52. ---> Package nginx-mod-stream.x86_64 1:1.12.2-1.el7 will be installed
    53. ---> Package openssl.x86_64 1:1.0.1e-42.el7.9 will be updated
    54. ---> Package openssl.x86_64 1:1.0.2k-8.el7 will be an update
    55. --> Running transaction check
    56. ---> Package GeoIP.x86_64 0:1.5.0-11.el7 will be installed
    57. ---> Package gd.x86_64 0:2.0.35-26.el7 will be installed
    58. --> Processing Dependency: libpng15.so.15(PNG15_0)(64bit) for package: gd-2.0.35-26.el7.x86_64
    59. --> Processing Dependency: libjpeg.so.62(LIBJPEG_6.2)(64bit) for package: gd-2.0.35-26.el7.x86_64
    60. --> Processing Dependency: libpng15.so.15()(64bit) for package: gd-2.0.35-26.el7.x86_64
    61. --> Processing Dependency: libjpeg.so.62()(64bit) for package: gd-2.0.35-26.el7.x86_64
    62. --> Processing Dependency: libfontconfig.so.1()(64bit) for package: gd-2.0.35-26.el7.x86_64
    63. --> Processing Dependency: libXpm.so.4()(64bit) for package: gd-2.0.35-26.el7.x86_64
    64. --> Processing Dependency: libX11.so.6()(64bit) for package: gd-2.0.35-26.el7.x86_64
    65. ---> Package libxslt.x86_64 0:1.1.28-5.el7 will be installed
    66. --> Running transaction check
    67. ---> Package fontconfig.x86_64 0:2.10.95-11.el7 will be installed
    68. --> Processing Dependency: fontpackages-filesystem for package: fontconfig-2.10.95-11.el7.x86_64
    69. --> Processing Dependency: font(:lang=en) for package: fontconfig-2.10.95-11.el7.x86_64
    70. ---> Package libX11.x86_64 0:1.6.5-1.el7 will be installed
    71. --> Processing Dependency: libX11-common >= 1.6.5-1.el7 for package: libX11-1.6.5-1.el7.x86_64
    72. --> Processing Dependency: libxcb.so.1()(64bit) for package: libX11-1.6.5-1.el7.x86_64
    73. ---> Package libXpm.x86_64 0:3.5.12-1.el7 will be installed
    74. ---> Package libjpeg-turbo.x86_64 0:1.2.90-5.el7 will be installed
    75. ---> Package libpng.x86_64 2:1.5.13-7.el7_2 will be installed
    76. --> Running transaction check
    77. ---> Package fontpackages-filesystem.noarch 0:1.44-8.el7 will be installed
    78. ---> Package libX11-common.noarch 0:1.6.5-1.el7 will be installed
    79. ---> Package libxcb.x86_64 0:1.12-1.el7 will be installed
    80. --> Processing Dependency: libXau.so.6()(64bit) for package: libxcb-1.12-1.el7.x86_64
    81. ---> Package lyx-fonts.noarch 0:2.2.3-1.el7 will be installed
    82. --> Running transaction check
    83. ---> Package libXau.x86_64 0:1.0.8-2.1.el7 will be installed
    84. --> Finished Dependency Resolution
    85. Dependencies Resolved
    86. ====================================================================================================================================================================================================================================
    87. Package Arch Version Repository Size
    88. ====================================================================================================================================================================================================================================
    89. Installing:
    90. nginx x86_64 1:1.12.2-1.el7 epel 529 k
    91. Installing for dependencies:
    92. GeoIP x86_64 1.5.0-11.el7 base 1.1 M
    93. fontconfig x86_64 2.10.95-11.el7 base 229 k
    94. fontpackages-filesystem noarch 1.44-8.el7 base 9.9 k
    95. gd x86_64 2.0.35-26.el7 base 146 k
    96. gperftools-libs x86_64 2.4-8.el7 base 272 k
    97. libX11 x86_64 1.6.5-1.el7 base 606 k
    98. libX11-common noarch 1.6.5-1.el7 base 164 k
    99. libXau x86_64 1.0.8-2.1.el7 base 29 k
    100. libXpm x86_64 3.5.12-1.el7 base 55 k
    101. libjpeg-turbo x86_64 1.2.90-5.el7 base 134 k
    102. libpng x86_64 2:1.5.13-7.el7_2 base 213 k
    103. libunwind x86_64 2:1.2-2.el7 base 57 k
    104. libxcb x86_64 1.12-1.el7 base 211 k
    105. libxslt x86_64 1.1.28-5.el7 base 242 k
    106. lyx-fonts noarch 2.2.3-1.el7 epel 159 k
    107. nginx-all-modules noarch 1:1.12.2-1.el7 epel 16 k
    108. nginx-filesystem noarch 1:1.12.2-1.el7 epel 17 k
    109. nginx-mod-http-geoip x86_64 1:1.12.2-1.el7 epel 23 k
    110. nginx-mod-http-image-filter x86_64 1:1.12.2-1.el7 epel 26 k
    111. nginx-mod-http-perl x86_64 1:1.12.2-1.el7 epel 35 k
    112. nginx-mod-http-xslt-filter x86_64 1:1.12.2-1.el7 epel 25 k
    113. nginx-mod-mail x86_64 1:1.12.2-1.el7 epel 53 k
    114. nginx-mod-stream x86_64 1:1.12.2-1.el7 epel 76 k
    115. Updating for dependencies:
    116. openssl x86_64 1:1.0.2k-8.el7 base 492 k
    117. openssl-libs x86_64 1:1.0.2k-8.el7 base 1.2 M
    118. Transaction Summary
    119. ====================================================================================================================================================================================================================================
    120. Install 1 Package (+23 Dependent packages)
    121. Upgrade ( 2 Dependent packages)
    122. Total download size: 6.0 M
    123. Background downloading packages, then exiting:
    124. Delta RPMs disabled because /usr/bin/applydeltarpm not installed.
    125. (1/26): fontpackages-filesystem-1.44-8.el7.noarch.rpm | 9.9 kB 00:00:00
    126. (2/26): fontconfig-2.10.95-11.el7.x86_64.rpm | 229 kB 00:00:00
    127. (3/26): gd-2.0.35-26.el7.x86_64.rpm | 146 kB 00:00:00
    128. (4/26): libX11-1.6.5-1.el7.x86_64.rpm | 606 kB 00:00:00
    129. (5/26): libX11-common-1.6.5-1.el7.noarch.rpm | 164 kB 00:00:00
    130. (6/26): libXau-1.0.8-2.1.el7.x86_64.rpm | 29 kB 00:00:00
    131. (7/26): libXpm-3.5.12-1.el7.x86_64.rpm | 55 kB 00:00:00
    132. (8/26): libjpeg-turbo-1.2.90-5.el7.x86_64.rpm | 134 kB 00:00:00
    133. (9/26): libpng-1.5.13-7.el7_2.x86_64.rpm | 213 kB 00:00:00
    134. (10/26): libunwind-1.2-2.el7.x86_64.rpm | 57 kB 00:00:00
    135. (11/26): libxcb-1.12-1.el7.x86_64.rpm | 211 kB 00:00:00
    136. (12/26): libxslt-1.1.28-5.el7.x86_64.rpm | 242 kB 00:00:00
    137. warning: /root/mypackages/lyx-fonts-2.2.3-1.el7.noarch.rpm.12470.tmp: Header V3 RSA/SHA256 Signature, key ID 352c64e5: NOKEY
    138. Public key for lyx-fonts-2.2.3-1.el7.noarch.rpm.12470.tmp is not installed
    139. (13/26): lyx-fonts-2.2.3-1.el7.noarch.rpm | 159 kB 00:00:00
    140. (14/26): GeoIP-1.5.0-11.el7.x86_64.rpm | 1.1 MB 00:00:01
    141. (15/26): nginx-filesystem-1.12.2-1.el7.noarch.rpm | 17 kB 00:00:00
    142. (16/26): nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm | 26 kB 00:00:00
    143. (17/26): nginx-all-modules-1.12.2-1.el7.noarch.rpm | 16 kB 00:00:00
    144. (18/26): nginx-mod-http-perl-1.12.2-1.el7.x86_64.rpm | 35 kB 00:00:00
    145. (19/26): nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64.rpm | 25 kB 00:00:00
    146. (20/26): nginx-mod-stream-1.12.2-1.el7.x86_64.rpm | 76 kB 00:00:00
    147. (21/26): nginx-mod-mail-1.12.2-1.el7.x86_64.rpm | 53 kB 00:00:00
    148. (22/26): nginx-1.12.2-1.el7.x86_64.rpm | 529 kB 00:00:01
    149. (23/26): openssl-1.0.2k-8.el7.x86_64.rpm | 492 kB 00:00:00
    150. (24/26): openssl-libs-1.0.2k-8.el7.x86_64.rpm | 1.2 MB 00:00:00
    151. (25/26): nginx-mod-http-geoip-1.12.2-1.el7.x86_64.rpm | 23 kB 00:00:01
    152. (26/26): gperftools-libs-2.4-8.el7.x86_64.rpm | 272 kB 00:00:13
    153. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    154. Total 438 kB/s | 6.0 MB 00:00:13
    155. exiting because "Download Only" specified

    现在去你指定的目录位置下,你将会看到那里有下载好的软件包和依赖的软件。在我这种情况下,我已经把软件包下载到 /root/mypackages/ 目录下。

    让我们来查看一下内容:

    1. [root@node76 ~]# ls mypackages/
    2. fontconfig-2.10.95-11.el7.x86_64.rpm libpng-1.5.13-7.el7_2.x86_64.rpm libXpm-3.5.12-1.el7.x86_64.rpm nginx-mod-http-geoip-1.12.2-1.el7.x86_64.rpm openssl-1.0.2k-8.el7.x86_64.rpm
    3. fontpackages-filesystem-1.44-8.el7.noarch.rpm libunwind-1.2-2.el7.x86_64.rpm libxslt-1.1.28-5.el7.x86_64.rpm nginx-mod-http-image-filter-1.12.2-1.el7.x86_64.rpm openssl-libs-1.0.2k-8.el7.x86_64.rpm
    4. gd-2.0.35-26.el7.x86_64.rpm libX11-1.6.5-1.el7.x86_64.rpm lyx-fonts-2.2.3-1.el7.noarch.rpm nginx-mod-http-perl-1.12.2-1.el7.x86_64.rpm
    5. GeoIP-1.5.0-11.el7.x86_64.rpm libX11-common-1.6.5-1.el7.noarch.rpm nginx-1.12.2-1.el7.x86_64.rpm nginx-mod-http-xslt-filter-1.12.2-1.el7.x86_64.rpm
    6. gperftools-libs-2.4-8.el7.x86_64.rpm libXau-1.0.8-2.1.el7.x86_64.rpm nginx-all-modules-1.12.2-1.el7.noarch.rpm nginx-mod-mail-1.12.2-1.el7.x86_64.rpm
    7. libjpeg-turbo-1.2.90-5.el7.x86_64.rpm libxcb-1.12-1.el7.x86_64.rpm nginx-filesystem-1.12.2-1.el7.noarch.rpm nginx-mod-stream-1.12.2-1.el7.x86_64.rpm

    正如你在上面输出所看到的, nginx软件包已经被依据所有依赖性下载完成了 。

    请注意,这个插件适用于 yum install/yum update, 但是并不适用于 yum groupinstall。默认情况下,这个插件将会下载仓库中最新可用的软件包。然而你可以通过指定版本号来下载某个特定的软件版本。
    例子:

    1. yum install --downloadonly --downloaddir=/root/mypackages/ httpd-2.2.6-40.el7

    此外,你也可以如下一次性下载多个包:

    1. yum install --downloadonly --downloaddir=/root/mypackages/ httpd vsftpd

    方法二:

    1. yum install -y yum-utils

    以 root 身份运行如下命令安装 “Yumdownloader” 工具。

    1. yum install yum-utils

    一旦安装完成,运行如下命令去下载一个软件包,例如 httpd:

    1. yumdownloader httpd

    为了根据所有依赖性下载软件包,我们使用 —resolve 参数:

    1. yumdownloader --resolve httpd

    默认情况下,Yumdownloader 将会下载软件包到当前工作目录下。

    为了将软件下载到一个特定的目录下,我们使用 —destdir 参数:

    1. yumdownloader --resolve --destdir=/root/mypackages/ httpd

    或者:

    1. yumdownloader --resolve --destdir /root/mypackages/ httpd

    不像 Downloadonly 插件,Yumdownload 可以下载一组相关的软件包。

    1. yumdownloader "@Development Tools" --resolve --destdir /root/mypackages/

    rpm包安装

    1. rpm -Uvh --force --nodeps *rpm