最新CentOS7更改yum源为国内源

yum源

yum是redhat和centos的软件包管理工具,安装软件包时可以在网上远程仓库或者本地自动下载所有依赖包

对于yum仓库来说,有三种搭建方式,分别是本地yum仓库的搭建、网络yum源的搭建和自建yum源仓库。对于没有外网的用户来说,本地yum仓库的搭建是一种非常不错的选择,因为几乎在所有的linux安装包中都有一套yum仓库,我们只需要简单配置就能直接使用。

源的配置文件均位于/etc/yum.repos.d目录

centos7 下完整镜像自带的yum源如下图

在这里插入图片描述

常用yum 命令:

yum repolist: 列出所有启用的源

yum repolist disabled: 列出所有禁用的源

centos

CentOS开头的几个文件就是支持centos的yum源文件

我们通常修改CentOS-Base.repo来加速yum源

因为某些原因(大家都知道),通过国外镜像站下载软件的速度真是让人感动的流鼻涕

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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
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
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


  1. 原文件改名,用于恢复 == 建议一定要执行,用于yum文件修改后无法访问yum源的情况 ==

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

  1. 获取国内镜像站CentOS-Base.repo

阿里云


#CentOS7:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

已更新为:

#CentOS7:
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

163


#CentOS7:
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

  1. 重新加载yum源

清除yum缓存

yum clean all  

生成yum缓存

yum makecache     

当然也可以手动修改CentOS-Base.repo来改变yum源

epel

EPEL(Extra Packages for Enterprise Linux)是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS等提供高质量软件包的项目,其为EL6或EL7提供重建的Fedora组件,并且不会替换base中的包。装上了 EPEL就可以通过 yum install 软件包名,来安装很多以前需要编译安装的软件、常用的软件或一些比较流行的软件,比如现在流行的nginxhtopncdu 等等

直接通过命令安装epel:

 
 yum -y install epel-release
 

阿里云源获取epel源的最新仓库文件

epel(RHEL 7)


wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

epel(RHEL 6)


wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

epel(RHEL 5)


wget -O /etc/yum.repos.d/epel.repohttp://mirrors.aliyun.com/repo/epel-5.repo

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值