vim CentOS-Base.repo
# 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
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=file:///media/CentOS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=file:///media/CentOS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=file:///media/CentOS/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
baseurl=file:///media/CentOS/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
4、清除yum缓存后重新生成缓存
[root@fudanwuxi yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks
Cleaning repos: base extras updates
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@fudanwuxi yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.6 kB 00:00:00
updates | 3.6 kB 00:00:00
(1/12): base/group_gz | 156 kB 00:00:00
(2/12): base/primary_db | 3.1 MB 00:00:00
(3/12): base/filelists_db | 3.1 MB 00:00:00
(4/12): extras/group_gz | 156 kB 00:00:00
(5/12): base/other_db | 1.2 MB 00:00:00
(6/12): extras/filelists_db | 3.1 MB 00:00:00
(7/12): extras/primary_db | 3.1 MB 00:00:00
(8/12): extras/other_db | 1.2 MB 00:00:00
(9/12): updates/group_gz | 156 kB 00:00:00
(10/12): updates/filelists_db | 3.1 MB 00:00:00
(11/12): updates/primary_db | 3.1 MB 00:00:00
(12/12): updates/other_db | 1.2 MB 00:00:00
Determining fastest mirrors
Metadata Cache Created
[root@fudanwuxi yum.repos.d]#
5、测试,网络是不通的,通过本地yum源进行安装DNS域名解析服务
[root@fudanwuxi yum.repos.d]# ping -c 3 www.baidu.com
ping: www.baidu.com: Name or service not known
[root@fudanwuxi yum.repos.d]# yum install bind-chroot
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bind-chroot.x86_64 32:9.9.4-50.el7 will be installed
--> Processing Dependency: bind = 32:9.9.4-50.el7 forpackage: 32:bind-chroot-9.9.4-50.el7.x86_64
--> Running transaction check
---> Package bind.x86_64 32:9.9.4-50.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
=======================================================================================
Package Arch Version Repository Size
=======================================================================================
Installing:
bind-chroot x86_64 32:9.9.4-50.el7 base 86 k
Installing for dependencies:
bind x86_64 32:9.9.4-50.el7 base 1.8 M
Transaction Summary
=======================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 1.9 M
Installed size: 4.3 M
Is this ok [y/d/N]: y
Downloading packages:
warning: /media/CentOS/Packages/bind-9.9.4-50.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key forbind-9.9.4-50.el7.x86_64.rpm is not installed
---------------------------------------------------------------------------------------
Total 30 MB/s | 1.9 MB 00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-4.1708.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : 32:bind-9.9.4-50.el7.x86_64 1/2
Installing : 32:bind-chroot-9.9.4-50.el7.x86_64 2/2
Verifying : 32:bind-9.9.4-50.el7.x86_64 1/2
Verifying : 32:bind-chroot-9.9.4-50.el7.x86_64 2/2
Installed:
bind-chroot.x86_64 32:9.9.4-50.el7
Dependency Installed:
bind.x86_64 32:9.9.4-50.el7
Complete!
[root@fudanwuxi yum.repos.d]#
6、重启后自动挂载本地yum源
vim /etc/fstab
## /etc/fstab# Created by anaconda on Mon May 14 12:30:53 2018## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#
UUID=d0359271-49d5-42c6-980d-23dea91ae9dc / xfs defaults 00
UUID=03804cec-c899-4f0c-a6d4-9424ffdd6097 /boot xfs defaults 00
UUID=c43e19d0-7ba6-4189-90ff-45922f3b4812 swap swap defaults 00
/dev/sr0 /media/CentOS iso9660 defaults 00
扩展 更换yum源为①阿里源和②网易源
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak