linux-配置yum源

37 篇文章 0 订阅

一、配置本地yum源

        首先将centos自带的网络yum源删掉(自带的默认从centos官网下载软件,服务器在国外,非常不稳定)

 [root@cloud ~]# rm -rf /etc/yum.repos.d/*

创建挂载点并挂载镜像

[root@cloud ~]# mkdir /opt/centos

[root@cloud ~]# mount /dev/cdrom /opt/centos/

mount: /dev/sr0 写保护,将以只读方式挂载

创建并编写本地yum源配置文件,编写完成之后wq保存退出

[root@cloud ~]# vi /etc/yum.repos.d/local.repo
[centos]

name=centos                 # Yum源的名称,用于描述这个源

baseurl=file:///opt/centos  # 本地Yum源的位置,指向挂载点目录

gpgcheck=0                  # 不进行GPG签名检查

enabled=1                   # 启用该Yum源

清除缓存原来的生成新的缓存并列出当前系统中已配置和启用的Yum仓库(repositories)及其状态

[root@cloud ~]# yum clean all
已加载插件:fastestmirror, langpacks

正在清理软件源: centos

Cleaning up list of fastest mirrors

Other repos take up 1.0 G of disk space (use --verbose for details)
[root@cloud ~]# yum makecache

已加载插件:fastestmirror, langpacks

Determining fastest mirrors

centos                                                                                           | 3.6 kB  00:00:00    

(1/4): centos/group_gz                                                                           | 153 kB  00:00:00    

(2/4): centos/primary_db                                                                         | 3.3 MB  00:00:00    

(3/4): centos/other_db                                                                           | 1.3 MB  00:00:00    

(4/4): centos/filelists_db                                                                       | 3.3 MB  00:00:00    

元数据缓存已建立

[root@cloud ~]# yum repolist

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

源标识                                                   源名称                                                    状态

centos                                                   centos                                                    4,070

repolist: 4,070

下载httpd测试一下

[root@cloud ~]# yum install -y httpd

已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

正在解决依赖关系

--> 正在检查事务

---> 软件包 httpd.x86_64.0.2.4.6-95.el7.centos 将被 安装

--> 正在处理依赖关系 httpd-tools = 2.4.6-95.el7.centos,它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要

--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要

--> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要

--> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要

--> 正在检查事务

---> 软件包 apr.x86_64.0.1.4.8-7.el7 将被 安装

---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装

---> 软件包 httpd-tools.x86_64.0.2.4.6-95.el7.centos 将被 安装

---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装

--> 解决依赖关系完成



依赖关系解决



========================================================================================================================

 Package                     架构                   版本                                   源                      大小

========================================================================================================================

正在安装:

 httpd                       x86_64                 2.4.6-95.el7.centos                    centos                 2.7 M

为依赖而安装:

 apr                         x86_64                 1.4.8-7.el7                            centos                 104 k

 apr-util                    x86_64                 1.5.2-6.el7                            centos                  92 k

 httpd-tools                 x86_64                 2.4.6-95.el7.centos                    centos                  93 k

 mailcap                     noarch                 2.1.41-2.el7                           centos                  31 k



事务概要

========================================================================================================================

安装  1 软件包 (+4 依赖软件包)



总下载量:3.0 M

安装大小:10 M

Downloading packages:

------------------------------------------------------------------------------------------------------------------------

总计                                                                                     95 MB/s | 3.0 MB  00:00:00    

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

  正在安装    : apr-1.4.8-7.el7.x86_64                                                                              1/5

  正在安装    : apr-util-1.5.2-6.el7.x86_64                                                                         2/5

  正在安装    : httpd-tools-2.4.6-95.el7.centos.x86_64                                                              3/5

  正在安装    : mailcap-2.1.41-2.el7.noarch                                                                         4/5

  正在安装    : httpd-2.4.6-95.el7.centos.x86_64                                                                    5/5

  验证中      : httpd-tools-2.4.6-95.el7.centos.x86_64                                                              1/5

  验证中      : mailcap-2.1.41-2.el7.noarch                                                                         2/5

  验证中      : apr-1.4.8-7.el7.x86_64                                                                              3/5

  验证中      : httpd-2.4.6-95.el7.centos.x86_64                                                                    4/5

  验证中      : apr-util-1.5.2-6.el7.x86_64                                                                         5/5



已安装:

  httpd.x86_64 0:2.4.6-95.el7.centos                                                                                   



作为依赖被安装:

  apr.x86_64 0:1.4.8-7.el7            apr-util.x86_64 0:1.5.2-6.el7       httpd-tools.x86_64 0:2.4.6-95.el7.centos     

  mailcap.noarch 0:2.1.41-2.el7 

    

