CentOS 利用Yum 下载软件包

需求:
假如需要下载某些rpm软件包,但这些rpm软件包已经很难找到下载资源并且很多是存在依赖包,一个一个下载很麻烦,但很多网络yum源提是可以直接在线安装,如果用户需要是把rpm软件包和依赖包一并下载,这时,使用网络yum源下载rpm软件包最为方便。

Yum下载软件包有两种方法:(本教程以阿里云Yum源为下载RPM软件包)

Linux System Environment

[root@yumserver ~]cat /etc/redhat-release                   #==》系统版本
CentOS Linux release 7.5.1804 (Core)
[root@yumserver ~]uname –r                                 #==》内核版本
3.10.0-862.el7.x86_64
[root@yumserver ~] uname -m                                 #==》系统架构
x86_64
[root@yumserver ~]echo $LANG                               #==》系统字符集
en_US.UTF-8

方法一、使用yum源的downloadonly插件(Yum工具自带此插件)
提示:此方法会把RPM软件包和相关的依赖包一并下载,但本地系统不会安装下载的软件,推荐使用此方法。

1、配置阿里云Yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、使用yum源命令下载createrepo软件包并指定路径

[root@yumserver ~]# mkdir -p /tmp/yum
[root@yumserver ~]# yum -y install createrepo --downloadonly --downloaddir=/tmp/yum
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package createrepo.noarch 0:0.9.9-28.el7 will be installed
--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Processing Dependency: deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Running transaction check
---> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
---> Package python-deltarpm.x86_64 0:3.6-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================
 Package                     Arch               Version                     Repository        Size
===================================================================================================
Installing:
 createrepo                  noarch             0.9.9-28.el7                base              94 k
Installing for dependencies:
 deltarpm                    x86_64             3.6-3.el7                   base              82 k
 python-deltarpm             x86_64             3.6-3.el7                   base              31 k

Transaction Summary
===================================================================================================
Install  1 Package (+2 Dependent packages)

Total download size: 207 k
Installed size: 558 k
Background downloading packages, then exiting:
(1/3): createrepo-0.9.9-28.el7.noarch.rpm                                   |  94 kB  00:00:00     
(2/3): deltarpm-3.6-3.el7.x86_64.rpm                                        |  82 kB  00:00:00     
(3/3): python-deltarpm-3.6-3.el7.x86_64.rpm                                 |  31 kB  00:00:00     
---------------------------------------------------------------------------------------------------
Total                                                              1.8 MB/s | 207 kB  00:00:00     
exiting because "Download Only" specified
[root@yumserver ~]# ls -lrth /tmp/yum
total 212K
-rw-r--r-- 1 root root 83K Jul  4  2014 deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 32K Jul  4  2014 python-deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 94K Aug 10  2017 createrepo-0.9.9-28.el7.noarch.rpm

方法二:利用Yum工具缓存功能
提示:此方法会把RPM软件包和相关的依赖包一并下载,并且本地系统会把下载的软件包一并安装。

1、配置阿里云Yum源

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum makecache

2、/etc/yum.conf配置文件参数说明

[root@yumserver ~]# cat /etc/yum.conf 
[main]
cachedir=/var/cache/yum/$basearch/$releasever  ##指定yum缓存的RPM软件包
keepcache=0                                ##1保存已安装的RPM软件包,0不保存
debuglevel=2                               ##调试级别(0-10)
logfile=/var/log/yum.log                      ##记录yum下载的软件包记录
exactarch=1 
obsoletes=1
gpgcheck=1                                ##是否密钥检查
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release

3、修改/etc/yum.conf配置文件将keepcache=0改成keepcache=1,保存退出

[root@yumserver ~]# sed -i 's/keepcache=0/keepcache=1/g' /etc/yum.conf
[root@yumserver ~]# cat /etc/yum.conf | grep keepcache
keepcache=1
[root@yumserver ~]# systemctl daemon-reload
[root@yumserver ~]# yum makecache
[root@yumserver ~]# rpm -qa | grep createrepo
[root@yumserver ~]# yum -y install createrepo
[root@yumserver ~]# ls -lrth /var/cache/yum/x86_64/7/base/packages/
total 212K
-rw-r--r-- 1 root root 83K Jul  4  2014 deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 32K Jul  4  2014 python-deltarpm-3.6-3.el7.x86_64.rpm
-rw-r--r-- 1 root root 94K Aug 10  2017 createrepo-0.9.9-28.el7.noarch.rp
[root@yumserver ~]# rpm -qa | grep createrepo
createrepo-0.9.9-28.el7.noarch

你可能感兴趣的:(CentOS 利用Yum 下载软件包)