CentOS 7配置网络yum源(阿里)超详细步骤

步骤1、备份yum源文件

1)进入/etc/yum.repos.d/目录,查看是否yum源文件是否存在。

[root@localhost /]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 60
-rw-------. 1 root root 2523 7月  30 2024 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 5月  21 2024 CentOS-CR.repo
-rw-r--r--. 1 root root  649 5月  21 2024 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 5月  21 2024 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 5月  21 2024 CentOS-Media.repo
-rw-r--r--. 1 root root  998 12月 11 2018 CentOS-SCLo-scl.repo.bak
-rw-r--r--. 1 root root  181 7月  31 2024 CentOS-SCLo-scl-rh.repo
-rw-r--r--. 1 root root 1159 7月  31 2024 CentOS-SCLo-scl-rh.repo.bak
-rw-r--r--. 1 root root 1331 5月  21 2024 CentOS-Sources.repo
-rw-r--r--. 1 root root 9454 5月  21 2024 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 5月  21 2024 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 1358 9月   5 2021 epel.repo
-rw-r--r--. 1 root root 1457 9月   5 2021 epel-testing.repo

2)执行mv CentOS-Base.repo CentOS-Base.repo.bak 将原始yum源文件备份至本目录下。

[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@localhost yum.repos.d]# ll
总用量 60
-rw-------. 1 root root 2523 7月  30 2024 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 5月  21 2024 CentOS-CR.repo
-rw-r--r--. 1 root root  649 5月  21 2024 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 5月  21 2024 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 5月  21 2024 CentOS-Media.repo
-rw-r--r--. 1 root root  998 12月 11 2018 CentOS-SCLo-scl.repo.bak
-rw-r--r--. 1 root root  181 7月  31 2024 CentOS-SCLo-scl-rh.repo
-rw-r--r--. 1 root root 1159 7月  31 2024 CentOS-SCLo-scl-rh.repo.bak
-rw-r--r--. 1 root root 1331 5月  21 2024 CentOS-Sources.repo
-rw-r--r--. 1 root root 9454 5月  21 2024 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 5月  21 2024 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 1358 9月   5 2021 epel.repo
-rw-r--r--. 1 root root 1457 9月   5 2021 epel-testing.repo

步骤2、获取阿里yum源配置文件(需要确保虚拟机连接外网正常)。

1)执行 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 下载文件至/etc/yum.repos.d/下。

[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2025-02-18 15:31:35--  http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 116.196.140.238, 116.196.140.235, 116.196.140.231, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|116.196.140.238|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”

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

2025-02-18 15:31:35 (74.1 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])

[root@localhost yum.repos.d]#

2)查看/etc/yum.repos.d/目录下新下载的文件

[root@localhost yum.repos.d]# ll
总用量 64
-rw-r--r--  1 root root 2523 8月   4 2022 CentOS-Base.repo
-rw-------. 1 root root 2523 7月  30 2024 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 5月  21 2024 CentOS-CR.repo
-rw-r--r--. 1 root root  649 5月  21 2024 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 5月  21 2024 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 5月  21 2024 CentOS-Media.repo
-rw-r--r--. 1 root root  998 12月 11 2018 CentOS-SCLo-scl.repo.bak
-rw-r--r--. 1 root root  181 7月  31 2024 CentOS-SCLo-scl-rh.repo
-rw-r--r--. 1 root root 1159 7月  31 2024 CentOS-SCLo-scl-rh.repo.bak
-rw-r--r--. 1 root root 1331 5月  21 2024 CentOS-Sources.repo
-rw-r--r--. 1 root root 9454 5月  21 2024 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 5月  21 2024 CentOS-x86_64-kernel.repo
-rw-r--r--. 1 root root 1358 9月   5 2021 epel.repo
-rw-r--r--. 1 root root 1457 9月   5 2021 epel-testing.repo

3)运行 yum clean all 清除缓存

[root@localhost yum.repos.d]# yum clean all 
已加载插件:fastestmirror
正在清理软件源: base centos-sclo-rh epel extras updates
Cleaning up list of fastest mirrors

4)运行 yum makecache 生成新的缓存

