yum 配置及yum 源配置

yum.conf 配置文件说明

yum 的配置文件分为两部分:main 和repository

main 部分定义了全局配置选项,整个yum 配置文件应该只有一个main。常位于/etc/yum.conf 中。
repository 部分定义了每个源/服务器的具体配置,可以有一到多个。常位于/etc/yum.repo.d 目录下的各文件中。
yum.conf 文件一般位于/etc目录下,一般其中只包含main部分的配置选项。

  

root@localhost yum.repos.d]# cat /etc/yum.conf 
[main]    
  //全局配置文件 cachedir=/var/cache/yum/$basearch/$releasever
  //yum 缓存目录,yum 在这储存缓存的rpm 包和数据库 keepcache=0
   //keepcache 安装完成后是否保留下载的rpm 包,0为不保留(1 为保留),默认为0 debuglevel=2
   //Debug 信息输出等级,默认为2 logfile=/var/log/yum.log
    //log 输出位置 exactarch=1
   //有0 和 1 两个选项,设置为1 表示yum 只会安装和系统硬件架构匹配的软件包,默认为1 obsoletes=1
  // 这是一个update 参数,允许更新旧的软件包 gpgcheck=1
  //是否进行gpg效验,1 代表进行效验 plugins=1
   //是否启用插件 installonly_limit=5 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum distroverpkg=centos-release # This is the default, if you make this bigger yum won't see if the metadata # is newer on the remote and so you'll "gain" the bandwidth of not having to # download the new metadata and "pay" for it by yum not having correct # information. # It is esp. important, to have correct metadata, for distributions like # Fedora which don't keep old packages around. If you don't like this checking # interupting your command line usage, it's much better to have something # manually check the metadata once an hour (yum-updatesd will do this). # metadata_expire=90m # PUT YOUR REPOS HERE OR IN separate files named file.repo # in /etc/yum.repos.d [root@localhost yum.repos.d]#

repo 文件

所有repository 服务器设置都应该遵循如下格式:

[serverid]
name=Some name for this server
baseurl=url://path/to/repository/
  • serverid 是用于区别各个不同的repository,必须有一个独一无二的名称;
  • name 是对repository 的描述,支持像$releasever $basearch这样的变量;
  • baseurl 是服务器设置中最重要的部分,只有设置正确,才能从上面获取软件。它的格式是:
baseurl=url://server1/path/to/repository/
     url://server2/path/to/repository/
     url://server3/path/to/repository/

其中url 支持的协议有 http:// ftp:// file:// 三种。baseurl 后可以跟多个url,你可以自己改为速度比较快的镜像站,但baseurl 只能有一个,也就是说不能像如下格式:

baseurl=url://server1/path/to/repository/
baseurl=url://server2/path/to/repository/
baseurl=url://server3/path/to/repository/

其中url 指向的目录必须是这个repository header 目录的上一级,它也支持$releasever $basearch 这样的变量。

关于变量

  • $releasever:代表发行版的版本,从[main]部分的distroverpkg获取,如果没有,则根据redhat-release包进行判断。
  • $arch:cpu体系,如i686,athlon等
  • $basearch:cpu的基本体系组,如i686和athlon同属i386,alpha和alphaev6同属alpha。
  • enabled=[1 or 0]
    #当某个软件仓库被配置成 enabled=0 时,yum 在安装或升级软件包时不会将该仓库做为软件包提供源。使用这个选项,可以启用或禁用软件仓库。
    #通过 yum 的 --enablerepo=[repo_name] 和 --disablerepo=[repo_name] 选项,或者通过 PackageKit 的"添加/删除软件"工具,也能够方便地启用和禁用指定的软件仓库

b. 导入GPG KEY

yum 可以使用gpg 对包进行校验,确保下载包的完整性,所以我们先要到各个repository 站点找到gpg key,一般都会放在首页的醒目位置,一些名字诸如RPM-GPG-KEY-CentOS-5 之类的纯文本文件,把它们下载下来,然后用rpm --import RPM-GPG-KEY-CentOS-5 命令将key 导入。

repo 自定义编辑

在定义repo 文件时,baseurl 路径指定的就是软件信息获取的位置,指定为 repodata 的上一级目录

[root@localhost yum.repos.d]# cat kubernetes.repo 
[kubernetes]
name=Kubernetes repo edit
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
gpgcheck=1
   //启用gpg 效验 gpgkey=https://mirrors.aliyun.com/kubernetes/yum/doc/yum-key.gpg
  //指定效验配置文件,不指定就通过rpm --import 文件导入 enable=1
  //启用仓库 [root@localhost yum.repos.d]#

  

root@localhost yum.repos.d]# yum remove all
Loaded plugins: fastestmirror
No Match for argument: all
No Packages marked for removal
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
base                                                                               | 3.6 kB  00:00:00     
docker-ce-stable                                                                   | 3.5 kB  00:00:00     
extras                                                                             | 3.4 kB  00:00:00     
kubernetes                                                                         | 1.4 kB  00:00:00     
updates                                                                            | 3.4 kB  00:00:00     
(1/3): kubernetes/primary                                                          |  50 kB  00:00:00     
(2/3): kubernetes/filelists                                                        |  18 kB  00:00:00     
(3/3): kubernetes/other                                                            |  33 kB  00:00:00     
kubernetes                                                                                        363/363
kubernetes                                                                                        363/363
kubernetes                                                                                        363/363
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                        repo name                                            status
base/7/x86_64                                  CentOS-7 - Base - 163.com                            10,019
docker-ce-stable/x86_64                        Docker CE Stable - x86_64                                46
extras/7/x86_64                                CentOS-7 - Extras - 163.com                             419
kubernetes                                     Kubernetes repo edit                                    363
updates/7/x86_64                               CentOS-7 - Updates - 163.com                          2,146
repolist: 12,993

  

猜你喜欢

转载自www.cnblogs.com/zy09/p/11127572.html