CentOS 7配置本地Yum源、阿里源、网易源

版权声明:©来自CSDN博客作者"Debug The Life"的原创作品,如需转载,请注明出处。 https://blog.csdn.net/zhaoxixc/article/details/82079692
1、进行挂载
[root@fudanwuxi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        17G  4.1G   13G  24% /
devtmpfs        978M     0  978M   0% /dev
tmpfs           993M     0  993M   0% /dev/shm
tmpfs           993M  9.0M  984M   1% /run
tmpfs           993M     0  993M   0% /sys/fs/cgroup
/dev/sda1      1014M  158M  857M  16% /boot
tmpfs           199M  4.0K  199M   1% /run/user/42
tmpfs           199M   24K  199M   1% /run/user/0
[root@fudanwuxi ~]# mkdir /media/CentOS
[root@fudanwuxi ~]# mount -t auto /dev/cdrom /media/CentOS
mount: /dev/sr0 is write-protected, mounting read-only
[root@fudanwuxi ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        17G  4.1G   13G  24% /
devtmpfs        978M     0  978M   0% /dev
tmpfs           993M     0  993M   0% /dev/shm
tmpfs           993M  9.0M  984M   1% /run
tmpfs           993M     0  993M   0% /sys/fs/cgroup
/dev/sda1      1014M  158M  857M  16% /boot
tmpfs           199M  4.0K  199M   1% /run/user/42
tmpfs           199M   28K  199M   1% /run/user/0
/dev/sr0        4.3G  4.3G     0 100% /media/CentOS
2、将原文件进行备份
[root@fudanwuxi ~]# cd /etc/yum.repos.d/
[root@fudanwuxi yum.repos.d]# ll
total 28
-rw-r--r--. 1 root root 1664 Aug 30  2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Aug 30  2017 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Aug 30  2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Aug 30  2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Aug 30  2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Aug 30  2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 Aug 30  2017 CentOS-Vault.repo
[root@fudanwuxi yum.repos.d]# cp CentOS-Base.repo CentOS-Base.repo.bak
[root@fudanwuxi yum.repos.d]# ll
total 32
-rw-r--r--. 1 root root 1664 Aug 30  2017 CentOS-Base.repo
-rw-r--r--. 1 root root 1664 Aug  2 11:00 CentOS-Base.repo.bak
-rw-r--r--. 1 root root 1309 Aug 30  2017 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Aug 30  2017 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Aug 30  2017 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Aug 30  2017 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Aug 30  2017 CentOS-Sources.repo
-rw-r--r--. 1 root root 3830 Aug 30  2017 CentOS-Vault.repo
3、修改yum配置文件,将CentOS-Base.repo中的mirrorlist行进行注释掉,baseurl行取消注释且设置值为挂载点baseurl=file:///media/CentOS/
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 for package: 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 for bind-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        0 0
UUID=03804cec-c899-4f0c-a6d4-9424ffdd6097 /boot                   xfs     defaults        0 0
UUID=c43e19d0-7ba6-4189-90ff-45922f3b4812 swap                    swap    defaults        0 0
/dev/sr0 /media/CentOS iso9660 defaults 0 0

  • 扩展
    更换yum源为①阿里源和②网易源
cd /etc/yum.repos.d/
mv CentOS-Base.repo CentOS-Base.repo.bak
①:wget http://mirrors.aliyun.com/repo/Centos-7.repo
②:wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
①:mv Centos-7.repo CentOS-Base.repo
②:mv CentOS7-Base-163.repo CentOS-Base.repo
yum clean all
yum makecache

猜你喜欢

转载自blog.csdn.net/zhaoxixc/article/details/82079692