首页 > 系统相关 >yum网络源的配置

yum网络源的配置

时间:2024-08-12 17:37:51浏览次数:5  
标签:-- repos 配置 网络 repo yum 软件 root

yum 的原理

yum 的全称是 Yellow dog Updater,Modified,yum 是 CentOS 或者是 RedHat 中最常见的包管理器。

早期的 Linux 发行版安装软件包要解决软件包的依赖问题,这些依赖的问题需要人工手动解决,通常是需要安装的软件有多个依赖,依赖又有其他的依赖所以自行手动安装很麻烦。

yum 就是为了解决上述的这类问题,yum 解决了分析需要安装软件的依赖的痛点,由程序完成对软件依赖的分析和下载。

例如:当我需要安装一个httpd的软件,yum的客户机 会向 yum的软件仓库 发出请求,yum的客户机会得到一份软件清单,软件清单记录了 httpd 需要的软件清单关系,yum在安装使用的时候,会基于软件清单分析出下载安装的软件包和所依赖的包,最后以 rpm 这种机制完成。

上面的过程一个命令 yum install httpd 就能完成了

yum 最初登录在一个名为 黄狗Linux 的发型版中,后来进入到了 红帽 ,这就有了现在的 yum 软件。

yum的安装过程

  1. yum客户机向yun软件仓库软件清单

  2. 将下载的软件清单保存在 /var/cache/yum 目录中

  3. 分析出需要下载安装的软件包和依赖的包的列表

  4. 从仓库中下载所需要的软件包

  5. 以 rpm 机制安装下载的软件包

yum 源的设置

安装操作系统之后一般都是自带网络源的。这里是以 CentOS7 发行版示列:
[root@server ~]# cat /etc/redhat-release
CentOS Linux release 7.5.1804 (Core)

这是 7.5.1804 的发行版。

[root@server ~]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# ll
total 32
-rw-r--r--. 1 root root 1664 Apr 28  2018 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Apr 28  2018 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Apr 28  2018 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Apr 28  2018 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Apr 28  2018 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Apr 28  2018 CentOS-Sources.repo
-rw-r--r--. 1 root root 4768 Apr 28  2018 CentOS-Vault.repo

默认有7个以 .repo 结尾的文件,yum客户端有repo相当与就是有 yum服务器 联系方式了,这里的 yum服务器 显然就是CentOS官方的软件仓库。

[root@server yum.repos.d]# yum install httpd -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os                                                               
&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

 One of the configured repositories failed (Unknown),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

这是我通过 yum install httpd -y 来下载 httpd 软件,-y 表示确认不需要手动输入 y

通过显示的 Could not resolve host: mirrorlist.centos.org; Unknown error 结果表明官网的 yum源 失效了,现在的时间段 CentOS7 已经停止维护了,它的yum源也就终止服务了。

这就需要 第三方 的 yum源,也就第三的软件仓库为我们提供yum的服务。

yum 源的配置文件

第三方的yum源是比较好找的,在配置yum之前先要知道yum的配置文件。

yum 的配置文件以 .repo 的格式为结尾,这写文件在 /etc/yum.repos.d 目录下。

由于先前的官网已经失效所以,现在这些原本的 .repo 文件失去了提供服务的作用,但最好还是将这些没有用的文件先保存起来,保存这些过期文件的文件名叫做 yum_bak

[root@server ~]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# mkdir yum_bak
[root@server yum.repos.d]# mv C* yum_bak/
[root@server yum.repos.d]# ll
total 0
drwxr-xr-x. 2 root root 187 Aug 12 04:18 yum_bak

配置文件:
一个基本的yum的配置文件比较简单,很容易理解。

[main]
name=                ==> 定义软件仓库对于我来说的名字
baseurl=             ==> 软件仓库的网址
enable=              ==> 是否启用该软件仓库 1 表示启动 0 表示不启动
gpgcheck=            ==> 下载软件时候对软件的检查,防止下载到篡改后的文件

通过搜索找到了阿里云的yum软件仓库也就是阿里源的地址:
https://mirrors.aliyun.com/centos-vault/7.5.1804/os/x86_64/ 这个网址就用于 baseurl= 的右边。

[abc]
name=aliyuan
baseurl=https://mirrors.aliyun.com/centos-vault/7.5.1804/os/x86_64/ 
enable=1
gpgcheck=1

将这段文件内容保存在 aliyuan.repo 文件里面,该文件在 /etc/yum.repos.d 目录下。

[root@server yum.repos.d]# ll
total 4
-rw-r--r--. 1 root root  98 Aug 12 05:03 aliyun.repo
drwxr-xr-x. 2 root root 187 Aug 12 04:18 yum_bak

.repo 文件有其他的参数和用法这里不做解释。

使用 rpm 对 GPG-KEY 进行导入,这对应的就是 gpgcheck=1 这个选项。

[root@server yum.repos.d]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

RPM-GPG-KEY-CentOS-7 这个文件是系统自带的,也可以是你自行下载的,第三方网站会在yum软件仓库网络中提供这样的文件。

[root@server yum.repos.d]# yum clean all
Cleaning repos: name
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

