Centos7配置yum源

  • Post author:
  • Post category:其他


yum是linux环境安装软件包的一种方式。很多时候安装一个软件需要安装1个或者多个其他软件。yum仓库用来存放所有的现有的.rpm包,当使用yum安装一个rpm包时,需要依赖关系,会自动在仓库中查找依赖软件并安装。仓库可以是本地的,也可以是HTTP、FTP、nfs形式使用的集中地、统一的网络仓库如果你的linux环境不能访问外网,那你装yum没有意义,因为它需要访问http的仓库里面的。当然如果你有本地仓库,就把/etc/yum.repos.d改一下地址就可以。

yum源即是软件仓库,三种配置方式网络yum源(需要联网),局域网yum源,本地yum源。

yum安装软件:

yum list | grep 软件名 //查看软件
yum install 软件 -y   //安装

一、网络yum源

查看配置文件

ll /etc/yum.repos.d

在这里插入图片描述

CentOS-Base.repo:在线的yum源配置文件

CentOS-Media.repo:本地yum源配置文件

查看CentOS-Base.repo:

cat CentOS-Base.repo

在这里插入图片描述

id:[base]基础 [updates]升级时 [extras]额外的

如果原本的不可用,可以配置为阿里的yum源:

yum clean all
yum makecache
yum  install -y  wget    #方面后面wget获取yum源文件

将yum源配置的目录做一个备份。

mv /etc/yum.repos.d /etc/yum.repos.d.bak 
mkdir /etc/yum.repos.d

cp mv 都可以,使用 mv 就需要新建这个目录,使用cp 就需要删除目录内的文件。

第二步,下载yum源配置文件

阿里源:
 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
 或  curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
 epel源:
 rpm -vih http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-9.noarch.rpm
 直接安装epel-yum源

第三步 重建缓存

使用命令

 yum clean all
 yum makecache

此时可以正常使用阿里yum源了,



如果不需要配置本地yum源,到这里就可以结束了。

需用配置本地镜像yum源的童鞋,考虑到优先使用本地安装包进行安装,所以涉及到一个优先级的概念。

一、安装yum 的优先级插件。

mkdir /mnt//cdrom

mount /dev/cdrom /mnt/cdrom //此处为挂载镜像,大家各显神通,此处我使用的是虚拟机的常用方式

mkdir /mnt//cdrom
mount /dev/cdrom /mnt/cdrom //此处为挂载镜像,大家各显神通,此处我使用的是虚拟机的常用方式
cd /mnt/cdrom/Packages/
rpm -q yum-plugin*
rpm -ivh yum-plugin-priorities-1.1.31-40.el7.noarch.rpm 

二、创建本地yum源配置文件

可以直接创建全新的,也可以将备份中的配置文件修改后使用。此处我使用后者。

 cp  /etc/yum.repos.d.bak/CentOS-Base.repo /etc/yum.repos.d/CentOS-local.repo 
//将备份的配置文件修改名字复制到yum源配置目录中

三、修改源配置文件和本地源配置文件

阿里源配置文件需要做的是增加优先级参数。

本地源需要做的是指向正确的目录和设置优先级参数。

编辑本地源配置文件

vi /etc/yum.repos.d/CentOS-local.repo

本地yum源配置内容如下

在这里插入图片描述

目录指向到达镜像包即可,不可以到Package文件夹下,会报错。

注意此处有priority=1 ,代表优先级为1.

编辑阿里源配置文件

vi /etc/yum.repos.d/CentOS-Base.repo

阿里yum源配置内容中,在每个节下添加优先级参数即可。

在这里插入图片描述

四、重建缓存。

使用命令

 yum clean all
 yum makecache


安装EPEL(Extra Packages for Enterprise Linux )源

4、安装EPEL源

[root@bogon yum.repos.d]# yum list | grep epel-release
epel-release.noarch                         7-9                        extras   
[root@bogon yum.repos.d]# yum install -y epel-release
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package epel-release.noarch 0:7-9 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==================================================================================================================================
 Package                             Arch                          Version                    Repository                     Size
==================================================================================================================================
Installing:
 epel-release                        noarch                        7-9                        extras                         14 k

Transaction Summary
==================================================================================================================================
Install  1 Package

Total download size: 14 k
Installed size: 24 k
Downloading packages:
epel-release-7-9.noarch.rpm                                                                                |  14 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : epel-release-7-9.noarch                                                                                        1/1 
  Verifying  : epel-release-7-9.noarch                                                                                        1/1 

Installed:
  epel-release.noarch 0:7-9                                                                                                       

Complete!
[root@bogon yum.repos.d]# ls                      #多了epel.repo和epel-testing.repo
CentOS-Base.repo  epel.repo  epel-testing.repo  repo_bak

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

6、查看启用的yum源和所有的yum源

[root@bogon yum.repos.d]# yum repolist enabled               #查看启用的仓库
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                        repo name                                                                    status
base/7/x86_64                                  CentOS-7 - Base - mirrors.aliyun.com                                          9,591
epel/x86_64                                    Extra Packages for Enterprise Linux 7 - x86_64                               12,277
extras/7/x86_64                                CentOS-7 - Extras - mirrors.aliyun.com                                          388
updates/7/x86_64                               CentOS-7 - Updates - mirrors.aliyun.com                                       1,929
repolist: 24,185
[root@bogon yum.repos.d]# yum repolist all                          #查看所有的仓库
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.ustc.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                repo name                                                                   status
base/7/x86_64                          CentOS-7 - Base - mirrors.aliyun.com                                        enabled:  9,591
centosplus/7/x86_64                    CentOS-7 - Plus - mirrors.aliyun.com                                        disabled
contrib/7/x86_64                       CentOS-7 - Contrib - mirrors.aliyun.com                                     disabled
epel/x86_64                            Extra Packages for Enterprise Linux 7 - x86_64                              enabled: 12,277
epel-debuginfo/x86_64                  Extra Packages for Enterprise Linux 7 - x86_64 - Debug                      disabled
epel-source/x86_64                     Extra Packages for Enterprise Linux 7 - x86_64 - Source                     disabled
epel-testing/x86_64                    Extra Packages for Enterprise Linux 7 - Testing - x86_64                    disabled
epel-testing-debuginfo/x86_64          Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Debug            disabled
epel-testing-source/x86_64             Extra Packages for Enterprise Linux 7 - Testing - x86_64 - Source           disabled
extras/7/x86_64                        CentOS-7 - Extras - mirrors.aliyun.com                                      enabled:    388
updates/7/x86_64                       CentOS-7 - Updates - mirrors.aliyun.com                                     enabled:  1,929
repolist: 24,185



版权声明:本文为q309572960原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。