你的位置:焦点娱乐 > 业务范围 >
Centos7配置本地Yum源以及网络YUM源(保姆级)
发布日期:2024-08-26 07:47    点击次数:168

在虚拟机没有网络或者网络不稳定的情况下需要配置本地yum源

优点:由于数据从本地获取,下载和安装软件包的速度非常快,完全不需要网络

缺点:软件可能不是最新版,需要手动更新比较麻烦

一、配置本地yum源

        首先将centos自带的网络yum源删掉(自带的默认从centos官网下载软件,服务器在国外,非常不稳定)

 [root@cloud ~]# rm -rf /etc/yum.repos.d/*

         创建挂载点并挂载镜像

[root@cloud ~]# mkdir /opt/centos[root@cloud ~]# mount /dev/cdrom /opt/centos/mount: /dev/sr0 写保护,将以只读方式挂载

创建并编写本地yum源配置文件,编写完成之后wq保存退出

[root@cloud ~]# vi /etc/yum.repos.d/local.repo[centos]name=centos                 # Yum源的名称,用于描述这个源baseurl=file:///opt/centos  # 本地Yum源的位置,指向挂载点目录gpgcheck=0                  # 不进行GPG签名检查enabled=1                   # 启用该Yum源

清除缓存原来的生成新的缓存并列出当前系统中已配置和启用的Yum仓库(repositories)及其状态

[root@cloud ~]# yum clean all 已加载插件:fastestmirror, langpacks正在清理软件源: centosCleaning up list of fastest mirrorsOther repos take up 1.0 G of disk space (use --verbose for details)[root@cloud ~]# yum makecache 已加载插件:fastestmirror, langpacksDetermining fastest mirrorscentos                                                                                           | 3.6 kB  00:00:00     (1/4): centos/group_gz                                                                           | 153 kB  00:00:00     (2/4): centos/primary_db                                                                         | 3.3 MB  00:00:00     (3/4): centos/other_db                                                                           | 1.3 MB  00:00:00     (4/4): centos/filelists_db                                                                       | 3.3 MB  00:00:00     元数据缓存已建立[root@cloud ~]# yum repolist 已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile源标识                                                   源名称                                                    状态centos                                                   centos                                                    4,070repolist: 4,070

图片

下载httpd测试一下

[root@cloud ~]# yum install -y httpd已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile正在解决依赖关系--> 正在检查事务---> 软件包 httpd.x86_64.0.2.4.6-95.el7.centos 将被 安装--> 正在处理依赖关系 httpd-tools = 2.4.6-95.el7.centos,它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要--> 正在处理依赖关系 /etc/mime.types,它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要--> 正在处理依赖关系 libaprutil-1.so.0()(64bit),它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要--> 正在处理依赖关系 libapr-1.so.0()(64bit),它被软件包 httpd-2.4.6-95.el7.centos.x86_64 需要--> 正在检查事务---> 软件包 apr.x86_64.0.1.4.8-7.el7 将被 安装---> 软件包 apr-util.x86_64.0.1.5.2-6.el7 将被 安装---> 软件包 httpd-tools.x86_64.0.2.4.6-95.el7.centos 将被 安装---> 软件包 mailcap.noarch.0.2.1.41-2.el7 将被 安装--> 解决依赖关系完成依赖关系解决======================================================================================================================== Package                     架构                   版本                                   源                      大小========================================================================================================================正在安装: httpd                       x86_64                 2.4.6-95.el7.centos                    centos                 2.7 M为依赖而安装: apr                         x86_64                 1.4.8-7.el7                            centos                 104 k apr-util                    x86_64                 1.5.2-6.el7                            centos                  92 k httpd-tools                 x86_64                 2.4.6-95.el7.centos                    centos                  93 k mailcap                     noarch                 2.1.41-2.el7                           centos                  31 k事务概要========================================================================================================================安装  1 软件包 (+4 依赖软件包)总下载量:3.0 M安装大小:10 MDownloading packages:------------------------------------------------------------------------------------------------------------------------总计                                                                                     95 MB/s | 3.0 MB  00:00:00     Running transaction checkRunning transaction testTransaction test succeededRunning transaction  正在安装    : apr-1.4.8-7.el7.x86_64                                                                              1/5   正在安装    : apr-util-1.5.2-6.el7.x86_64                                                                         2/5   正在安装    : httpd-tools-2.4.6-95.el7.centos.x86_64                                                              3/5   正在安装    : mailcap-2.1.41-2.el7.noarch                                                                         4/5   正在安装    : httpd-2.4.6-95.el7.centos.x86_64                                                                    5/5   验证中      : httpd-tools-2.4.6-95.el7.centos.x86_64                                                              1/5   验证中      : mailcap-2.1.41-2.el7.noarch                                                                         2/5   验证中      : apr-1.4.8-7.el7.x86_64                                                                              3/5   验证中      : httpd-2.4.6-95.el7.centos.x86_64                                                                    4/5   验证中      : apr-util-1.5.2-6.el7.x86_64                                                                         5/5 已安装:  httpd.x86_64 0:2.4.6-95.el7.centos                                                                                    作为依赖被安装:  apr.x86_64 0:1.4.8-7.el7            apr-util.x86_64 0:1.5.2-6.el7       httpd-tools.x86_64 0:2.4.6-95.el7.centos        mailcap.noarch 0:2.1.41-2.el7      完毕!

图片

下载成功

二、配置网络yum源

优点:软件包和元数据由源服务器自动更新,国内镜像下载速度非常快

缺点:需要稳定的网络连接,网络不稳定或断开时无法使用

首先找到国内的镜像站(我这里以阿里云举例)

图片

找到自己的Linux版本(以centos为例)

图片

找到对应的系统版本(我的是7)并且复制这段命令到虚拟机粘贴

图片

同样需要先删除原有的yum仓库

列出当前系统中已配置和启用的Yum仓库(repositories)及其状态

[root@cloud ~]# rm -rf /etc/yum.repos.d/*[root@cloud ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo--2024-06-09 12:36:26--  https://mirrors.aliyun.com/repo/Centos-7.repo正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 183.215.53.217, 183.215.53.222, 183.215.53.224, ...正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|183.215.53.217|:443... 已连接。已发出 HTTP 请求,正在等待回应... 200 OK长度:2523 (2.5K) [application/octet-stream]正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”100%[======================================>] 2,523       --.-K/s 用时 0.006s  2024-06-09 12:36:26 (401 KB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])[root@cloud ~]# yum repolist 已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com源标识                                源名称                                                      状态!base/7/x86_64                        CentOS-7 - Base - mirrors.aliyun.com                        10,072!extras/7/x86_64                      CentOS-7 - Extras - mirrors.aliyun.com                         526!updates/7/x86_64                     CentOS-7 - Updates - mirrors.aliyun.com                      5,890repolist: 16,488

图片

可以看到已经保存成功,网络yum源就配置好了

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报。