配置CentOS8 yum镜像源

配置yum镜像主要修改三个文件:

文件位置:/etc/yum.repos.d/

CentOS-Linux-AppStream.repo
配置CentOS8 yum镜像源_第1张图片

将上面的两段代码注释掉,之后添加清华镜
#清华云镜像地址

baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/virt/$basearch/advanced-virtualization/

#阿里云镜像地址

baseurl=https://mirrors.aliyun.com/centos-vault//$contentdir/$releasever/AppStream/$basearch/os/

根据以上步骤将后两个文件也进行修改

CentOS-Linux-BaseOS.repo
CentOS-Linux-Extras.repo

修改完成后执行更新缓存


yum clean all     # 清除系统所有的yum缓存
yum repolist
yum grouplist
yum makecache     # 生成yum缓存

centos8更换阿里云的sh脚本

#!bin/bash

#[appstream]
if cat '/etc/yum.repos.d/CentOS-Linux-AppStream.repo' | grep 'baseurl=https://mirrors.aliyun.com/centos-vault/$contentdir/$releasever/AppStream/$basearch/os/' > /dev/null
	then
		echo "warning AppStream  Mirror exists"
	else
		sed -i '15i baseurl=https://mirrors.aliyun.com/centos-vault/$contentdir/$releasever/AppStream/$basearch/os/' /etc/yum.repos.d/CentOS-Linux-AppStream.repo
		cat -n /etc/yum.repos.d/CentOS-Linux-AppStream.repo |grep -v "#"
		echo "Configuration succeeded!" 
	fi

#[baseos]
if cat '/etc/yum.repos.d/CentOS-Linux-BaseOS.repo' | grep 'baseurl=https://mirrors.aliyun.com/centos-vault/$contentdir/$releasever/BaseOS/$basearch/os/' > /dev/null
	then
		echo "warning BaseOS Mirror exists"
	else
		sed -i '15i baseurl=https://mirrors.aliyun.com/centos-vault/$contentdir/$releasever/BaseOS/$basearch/os/' /etc/yum.repos.d/CentOS-Linux-BaseOS.repo
		cat -n /etc/yum.repos.d/CentOS-Linux-BaseOS.repo |grep -v "#"
		echo "Configuration succeeded!"
	fi

#[extras]
if cat '/etc/yum.repos.d/CentOS-Linux-Extras.repo' | grep 'baseurl=https://mirrors.aliyun.com/centos-vault/$contentdir/$releasever/extras/$basearch/os/' > /dev/null
	then
		echo 'warning Extras Mirror exists'
	else
		sed -i '15i baseurl=https://mirrors.aliyun.com/centos-vault/$contentdir/$releasever/extras/$basearch/os/' /etc/yum.repos.d/CentOS-Linux-Extras.repo
		cat -n /etc/yum.repos.d/CentOS-Linux-Extras.repo |grep -v "#"
		echo 'Configuration succeeded!'
	fi

yum clean all
yum makecache

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