完毕!

下载成功

二、配置网络yum源

配置文件下载

网络源有很多,比如清华、阿里、网易以及其他很多高校都有,这里我们已网易的为例,其他几个网站地址如下

阿里云

http://mirrors.aliyun.com/repo/

网易

http://mirrors.163.com/.help/centos.html

清华

https://mirrors.tuna.tsinghua.edu.cn/help/centos/

进入/etc/yum.repos.d/,执行wget http://mirrors.163.com/.help/CentOS6-Base-163.repo下载网易yum源配置文件

[root@centos01 /]# cd /etc/yum.repos.d/

这里安装的是清华的yum

[root@centos01 yum.repos.d]# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
--2021-08-28 18:16:53--  http://mirrors.163.com/.help/CentOS6-Base-163.repo

正在解析主机 mirrors.163.com (mirrors.163.com)... 183.221.217.21, 183.221.217.23, 183.221.217.22

正在连接 mirrors.163.com (mirrors.163.com)|183.221.217.21|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

长度:2006 (2.0K) [application/octet-stream]

正在保存至: “CentOS6-Base-163.repo”



100%[====================================================================>] 2,006       --.-K/s 用时 0s     



2021-08-28 18:17:08 (165 MB/s) - 已保存 “CentOS6-Base-163.repo” [2006/2006])



[root@centos01 yum.repos.d]# ll

总用量 12

-rw-r--r-- 1 root root 2006 12月  1 2016 CentOS6-Base-163.repo

-rw-r--r-- 1 root root 2006 8月  25 11:54 CentOS6-Base-163.repo_bak

-rw-r--r-- 1 root root  104 8月  28 17:55 Local.repo

执行yun clean all清除缓存

[root@centos01 yum.repos.d]# yum clean all

已加载插件:fastestmirror, langpacks

正在清理软件源: Local-Centos7.5 base extras updates

Cleaning up everything

Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

Cleaning up list of fastest mirrors

[root@centos01 yum.repos.d]#

执行 yum makecache和yum repolist创建缓存并查看当前yum源的可用资源数



[root@centos01 yum.repos.d]#yum makecache

[root@centos01 yum.repos.d]#yum repolist

已加载插件:fastestmirror, langpacks

Determining fastest mirrors

base                                                                                   | 3.6 kB  00:00:00    

extras                                                                                 | 2.9 kB  00:00:00    

updates                                                                                | 2.9 kB  00:00:00    

(1/4): extras/7/x86_64/primary_db                                                      | 242 kB  00:00:05    

(2/4): updates/7/x86_64/primary_db                                                     | 9.6 MB  00:00:06    

(3/4): base/7/x86_64/group_gz                                                          | 153 kB  00:00:15    

(4/4): base/7/x86_64/primary_db                                                        | 6.1 MB  00:00:19    

源标识                                        源名称                                                    状态

base/7/x86_64                                 CentOS-7 - Base - 163.com                                 10,072

extras/7/x86_64                               CentOS-7 - Extras - 163.com                                  498

updates/7/x86_64                              CentOS-7 - Updates - 163.com                               2,579

repolist: 13,149

执行yum install telnet 安装telnet   安装成功表示当前网络YUM源配置成功

[root@centos01 yum.repos.d]# rpm -e telnet-0.17-64.el7.x86_64

[root@centos01 yum.repos.d]# yum install telnet
已加载插件:fastestmirror, langpacks

Loading mirror speeds from cached hostfile

正在解决依赖关系

--> 正在检查事务

---> 软件包 telnet.x86_64.1.0.17-66.el7 将被 安装

--> 解决依赖关系完成



依赖关系解决



==============================================================================================================

 Package                架构                   版本                             源                       大小

==============================================================================================================

正在安装:

 telnet                 x86_64                 1:0.17-66.el7                    updates                  64 k



事务概要

==============================================================================================================

安装  1 软件包



总下载量:64 k

安装大小:113 k

Is this ok [y/d/N]: y

Downloading packages:

telnet-0.17-66.el7.x86_64.rpm                                                          |  64 kB  00:00:15    

Running transaction check

Running transaction test

Transaction test succeeded

Running transaction

警告:RPM 数据库已被非 yum 程序修改。

  正在安装    : 1:telnet-0.17-66.el7.x86_64                                                               1/1

  验证中      : 1:telnet-0.17-66.el7.x86_64                                                               1/1



已安装:

  telnet.x86_64 1:0.17-66.el7                

                                                                

完毕!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值