当前位置: 代码网 > 移动>阿里 > CentOS 7.9 快速更换 阿里云源教程

CentOS 7.9 快速更换 阿里云源教程

2024年08月03日 阿里 我要评论
总结。

centos 7.9 更换源教程

总结

# 下载 wget
yum -y install wget
# 备份 yum 源
mv /etc/yum.repos.d/centos-base.repo /etc/yum.repos.d/centos-base.repo.bak
# 下载阿里云的yum源到 /etc/yum.repos.d/
# 此处以 centos 7 为例,如果是其它版本或者系统的话,请看:http://mirrors.aliyun.com/repo/
wget -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/repo/centos-7.repo
# 清除缓存
yum clean all
# 更新本地 yum 缓存
yum makecache
# 更新 yum 中的所有软件包
yum -y update 

以下是步骤!!

查看版本

cat /etc/redhat-release

https://blog.csdn.net/xiaoxinyayaya/article/details/139620079

centos 7是一个使用比较广泛,也比较流行的linux发行版,但是默认的yum源常常无法满足我们的需求。以下是以阿里源为例的详细换源教程。

1、备份原有源文件

备份原有的源文件,以备不时之需。命令如下:

sudo cp /etc/yum.repos.d/centos-base.repo /etc/yum.repos.d/centos-base.repo.backup

2、安装依赖工具

sudo yum install -y wget

3、更换源

下载新的源文件,指令如下:

sudo wget -o /etc/yum.repos.d/centos-base.repo https://mirrors.aliyun.com/repo/centos-7.repo

出现问题 需要增加dns解析!

在这里插入图片描述

输入

vim /etc/resolv.conf

添加dns地址:

nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 223.5.5.5
nameserver 223.6.6.6

当然不想下载,也可以采取如下方法:

sudo vi /etc/yum.repos.d/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=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
 
#released updates 
[updates]
name=centos-$releasever - updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
 
#additional packages that may be useful
[extras]
name=centos-$releasever - extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=centos-$releasever - plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
 
#contrib - packages by centos users
[contrib]
name=centos-$releasever - contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7

保存退出,操作如下:

1、按esc
2、输入:wq!
3、按enter

4、生成缓存

配置新的源后,需要清理yum的旧缓存并生成新缓存,指令如下:

sudo yum clean all
sudo yum makecache

5、检查新源

输入以下指令:

yum repolist

如图:

img

如果输出中包含了阿里源,则证明已换源成功。

6、测试新源

我们随便搜索一个软件包,比如nginx:

yum search nginx

7、其他源

如果想使用其他的源,替换对应的链接或内容即可。

网易源:

http://mirrors.163.com/.help/centos7-base-163.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 - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/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/$releasever/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/$releasever/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=centos-$releasever - plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/rpm-gpg-key-centos-7

若还需其他源,请自行搜集。

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com