赞
踩
实验时需要开启好几台虚拟机(最小化安装),将镜像挂载直接配置yum源,不用将iso拷贝到虚拟机中,减少磁盘占用;
检查是否虚拟机挂载镜像
检查挂载目录是否挂载
查看该目录下是否含有其他文件,如果没有创建目录cdrom,再次将/dev/sr0挂载到该目录下
[root@localhost ~]# cd /media/
[root@localhost media]# ls
cdrom
在其他目录下创建cdrom目录挂载:
[root@localhost ~]# mount -o loop /dev/sr0 /mnt/cdrom
再次查看是否挂载成功:
[root@localhost media]# df
/dev/sr0 3654720 3654720 0 100% /media/cdrom
/dev/loop0 3654720 3654720 0 100% /mnt/cdrom
配置yum源:
[root@localhost media]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# cat yum.repo
[rhel7.0]
name=redhat7.0
baseurl=file:///mnt/cdrom
enable=1 ###1表示启用,0表示不启用
gpgkey=1 ###是否进行gpg校验,1表示检查,0表示不检查
gpgkey=file:///mnt/cdrom/RPM-GPG-KEY-redhat-release
###定义检查gpgkey的地址
查看是否配置完成:
[root@localhost yum.repos.d]# yum clean all
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Cleaning repos: rhel7.0
Cleaning up everything
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: langpacks, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
rhel7.0 | 4.1 kB 00:00
(1/2): rhel7.0/group_gz | 134 kB 00:00
(2/2): rhel7.0/primary_db | 3.4 MB 00:00
repo id repo name status
rhel7.0 redhat7.0 4,305
repolist: 4,305
redhat 默认自带的 yum 源需要注册,才能更新。不花钱更新,需要替换掉redhat的yum源。
检查系统自带的yum包
[root@localhost yum.repos.d]# rpm -qa | grep yum
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-utils-1.1.31-24.el7.noarch
yum-langpacks-0.4.2-3.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-3.4.3-118.el7.noarch
yum-rhn-plugin-2.0.1-4.el7.noarch
[root@localhost yum.repos.d]# rpm -qa | grep yum | xargs rpm -e --nodeps ###卸载系统自带的yum包,--nodeps不检查依赖关系
[root@localhost yum.repos.d]# rpm -qa | grep yum
[root@localhost yum]# rpm -qa | grep python-urlgrabber
python-urlgrabber-3.10-4.el7.noarch
[root@localhost yum]# rpm -qa | grep python-urlgrabber | xargs rpm -e --nodeps[root@localhost yum]# rpm -qa | grep python-urlgrabber
阿里云镜像下载卸载软件
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-158.el7.centos.noarch.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-45.el7.noarch.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm
解决报错
rpm -ivh *.rpm时报错,rpm包的版本太低需要进行升级
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-python-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-libs-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/rpm-build-libs-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# ls
rpm-4.11.3-32.el7.x86_64.rpm
rpm-build-libs-4.11.3-32.el7.x86_64.rpm
rpm-libs-4.11.3-32.el7.x86_64.rpm
rpm-python-4.11.3-32.el7.x86_64.rpm
[root@localhost yum]# rpm -Uvh rpm-4.11.3-32.el7.x86_64.rpm rpm-libs-4.11.3-32.el7.x86_64.rpm rpm-python-4.11.3-32.el7.x86_64.rpm rpm-build-libs-4.11.3-32.el7.x86_64.rpm
Preparing... ################################# [100%]
Updating / installing...
1:rpm-libs-4.11.3-32.el7 ################################# [ 13%]
2:rpm-4.11.3-32.el7 ################################# [ 25%]
3:rpm-build-libs-4.11.3-32.el7 ################################# [ 38%]
4:rpm-python-4.11.3-32.el7 ################################# [ 50%]
Cleaning up / removing...
5:rpm-python-4.11.1-16.el7 ################################# [ 63%]
6:rpm-build-libs-4.11.1-16.el7 ################################# [ 75%]
7:rpm-libs-4.11.1-16.el7 ################################# [ 88%]
8:rpm-4.11.1-16.el7 ################################# [100%]
[root@localhost yum]# rpm -qa | grep rpm
rpm-4.11.3-32.el7.x86_64
rpm-python-4.11.3-32.el7.x86_64
rpm-libs-4.11.3-32.el7.x86_64
python-deltarpm-3.6-3.el7.x86_64
rpm-build-libs-4.11.3-32.el7.x86_64
安装下载的阿里云yum包
[root@localhost yum]# rpm -ivh yum-3.4.3-158.el7.centos.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-45.el7.noarch.rpm yum-utils-1.1.31-45.el7.noarch.rpm
Preparing... ################################# [100%]
Updating / installing...
1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%]
2:yum-plugin-fastestmirror-1.1.31-4################################# [ 50%]
3:yum-3.4.3-158.el7.centos ################################# [ 75%]
4:yum-utils-1.1.31-45.el7 ################################# [100%]
配置yum源文件
###查看yum.repo.d目录下是否含有yum源配置文件,如果有备份源文件;
[root@localhost yum]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
###下载阿里云的centos镜像文件
[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost yum.repos.d]# ls
CentOS-Base.repo
###修改yum源配置文件,将$releasever替换为7版本(这个看自己的服务器系统),enable的值修改为0;
[root@localhost yum.repos.d]# sed -i 's/$releasever/7/g' CentOS-Base.repo
[root@localhost yum.repos.d]# sed -i 's/enabled=1/enabled=0/g' CentOS-Base.repo
yum源
# 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-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
http://mirrors.aliyuncs.com/centos/7/os/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/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-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/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-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/
http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/
http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
清除缓存和缓存元数据
[root@localhost yum.repos.d]# yum clean all
[root@localhost yum.repos.d]# yum makecache
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。