一、centos7配置yum源
yum源分为本地yum源和网络yum源
1、配置本地yum源
步骤一:在centos虚拟机中挂载光盘
1.创建挂载点目录
[root@localhost ~]# mkdir /mnt/cdrom
[root@localhost ~]# df /mnt/cdrom
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda3 39517336 7718416 31798920 20% /
2.挂载光盘
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom
mount: /dev/sr0 写保护,将以只读方式挂载
3.查看挂载记录
[root@localhost ~]# df -hT /mnt/cdrom
文件系统 类型 容量 已用 可用 已用% 挂载点
/dev/sr0 iso9660 4.3G 4.3G 0 100% /mnt/cdrom
步骤二:更改配置文件
1.进入/etc/yum.repos.d/中查看文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
总用量 28
-rw-r--r--. 1 root root 1664 8月 30 2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 8月 30 2017 CentOS-CR.repo
-rw-r--r--. 1 root root 649 8月 30 2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 8月 30 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 8月 30 2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月 30 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 8月 30 2017 CentOS-Vault.repo
2.将CentOS-Base.repo和CentOS-Debuginfo.repo改名或者移动,绕过网络安装,以便使用本地安装
#本次使用改名 方便作为备份文件
[root@localhost yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak
[root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
3.编辑文件CentOS-Media.repo(使用vim编辑器)
[root@localhost yum.repos.d]# vim CentOS-Media.repo
# CentOS-Media.repo
#
# This repo can be used with mounted DVD media, verify the mount point for
# CentOS-7. You can use this repo and yum to install items directly off the
# DVD ISO that we release.
#
# To use this repo, put in your DVD and use it with the other repos too:
# yum --enablerepo=c7-media [command]
#
# or for ONLY the media repo, do this:
#
# yum --disablerepo=\* --enablerepo=c7-media [command]
[c7-media]
name=CentOS-$releasever - Media
baseurl=file:///mnt/cdrom
gpgcheck=0 #用来检查GPG-KEY,0为不检查,1为检查
enabled=1 #是否用该yum源,0为禁用,1为使用
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
~
~
~
"CentOS-Media.repo" 20L, 563C 17,1 全部
4.清除yum缓存,测试yum源配置
清除yum缓存
[root@localhost yum.repos.d]# yum clean all
已加载插件:fastestmirror, langpacks
正在清理软件源: c7-media
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
Cleaning up list of fastest mirrors
测试
[root@localhost yum.repos.d]# yum list
已加载插件:fastestmirror, langpacks
c7-media | 3.6 kB 00:00
(1/2): c7-media/group_gz | 156 kB 00:00
(2/2): c7-media/primary_db | 3.1 MB 00:00
Determining fastest mirrors
已安装的软件包
GConf2.x86_64 3.2.6-8.el7 @anaconda
GeoIP.x86_64 1.5.0-11.el7 @anaconda
ModemManager.x86_64 1.6.0-2.el7 @anaconda
ModemManager-glib.x86_64 1.6.0-2.el7 @anaconda
NetworkManager.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-adsl.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-glib.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libnm.x86_64 1:1.8.0-9.el7 @anaconda
NetworkManager-libreswan.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-libreswan-gnome.x86_64 1.2.4-2.el7 @anaconda
NetworkManager-ppp.x86_64 1:1.8.0-9.el7 @anaconda
出现已安装的软件包时,便成功配置了
2、配置网络yum源
步骤一:备份
1)进入/etc/yum.repos.d 查看目录下文件
[root@localhost yum.repos.d]# ll
总用量 28
-rw-r--r--. 1 root root 1664 8月 30 2017 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 8月 30 2017 CentOS-CR.repo
-rw-r--r--. 1 root root 649 8月 30 2017 CentOS-Debuginfo.repo.bak
-rw-r--r--. 1 root root 314 8月 30 2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 563 3月 18 19:37 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 8月 30 2017 CentOS-Sources.repo
-rw-r--r--. 1 root root