[root@localhost yum.repos.d]# yum makecache
已加载插件:fastestmirror
Determining fastest mirrors
epel/x86_64/metalink                                                                                                         | 5.1 kB  00:00:00     
 * base: mirrors.cloud.aliyuncs.com
 * epel: mirror.math.princeton.edu
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
base                                                                                                                         | 3.6 kB  00:00:00     
centos-sclo-rh                                                                                                               | 3.0 kB  00:00:00     
https://repo.jing.rocks/fedora-buffet/archive/epel/7/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed to connect to 240b:10:f00:1b00::240: 网络不可达"
正在尝试其它镜像。
epel                                                                                                                         | 4.3 kB  00:00:00     
extras                                                                                                                       | 2.9 kB  00:00:00     
updates                                                                                                                      | 2.9 kB  00:00:00     
(1/19): base/7/x86_64/group_gz                                                                                               | 153 kB  00:00:00     
(2/19): base/7/x86_64/other_db                                                                                               | 2.6 MB  00:00:02     
(3/19): centos-sclo-rh/primary_db                                                                                            | 3.4 MB  00:00:05     
epel/x86_64/group              FAILED                                                                             ] 1.4 MB/s | 9.9 MB  00:01:09 ETA 
https://repo.jing.rocks/fedora-buffet/archive/epel/7/x86_64/repodata/9cfdefede5c3cf769a448c2a7d0a6441d6dbd7ba215833153a284c50c76faa56-comps-Everything.x86_64.xml: [Errno 14] curl#7 - "Failed to connect to 240b:10:f00:1b00::240: Network is unreachable"
正在尝试其它镜像。
epel/x86_64/filelists_db       FAILED                                          
https://repo.jing.rocks/fedora-buffet/archive/epel/7/x86_64/repodata/1e0f3b42efd8b5d54a6aa9feb1f03c7de2bb414b92268c3db5965bd38648b2da-filelists.sqlite.gz: [Errno 14] curl#7 - "Failed to connect to 240b:10:f00:1b00::240: Network is unreachable"
正在尝试其它镜像。
(4/19): centos-sclo-rh/other_db                                                                                              | 1.6 MB  00:00:02     
(5/19): epel/x86_64/prestodelta                                                                                              |  592 B  00:00:00     
base/7/x86_64/filelists_db     FAILED                                                                             ] 1.3 MB/s |  16 MB  00:01:10 ETA 
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/d6d94c7d406fe7ad4902a97104b39a0d8299451832a97f31d71653ba982c955b-filelists.sqlite.bz2: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
正在尝试其它镜像。
base/7/x86_64/primary_db       FAILED                                          
http://mirrors.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
正在尝试其它镜像。
(6/19): extras/7/x86_64/filelists_db                                                                                         | 305 kB  00:00:00     
(7/19): extras/7/x86_64/primary_db                                                                                           | 253 kB  00:00:00     
(8/19): epel/x86_64/updateinfo                                                                                               | 1.0 MB  00:00:05     
(9/19): extras/7/x86_64/other_db                                                                                             | 154 kB  00:00:00     
(10/19): epel/x86_64/other_db                                                                                                | 4.1 MB  00:00:02     
(11/19): centos-sclo-rh/filelists_db                                                                                         |  12 MB  00:00:17     
(12/19): updates/7/x86_64/filelists_db                                                                                       |  15 MB  00:00:15     
(13/19): epel/x86_64/group                                                                                                   | 399 kB  00:00:00     
(14/19): updates/7/x86_64/other_db                                                                                           | 1.6 MB  00:00:01     
(15/19): epel/x86_64/filelists_db                                                                                            |  15 MB  00:00:02     
(16/19): base/7/x86_64/primary_db                                                                                            | 6.1 MB  00:00:06     
(17/19): base/7/x86_64/filelists_db                                                                                          | 7.2 MB  00:00:07     
(18/19): updates/7/x86_64/primary_db                                                                                         |  27 MB  00:00:28     
(19/19): epel/x86_64/primary_db                                                                                              | 8.7 MB  00:00:34     
元数据缓存已建立
[root@localhost yum.repos.d]#

5)运行 yum repolist all 查看yum软件仓库

[root@localhost yum.repos.d]# yum repolist all
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * epel: mirror.math.princeton.edu
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
源标识
base/7/x86_64                                        CentOS-7 - Base - mirrors.aliyun.com                                               启用: 10,072
base-debuginfo/x86_64                                CentOS-7 - Debuginfo                                                               禁用
base-source/7                                        CentOS-7 - Base Sources                                                            禁用
c7-media                                             CentOS-7 - Media                                                                   禁用
centos-kernel/7/x86_64                               CentOS LTS Kernels for x86_64                                                      禁用
centos-kernel-experimental/7/x86_64                  CentOS Experimental Kernels for x86_64                                             禁用
centos-sclo-rh                                       CentOS-7 - SCLo rh                                                                 启用:  8,170
centosplus/7/x86_64                                  CentOS-7 - Plus - mirrors.aliyun.com                                               禁用
centosplus-source/7                                  CentOS-7 - Plus Sources                                                            禁用
contrib/7/x86_64                                     CentOS-7 - Contrib - mirrors.aliyun.com                                            禁用
cr/7/x86_64                                          CentOS-7 - cr                                                                      禁用
epel/x86_64                                          Extra Packages for Enterprise Linux 7 - x86_64                                     启用: 13,791
epel-debuginfo/x86_64                                Extra Packages for Enterprise Linux 7 - x86_64 - Debug                             禁用
epel-source/x86_64                                   Extra Packages for Enterprise Linux 7 - x86_64 - Source                            禁用
epel-testing/x86_64                                  Extra Packages for Enterprise Linux 7 - Testing - x86_64                           禁用
epel-testing-debuginfo/x86_64                        Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Debug                   禁用
epel-testing-source/x86_64                           Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Source                  禁用
extras/7/x86_64                                      CentOS-7 - Extras - mirrors.aliyun.com                                             启用:    526
extras-source/7                                      CentOS-7 - Extras Sources                                                          禁用
fasttrack/7/x86_64                                   CentOS-7 - fasttrack                                                               禁用
updates/7/x86_64                                     CentOS-7 - Updates - mirrors.aliyun.com                                            启用:  6,173
updates-source/7                                     CentOS-7 - Updates Sources                                                         禁用
repolist: 38,732

