CentOS8 配置阿里云的yum源

2022-06-26  本文已影响0人  木子的毛线

1 检查是否有yum 安装

如果没有安装需要先安装yum,可百度搜索

# 查看是否安装yum
rpm -qa | grep yum

# 运行结果:表示已安装
yum-4.2.17-6.el8.noarch

2 备份yum配置文件

yum配置文件目录为:/etc/yum.repos.d/

#进入yum配置文件目录
cd /etc/yum.repos.d/
# 目录文件,可能不同系统配置源文件的数量不一致,是正常的
ls
CentOS-AppStream.repo  CentOS-centosplus.repo  CentOS-Devel.repo      CentOS-HA.repo          CentOS-Sources.repo                       mysql-community.repo
CentOS-Base.repo       CentOS-CR.repo          CentOS-Extras.repo     CentOS-Media.repo       CentOS-Vault.repo                         mysql-community-source.repo
CentOS-Base.repo.old   CentOS-Debuginfo.repo   CentOS-fasttrack.repo  CentOS-PowerTools.repo  mysql-community-release-el7-5.noarch.rpm

备份所有的配置源

#在/etc/yum.repos.d/目录下创建一个backup目录
mkdir backup

# 复制所有的repo文件到backup目录
 mv *.repo  backup/

3 下载阿里云的yum源配置文件

可以通过wget命令下载阿里云的yum源

[root@test239 ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
--2022-06-27 09:01:35--  http://mirrors.aliyun.com/repo/Centos-8.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 219.159.26.112, 101.75.234.99, 119.188.213.248, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|219.159.26.112|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2600 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

/etc/yum.repos.d/CentOS-Base.repo           100%[========================================================================================>]   2.54K  --.-KB/s    in 0.02s   

2022-06-27 09:01:35 (143 KB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2600/2600]

[root@test239 ~]#  wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
--2022-06-27 09:01:45--  http://mirrors.aliyun.com/repo/Centos-8.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 219.159.26.112, 219.159.26.114, 219.159.26.117, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|219.159.26.112|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2600 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’

/etc/yum.repos.d/CentOS-Base.repo           100%[========================================================================================>]   2.54K  --.-KB/s    in 0.009s  

2022-06-27 09:01:45 (286 KB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2600/2600]

这时候/etc/yum.repos.d/目录下会有一个CentOS-Base.repo文件

[root@test239 yum.repos.d]# ll
total 20
drwxr-xr-x. 2 root root 4096 Jun 27 08:55 backup
-rw-r--r--. 1 root root 2600 Feb 11 10:14 CentOS-Base.repo

4 修改yum源配置文件

进入CentOS-Base.repo文件

[root@test239 yum.repos.d]# vim  CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
#failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/

在vim中进入命令模式(英文输入的前提下按ESC,然后再按冒号,即可进入)
替换阿里云的源

%s/mirrors.cloud.aliyuncs.com/mirrors.aliyun.com/g

再次进入命令模式,继续替换

%s/$releasever/$releasever-stream/g

保存,退出:进入命令模式,输入wq,回车

5 更新yum源的配置文件,使配置生效

执行下面两个命令:
yum clean all
yum makecache

[root@test239 yum.repos.d]# yum clean all
34 files removed
[root@test239 yum.repos.d]# yum makecache
CentOS-8 - Base - mirrors.aliyun.com                                                                                                         448 kB/s | 4.6 MB     00:10    
CentOS-8 - Extras - mirrors.aliyun.com                                                                                                        25 kB/s |  10 kB     00:00    
CentOS-8 - AppStream - mirrors.aliyun.com                                                                                                    282 kB/s | 8.4 MB     00:30    
Metadata cache created.
[root@test239 yum.repos.d]# 

搞定,结束

上一篇下一篇

猜你喜欢

热点阅读