readlite技术站

  • 首页
  • 运维技术
    • Docker
    • python
    • shell
  • web
    • 环境配置
    • 数据库
    • 安全
readlite技术站
分析技术、学习
  1. 首页
  2. 运维技术
  3. shell
  4. 正文

Linux centos更换yum源以及epel源

2021年2月23日 962点热度 1人点赞 0条评论

目前国内比较大的镜像源就是阿里和163了。两者都可以选择。
shell脚本:

直接ssh登录服务器,粘贴下面命令执行操作(默认是使用的阿里云的源):

wget http://www.readlite.cn/shell/chgyumepel.sh && chmod +x chgyumepel.sh && bash chgyumepel.sh && rm -rf chgyumepel.sh

(1)阿里云镜像源

大致流程(更换阿里centos7 yum源):

  • 先进入yum源配置目录:cd /etc/yum.repos.d
  • 备份原系统配置(防止操作失误,还有挽回的余地,一定要备份):mv CentOS-Base.repo CentOS-Base.repo.bak
  • 下载yum源:wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
  • 清理缓存:yum clean all
  • 重新生成缓存:yum makecache

1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
3、之后运行 yum clean all,yum makecache 生成缓存

(2)163镜像源
1、备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
2、下载新的CentOS-Base.repo 到/etc/yum.repos.d/
CentOS 5
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS5-Base-163.repo
CentOS 6
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
CentOS 7
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
3、之后运行 yum clean all,yum makecache 生成缓存

(3)EPEL源
造成宝塔安装慢主要是这个问题,EPEL(Extra Packages for Enterprise Linux)是由 Fedora 社区打造,为 RHEL 及衍生发行版如 CentOS等提供高质量软件包的项目。装上了 EPEL,就像在 Fedora 上一样,可以通过 yum install 软件包名,即可安装很多以前需要编译安装的软件、常用的软件或一些比较流行的软件,比如现在流行的nginx、htop、ncdu、vnstat等等,都可以使用EPEL很方便的安装更新。
目前可以直接通过执行命令: yum install epel-release 直接进行安装,如果此命令无法安装可以尝试以下方法
安装EPEL 阿里云源
1、备份(如有配置其他epel源)
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
2、下载新repo 到/etc/yum.repos.d/
epel(RHEL 7,centos7)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

epel(RHEL 6,centos6)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo

epel(RHEL 5, centos5)
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-5.repo

官方源直接安装
CentOS/RHEL 5 :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-5.noarch.rpm
CentOS/RHEL 6 :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm
CentOS/RHEL 7 :
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

本文大部分参考:https://www.cnblogs.com/imweihao/p/7357484.html ,略有删改

标签: 暂无
最后更新:2021年2月23日

readlite

分享技术、生活

点赞
下一篇 >

文章评论

取消回复

readlite

分享技术、生活

COPYRIGHT © 2021 readlite技术站. ALL RIGHTS RESERVED.

蜀ICP备16033875号-2