[root@server yum.repos.d]# yum makecache

为了方便下载软件的速度 yum 会在本机留下缓存,由于我们更新的yum的配置文件,现在需要通过 yum clean all 进行清理,随后通过 yum makecahe 来构建新的缓存。

通过 yum repolist 列出yum的仓库,可以看出 aliyuan 已经有了。

[root@server yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
name/primary_db                                                   | 5.9 MB  00:00:11
repo id                                  repo name                                 status
name                                     aliyuan                                   9,911
repolist: 9,911
[1]-  Killed                  yum repolist

yum 安装软件

``` [root@server yum.repos.d]# yum -y install httpd

标签:--,repos,配置,网络,repo,yum,软件,root
From: https://www.cnblogs.com/takenika/p/18354699

相关文章

  • windows下nginx配置开机自启动
    (1)、WindowsServiceWrapper工具下载工具下载URL:https://github.com/winsw/winsw/releases   (2)、WindowsServiceWrapper工具安装配置第一步:下载后将该工具放入Nginx的安装目录下,并且将其重命名为nginx-service.exe第二步:在nginx安装目录下新建服务日志文件夹:server......
  • 安防监控/视频汇聚平台EasyCVR如何配置,实现默认获取设备的子码流?
    安防视频监控/视频集中存储/云存储/磁盘阵列EasyCVR平台基于云边端一体化架构,兼容性强、支持多协议接入,包括国标GB/T28181协议、部标JT808、GA/T1400协议、RTMP、RTSP/Onvif协议、海康Ehome、海康SDK、大华SDK、华为SDK、宇视SDK、乐橙SDK、萤石云SDK等。有用户反馈,选用HIKSDK......
  • Centos7.9安装配置Zabbix6.0详细步骤
    文章目录一:配置yum源二:关闭防火墙和selinux三:安装php四:安装apache五:安装mysql六:编译安装zabbix6.0七:php修改参数八:页面访问一:配置yum源1:备份现有的yum源(更改名称就行)2:创建阿里云yum源wget-O/etc/yum.repos.d/aliyun.repohttp://mirrors.aliyun.com/repo/Centos......
  • Jenkins+gitlab+harbor+docker-compose自动化部署配置
    本文主要讲解Jenkins在Linux环境下实现自动化部署项目(提供一种思路)持续集成与持续部署(CI/CD)流程的实现,需要依赖一系列先进的工具和技术。这些工具不仅提高了开发效率,还确保了代码质量和发布的可靠性。以下是构建CI/CD流程所需的关键工具列表及其作用概述:Jenkins-作为自动化......
  • 虚拟机网络设置 与dhcp 获取ip
     在宿主机(例如Linux服务器)中运行虚拟机时,虚拟机通常通过DHCP服务器获取IP地址。以下是如何配置和排查虚拟机DHCP获取IP的过程:1.检查虚拟机的网络配置虚拟机的网络配置类型通常有以下几种:NAT(NetworkAddressTranslation):虚拟机通过宿主机的IP地址访问外部......
  • 手把手教你实现Scrapy-Redis分布式爬虫:从配置到最终运行的实战指南
    1.scrapy-redis的环境准备pipinstallscrapy-redis安装完毕之后确保其可以正常导入使用即可。2.实现接下来我们只需要简单的几步操作就可以实现分布式爬虫的配置了。2.1修改Scheduler在前面的课时中我们讲解了Scheduler的概念,它是用来处理Request、Item等对象的调度......
  • 【Linux学习】CentOS7配置
    1、CentOS设置打开终端快捷键应用程序(Applications)>系统工具(SystemTools)>设置(Settings)>设备(Devices)>Keyboard拉到页面最底下,点击加号添加快捷键设置快捷键名称、命令(/usr/bin/gnome-terminal)以及快捷键,然后点击Add即可2、设置CentOS终端打开的默认字体......
  • 【Linux学习】Ubuntu配置
    1、如何在Ubuntu18.04上面安装VMware-tools实现屏幕适配,以及文件拖拽、复制、粘贴功能先设置以下:此处一定要设置路径保证客户机隔离选项两个勾选将主机桌面文件夹设置为共享 点击VMware顶部菜单,“虚拟机”>“安装VMwareTools”,桌面会出现光盘图标“VMwareTools”......
  • 07.网络管理课后习题
    07.网络管理课后习题1.如何查看系统中每个ip的连接数2.请列出下列服务使用的端口,http,ftp,ssh,telnet,mysql,dnsHTTP:默认端口80FTP:默认端口21(控制连接),20(数据连接)SSH:默认端口22Telnet:默认端口23MySQL:默认端口3306http 80/tcphttps 443/tcpssh ......
  • linux反向代理原理:帮助用户更好地优化网络架构
    Linux反向代理原理详解反向代理是一种在网络架构中常用的技术,尤其在Linux环境下被广泛应用。它可以帮助实现负载均衡、安全防护和请求缓存等功能。本文将深入探讨Linux反向代理的原理、工作机制以及其应用场景。1.什么是反向代理反向代理是指代理服务器接收客户端的请求,......