切换国内yum源
- 一、备份现有YUM源
- 二、下载新的YUM源配置文件
- 三、先清理YUM缓存再生成
- 四、测试新的YUM源
- 五、重启系统服务(生效可以不重启)可选
首先,切换国内YUM源的具体步骤取决于您使用的Linux发行版和当前的YUM源配置。以下是一般步骤,适用于大多数基于Red Hat的发行版,如CentOS和Fedora:
一、备份现有YUM源
在修改YUM源之前,建议先备份现有的YUM源配置文件,以防万一出现错误导致无法正常使用YUM
[root@hcss-ecs-c0a1 nginx]# mv /etc/yum.repos.d/CentOS-Linux-BaseOS.repo /etc/yum.repos.d/CentOS-Linux-BaseOS.repo.bak
二、下载新的YUM源配置文件
从官方网站或其他可靠的源下载新的YUM源配置文件。例如,如果您想要使用阿里云的YUM源。这里使用的是华为YUM源,因为我使用的是华为荣耀云服务,更新时相对较快。小伙伴们可以根据实际情况选择。
[root@hcss-ecs-c0a1 nginx]# wget -O /etc/yum.repos.d/CentOS-Linux-BaseOS.repo https://mirrors.huaweicloud.com/repository/conf/CentOS-8-anon.repo
--2024-06-23 14:50:33-- https://mirrors.huaweicloud.com/repository/conf/CentOS-8-anon.repo
Resolving mirrors.huaweicloud.com (mirrors.huaweicloud.com)... 124.70.125.167, 124.70.125.153
Connecting to mirrors.huaweicloud.com (mirrors.huaweicloud.com)|124.70.125.167|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Linux-BaseOS.repo’
/etc/yum.repos.d/CentOS-Linux-BaseOS.repo [ <=> ] 2.21K --.-KB/s in 0s
2024-06-23 14:50:33 (49.6 MB/s) - ‘/etc/yum.repos.d/CentOS-Linux-BaseOS.repo’ saved [2263]
[root@hcss-ecs-c0a1 nginx]# cat /etc/yum.repos.d/CentOS-Linux-BaseOS.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.
#
#
[BaseOS]
name=CentOS-$releasever - Base - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-Official
#released updates
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-vault/8.5.2111/AppStream/$basearch/os/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=PowerTools&infra=$infra
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-vault/8.5.2111/extras/$basearch/os/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.huaweicloud.com
baseurl=https://mirrors.huaweicloud.com/centos-vault/8.5.2111/centosplus/$basearch/os/
#mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=https://mirrors.huaweicloud.com/centos/RPM-GPG-KEY-CentOS-Official
-O:这是一个选项,它告诉wget将下载的文件输出到指定的文件名。在这里,-O后面跟着的路径是/etc/yum.repos.d/CentOS-Base.repo,这是YUM仓库配置文件的路径
需要其他源的可以去https://mirrors.huaweicloud.com/repository找,很方便
三、先清理YUM缓存再生成
[root@hcss-ecs-c0a1 nginx]# yum clean all
6 files removed
[root@hcss-ecs-c0a1 nginx]# yum makecache
CentOS-8 - Base - mirrors.huaweicloud.com 3.3 MB/s | 4.6 MB 00:01
CentOS-8 - AppStream - mirrors.huaweicloud.com 664 kB/s | 8.4 MB 00:13
CentOS-8 - PowerTools - mirrors.huaweicloud.com 800 kB/s | 2.3 MB 00:02
CentOS-8 - Extras - mirrors.huaweicloud.com 35 kB/s | 10 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64
Extra Packages for Enterprise Linux Modular 8 - x86_64
Metadata cache created.
[root@hcss-ecs-c0a1 nginx]#
四、测试新的YUM源
[root@hcss-ecs-c0a1 nginx]# yum install epel-release
Last metadata expiration check: 0:12:18 ago on Sun 23 Jun 2024 03:05:27 PM CST.
Package epel-release-8-19.el8.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
[root@hcss-ecs-c0a1 nginx]#
如果安装成功,说明新的YUM源配置正确。
五、重启系统服务(生效可以不重启)可选
systemctl restart network.service
systemctl restart yum.service
提示 |
---|
本人以抱着学习的态度去分享,以上内容如有雷同,不胜荣幸!如有不足,欢迎评论留言! |