Loading... > 每次新机器都配置很麻烦,记录一下如何配置网络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 正在清理软件源: centos Cleaning up list of fastest mirrors Other repos take up 1.0 G of disk space (use --verbose for details) [root@cloud ~]# yum makecache 已加载插件:fastestmirror, langpacks Determining fastest mirrors centos | 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, langpacks Loading mirror speeds from cached hostfile 源标识 源名称 状态 centos centos 4,070 repolist: 4,070 ``` 下载httpd测试一下 ``` [root@cloud ~]# yum install -y httpd 已加载插件:fastestmirror, langpacks Loading 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 M Downloading packages: ------------------------------------------------------------------------------------------------------------------------ 总计 95 MB/s | 3.0 MB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running 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, langpacks Loading 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,890 repolist: 16,488 ``` 可以看到已经保存成功,网络yum源就配置好了 最后修改:2025 年 06 月 22 日 © 允许规范转载 打赏 赞赏作者 支付宝微信 赞 2 如果觉得我的文章对你有用,请随意赞赏