赞
踩
#1、进入官方本地yum源相关的配置文件目录
cd /etc/yum.repos.d/
#2、看/etc/yum.repos.d/目录下配置文件信息
ll
#3、创建备份文件夹,用于存放查到的配置文件
mkdir repo-bak
#4、将所有以 .repo 结尾的文件移动到 repo-bak 文件夹中(备份查到的配置文件)
mv *.repo repo-bak/
#5、查看备份操作后 /etc/yum.repos.d/目录 的情况
ll
#6、创建本地yum源的配置文件
touch local.repo
#7、在local.repo文件中填写配置信息
echo -e '[local]\nname=local\nbaseurl=file:///mnt\nenabled=1\ngpgcheck=0' >local.repo
#执行后local.repo文件中内容如下
#其中
#[ local ]:代表源的名字,中括号要存在,里面的名字可以随便取,但是不能有两个相同的yum源名称;
#name:只是说明一下这个yum源的意义而已,重要性不高;
#baseurl=:这个最重要,后面接的是yum源的实际地址,这里代表文件目录为mnt;
#enable=1:就是让这个yum源被启动,如果不想启用可以使用enable=0;
#gpgcheck=0:0代表不查看RPM文件内的数字签名,如果设置为“1”则代表需要查看RPM的数字签名。
#gpgkey=:后面跟着RPM的数字签名的公钥文件所在位置,使用默认值即可。
#8、挂载镜像到 mnt 文件下
mount /dev/cdrom /mnt
执行此操作前要求,虚拟机满足以下状态。
执行后续操作(第10步骤)时可能会出现失败的情况。如下图
尽管镜像状态显示已链接,但虚拟机中还是提示未挂载(yum的运行的repolist为0,如下图,可通过第11步骤查看yum的运行信息)
出现以上的原因是 mnt 文件下无以下配置信息(及未满足条件,步骤8挂载失败),如下图,需要再次执行挂载命令
mount /dev/cdrom /mnt
#9、清理yum 缓存
yum clean all
#10、查看yum的运行信息
yum repolist
#11、更新yum
yum makecache
#1、卸载本地镜像 ( umount 命令后跟随的是本地指定的镜像目录 mnt)
umount /mnt
#1、确保自身能链接互联网
ping www.baidu.com
#2、下载阿里云镜像到本机/etc/yum.repos.d/
目录下
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者直接在/etc/yum.repos.d/
目录下新建文件Centos-7.repo,填入以下信息(以CentOS7为例)
# 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 - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#3、清理yum 缓存
yum clean all
#4、查看yum的运行信息
yum repolist
#5、更新yum
yum makecache
#1、阿里源和本地源同时存在时,要考虑两个yum源的优先级,是本地源优先还是阿里源优先。
使用yum提供的插件yum-plugin-priorities.noarch设置两个文件的优先级
,安装yum-plugin-priorities.noarch
yum install -y yum-plugin-priorities.noarch
#2、查看插件是否启用
cat /etc/yum/pluginconf.d/priorities.conf
#3、修改两个yum源配置文件,文件尾部增加字段priority ,priority的值越小优先级越高,此次配置本地源优先级高于阿里源
修改本地yum源
vi local.repo
修改阿里yum源
vi Centos7.repo
#4、检查所有仓库包
yum repolist all
#4、安装本地源内没有的程序进行测试是否能自动选择阿里源
(1)首先查出本地没有的源文件,若没有则执行(2)
ls /mnt/Packages | grep net-tools
若 /mnt 下没有 /Packages 文件夹说明本地伟挂载镜像需执行
mount /dev/cdrom /mnt
(2)安装检查
yum install -y net-tools
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。