给CentOS-7配置yum源(此处介绍网络yum源配置)

给CentOS-7配置yum源(此处介绍网络yum源配置)

 1、备份原始yum源
       cd   /etc/yum.repos.d
       cp  CentOS-Base.rpeo   CentOS-Base.repo-20220705.bak
 2、配置CentOS的DNS:
       vim   /etc/resolv.conf
       nameserver   114.114.114.114      //国内dns
       nameserver   8.8.8.8              //国外dns
 3、下载yum文件,替代原始yum源:
    执行命令 yum -y install wget
       (1)网易yum源:
            wget -O /etc/yum.repos.d/CentOS-Base.repo    http://mirrors.163.com/.help/CentOS7-Base-163.repo
            yum clean all          //清除缓存
            yum   makecache       //生成缓存
            解析:wget -o,使用“-o”参数来指定一个文件名
       (2)阿里云yum源:
            wget   -O   /etc/yum.repos.d/CentOS-Base.repo    http://mirrors.aliyun.com/repo/Centos-7.repo
            yum   clean  all
            yum   makecache
 4、获取阿里centos7的epel-repo
            wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo
            yum   clean  all
            yum   makecache

命令:wget -O /etc/yum.repos.d/epel-7.repo https://mirrors.aliyun.com/repo/epel-7.repo
在执行“yum makecache”时,若出现报错如下所示:
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6d0c3a488c282fe537794b5946b01e28c7f44db79097bb06826e1c0c88bad5ef-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error" Trying other mirror.
则执行下列操作:
1、修改CentOS-Base.repo文件

vi /etc/yum.repos.d/CentOS-Base.repo

2、使用全局替换命令,将该文件中$releasever全部改成7

:%s/$releasever/7/g

3、清空并生成缓存

yum clean all
yum makecache

你可能感兴趣的:(Linux,centos,linux,服务器)