MENU

CentOS7更换系统软件源

June 7, 2018 • Read: 1340 • 笔记阅读设置

CentOS7更换系统软件源

tags: 网站


简介

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

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

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

赞美TUNA!

清华大学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软件源

将CentOS7系统软件源(yum软件仓库)更换为清华大学镜像源。

清理旧仓库

# 清除缓存
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

按insert进入编辑模式,粘贴以下内容(不可遗漏任何字符)。完成后按esc键,输入 :wq 保存。

# 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:///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:///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:///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:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

重建缓存


# 建立缓存
yum makecache

# 重新安装EPEL仓库
yum install epel-release