0


【特别篇】Centos7配置yum源(本地源和网络源)

前言

在配置yum源之前,我们先了解一下本地源和网络源的区别:
本地源: 利用挂载系统系统镜像包进行配置,因受限与镜像包,能获取的包相对较少。
网络源:在能连接互联网的服务器上进行配置,配置简单,可选择性强,能获取的包也更多。
了解了我们接下就进行实操

一、本地yum源

1、创建挂载点目录

[root@lk ~]# mkdir /mnt/cdrom      #创建目录[root@lk ~]# df /mnt/cdrom/        #查看设备状况
Filesystem              1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root  178114561386708164247488% /

2、挂载CD(光盘)

[root@lk ~]# mount /dev/cdrom /mnt/cdrom/
mount: /dev/sr0 is write-protected, mounting read-only    #显示这个表示挂载成功

3、查看挂载记录

[root@lk ~]# df -h /mnt/cdrom/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sr0        4.4G  4.4G     0100% /mnt/cdrom

4、更改配置文件(查看/etc/yum.repos.d/中的文件)

[root@lk ~]# ls -l /etc/yum.repos.d/
total 40
-rw-r--r--. 1 root root 1664 Oct 232020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 232020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Oct 232020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Oct 232020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Oct 232020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 232020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 232020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Oct 232020 CentOS-x86_64-kernel.repo

5、绕过网络,使用本地安装

[root@lk ~]# cd /etc/yum.repos.d/[root@lk yum.repos.d]# ll
total 40
-rw-r--r--. 1 root root 1664 Oct 232020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 232020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Oct 232020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Oct 232020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Oct 232020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 232020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 232020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Oct 232020 CentOS-x86_64-kernel.repo
[root@lk yum.repos.d]# mkdir bak[root@lk yum.repos.d]# ll
total 40
drwxr-xr-x. 2 root root    6 Sep 20 07:15 bak
-rw-r--r--. 1 root root 1664 Oct 232020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 232020 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Oct 232020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Oct 232020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Oct 232020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 232020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 232020 CentOS-Vault.repo
-rw-r--r--. 1 root root  616 Oct 232020 CentOS-x86_64-kernel.repo
[root@lk yum.repos.d]# mv CentOS-* bak/[root@lk yum.repos.d]# ll
total 0
drwxr-xr-x. 2 root root 220 Sep 20 07:15 bak

6、编辑local.repo文件

[root@lk yum.repos.d]# vi local.repo[root@lk yum.repos.d]# cat local.repo[centos]name=centos
baseurl=file:///mnt/cdrom
gpgcheck=0#用来检查GPG-KEY,0为关闭,1为开启enabled=1#是否用该yum源,0为禁,1为使用

7、清除yum缓存 ,测试yum源

[root@lk yum.repos.d]# yum clean all;yum makecache
Loaded plugins: fastestmirror
Cleaning repos: centos
Cleaning up list of fastest mirrors
Other repos take up 19 M of disk space (use --verbose for details)
Loaded plugins: fastestmirror
Determining fastest mirrors
centos                                                                                     |3.6 kB  00:00:00
(1/4): centos/group_gz                                                                     |153 kB  00:00:00
(2/4): centos/filelists_db                                                                 |3.3 MB  00:00:00
(3/4): centos/primary_db                                                                   |3.3 MB  00:00:00
(4/4): centos/other_db                                                                     |1.3 MB  00:00:00
Metadata Cache Created
[root@lk yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                repo name                                               status
centos                                             centos                                              4,070
repolist: 4,070

出软件包数量,表示已成功配置了

二、阿里网络源yum源

1、查看目录下文件

[root@localhost ~]# cd /etc/yum.repos.d/[root@localhost yum.repos.d]# ll
total 32
-rw-r--r--. 1 root root 1664 Sep  52019 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Sep  52019 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Sep  52019 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Sep  52019 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Sep  52019 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Sep  52019 CentOS-Sources.repo
-rw-r--r--. 1 root root 6639 Sep  52019 CentOS-Vault.repo

2、把/etc/yum.repos.d/下的文件备份到新建目录下

[root@localhost yum.repos.d]# mkdir bak[root@localhost yum.repos.d]# mv C* bak[root@localhost yum.repos.d]# ll
total 0
drwxr-xr-x. 2 root root 187 Sep 20 09:50 bak

3、下载阿里centos7的网络源

[root@localhost yum.repos.d]# yum install wget -y[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo[root@localhost yum.repos.d]# ll
total 4
drwxr-xr-x. 2 root root  187 Sep 20 09:50 bak
-rw-r--r--. 1 root root 2523 Aug  4 03:04 CentOS-Base.repo

4、运行yum clean all 清除缓存,运行 yum makecache 生成新的缓存

[root@localhost yum.repos.d]# yum clean all | yum makecache
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 18051.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum
    Memory :23 M RSS (344 MB VSZ)
    Started: Tue Sep 2010:05:42 2022 - 00:01 ago
    State  : Running, pid: 18051
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                     |3.6 kB     00:00
extras                                                   |2.9 kB     00:00
updates                                                  |2.9 kB     00:00
(1/10): base/7/x86_64/group_gz                             |153 kB   00:00
(2/10): base/7/x86_64/primary_db                           |6.1 MB   00:04
extras/7/x86_64/other_db       FAILED
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/5ed35184b6160999eff67a1ce6f909e9c507535aafeea94489e2bc7a23bc9fd5-other.sqlite.bz2: [Errno 14]curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
(3/10): base/7/x86_64/filelists_db                         |7.2 MB   00:05
(4/10): extras/7/x86_64/filelists_db                       |277 kB   00:00
(5/10): extras/7/x86_64/primary_db                         |250 kB   00:00
(6/10): base/7/x86_64/other_db                             |2.6 MB   00:02
(7/10): updates/7/x86_64/filelists_db                      |9.4 MB   00:08
(8/10): extras/7/x86_64/other_db                           |149 kB   00:00
(9/10): updates/7/x86_64/other_db                          |1.1 MB   00:02
(10/10): updates/7/x86_64/primary_db                       |17 MB   00:12
Metadata Cache Created         #元数据缓已建立说明生成成功

5、查看所有的仓库

[root@localhost yum.repos.d]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id               repo name                                  status
base/7/x86_64         CentOS-7 - Base - mirrors.aliyun.com       enabled: 10,072
centosplus/7/x86_64   CentOS-7 - Plus - mirrors.aliyun.com       disabled
contrib/7/x86_64      CentOS-7 - Contrib - mirrors.aliyun.com    disabled
extras/7/x86_64       CentOS-7 - Extras - mirrors.aliyun.com     enabled:    516
updates/7/x86_64      CentOS-7 - Updates - mirrors.aliyun.com    enabled:  4,160
repolist: 14,748

yum源的本地源和网络源配置完毕。

如果对你有所帮助,还望赏个关注鸭 ! ! ! 😜
(⊙o⊙),我们下期再见!!!

标签: 网络 linux centos

本文转载自: https://blog.csdn.net/qq_56394220/article/details/126955021
版权归原作者 只学今天&明天 所有, 如有侵权,请联系我们删除。

“【特别篇】Centos7配置yum源(本地源和网络源)”的评论:

还没有评论