6)执行 yum install -y ntp 测试安装

[root@localhost yum.repos.d]# yum install -y ntp
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.cloud.aliyuncs.com
 * epel: mirror.math.princeton.edu
 * extras: mirrors.cloud.aliyuncs.com
 * updates: mirrors.cloud.aliyuncs.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 ntp.x86_64.0.4.2.6p5-29.el7.centos.2 将被 安装
--> 正在处理依赖关系 ntpdate = 4.2.6p5-29.el7.centos.2,它被软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 需要
--> 正在处理依赖关系 libopts.so.25()(64bit),它被软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 需要
--> 正在检查事务
---> 软件包 autogen-libopts.x86_64.0.5.18-5.el7 将被 安装
---> 软件包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos.2 将被 安装
--> 解决依赖关系完成

依赖关系解决

====================================================================================================================================================
 Package                               架构                         版本                                           源                          大小
====================================================================================================================================================
正在安装:
 ntp                                   x86_64                       4.2.6p5-29.el7.centos.2                        base                       549 k
为依赖而安装:
 autogen-libopts                       x86_64                       5.18-5.el7                                     base                        66 k
 ntpdate                               x86_64                       4.2.6p5-29.el7.centos.2                        base                        87 k

事务概要
====================================================================================================================================================
安装  1 软件包 (+2 依赖软件包)

总下载量:701 k
安装大小:1.6 M
Downloading packages:
(1/3): autogen-libopts-5.18-5.el7.x86_64.rpm                                                                                 |  66 kB  00:00:00     
(2/3): ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm                                                                            |  87 kB  00:00:00     
(3/3): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm                                                                                | 549 kB  00:00:00     
----------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                929 kB/s | 701 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : autogen-libopts-5.18-5.el7.x86_64                                                                                               1/3 
  正在安装    : ntpdate-4.2.6p5-29.el7.centos.2.x86_64                                                                                          2/3 
  正在安装    : ntp-4.2.6p5-29.el7.centos.2.x86_64                                                                                              3/3 
  验证中      : ntpdate-4.2.6p5-29.el7.centos.2.x86_64                                                                                          1/3 
  验证中      : ntp-4.2.6p5-29.el7.centos.2.x86_64                                                                                              2/3 
  验证中      : autogen-libopts-5.18-5.el7.x86_64                                                                                               3/3 

已安装:
  ntp.x86_64 0:4.2.6p5-29.el7.centos.2                                                                                                              

作为依赖被安装:
  autogen-libopts.x86_64 0:5.18-5.el7                                    ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2                                   

完毕!
[root@localhost yum.repos.d]#

1.查看系统本身存在的版本 rpm -qa | grep yum 2.卸载centos7上存在的yum安装包 rpm -e 包 --nodeps 3.下载yum包(http://mirrors.163.com/centos/7/os/x86_64/Packages/) yum-metadata-parser-1.1.4-10.el7.x86_64 PackageKit-yum-1.0.7-6.el7.centos.x86_64 yum-utils-1.1.31-40.el7.noarch 下方两个一起装 yum-plugin-fastestmirror-1.1.31-40.el7.noarch yum-langpacks-0.4.2-7.el7.noarch yum-3.4.3-150.el7.centos.noarch yum-rhn-plugin-2.0.1-6.el7.noarch 4.安装yum包 rpm -ivh yum* 5.创建配置文件(/etc/yum.repos.d/CentOS-Base.repo) vi /etc/yum.repos.d/CentOS-Base.repo [base] name=CentOS-$releasever - Base - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=os baseurl=http://mirrors.163.com/centos/(系统版本号)7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/7/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch;=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/7/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 每一个baseurl的centos后都改成自己系统的版本号 6.执行命令 yum clean all yum makecache yum install telnet
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值