CentOS更换系统软件源(yum软件仓库)

介绍:

少数操作系统被替换过系统软件源(如VPS服务商预装的CentOS7),由于软件源的更新快慢参差不齐,仓库中可能缺少某些软件包,可更换系统软件源解决。

推荐清华大学TUNA协会创建并维护的清华大学镜像源,是CentOS的官方镜像源之一,更新速度很快。而且清华大学作为中国的核心网络节点,国内外的访问速度都是很快的。

清华大学开源镜像站内容异常丰富,基本主流的开源项目在这里都能找到镜像源,因此国内许多大学的镜像站也以清华大学镜像源作为源站来进行同步。

清华大学TUNA协会主页:

https://tuna.moe

清华大学开源镜像站:

安装操作系统时选择下方的网址进行获取密钥
https://mirrors.tuna.tsinghua.edu.cn(双栈解析,自动识别)。
https://mirrors4.tuna.tsinghua.edu.cn(只解析 IPv4)。
https://mirrors6.tuna.tsinghua.edu.cn(只解析 IPv6)。

更换CentOS7软件源:

百度网盘清华大学yum源密钥链接:
提取码:2tf6

清理旧仓库:

# 清除缓存
yum clean all
sudo rm -rf /var/cache/yum
 
# 卸载epel仓库
yum remove epel-release
 
# 删除所有旧仓库文件
# 注意,如有其它仓库文件请自行重装或选择性删除
rm -rf /etc/yum.repos.d/*

建立仓库:

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
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///root/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///root/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///root/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///root/etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

重建缓存

# 建立缓存
yum makecache
 
# 重新安装原有的EPEL仓库
yum install epel-release

查看一下软件包源:

yum repolist

在这里插入图片描述

二、部署成阿里云提供的软件仓库:

1.先备份原有的repo仓库:

sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2.运行以下任一命令添加CentOS 7软件源。

sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3.运行以下命令生成本地缓存,加快搜索、安装软件的速度

sudo yum clean all && sudo yum makecache
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值