BaseOs之:yum源经验与常见问题

文章目录

yum常规操作:

案例1: 用yum下载批rpm包:

(针对下载yum list的包)

批量下载yum list中rpm包:
 yum list | awk '{print $1}' | while read line; do yumdownloader $line;done
下载系统内某个rpm包:
yumdownloader +包名  (yum-utils)
yumdownloader下载连同依赖包:

单纯的使用yumdownloader 只会下载给定名称的既定RPM包,安装时候所需要的一些依赖不会被下载。如果要下载依赖加上"--resolve"参数,如果要指定下载目录。加上"--destdir"参数

yumdownloader java-1.8.0-openjdk.x86_64 --resolve --destdir=/opt/java/

案例2: 调整yum repo使能优先级

问题需求:

https本机自带网络源,加本地自定义yum源,在安装rpm 时,不识别“自定义yum源”

处理:

安装插件(yum-plugin-priorities.noarch),调整 自定义 repo的优先级

第一:安装yum-plugin-priorities.noarch插件
     [root@test ~]# yum -y install yum-plugin-priorities.noarch
第二:查看插件是否启用
     [root@test ~]# cat /etc/yum/pluginconf.d/priorities.conf   
                           enabled = 1    //1为启用;0为禁用
第三:修改本地yum源优先使用
      [root@test ~]# ll /etc/yum.repos.d/   
      total 8   
      -rw-r--r--. 1 root root 2573 May 15  2015 CentOS-Base.repo   
      -rw-r--r--. 1 root root   67 Jun 20 06:04 local.repo        
      //有两个repo文件   
      [root@test ~]# vi /etc/yum.repos.d/local.repo   
            [local]   
            name=local   
            baseurl=file:///mnt/centos  
            ailovermethod=priority    #failovermethod 有两个值可以选择,priority是默认值,表示从列出的baseurl中顺序选择镜像服#务器地址,roundrobin表示在列出的服务器中随机选择 
            enabled=1   
            gpgcheck=0   
            priority=1    //在原基础上加入priority=1 ;数字越小优先级越高   
            //可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了


【参数】:
skip_if_unavailable=True 当repo不可用时跳过
总结:

如果本地有多个YUM源(网络源+本地自定义YUM源,建议先将“本地自定义YUM源优先级设置好”)

yum repo:
#cat /etc/yum.repos.d/myyun.repo
[local_yum]

name=centos7_local
baseurl=file:///root/myyum/
gpgcheck=0
enabled=1
priority=1
[fix_yum]
name=alios7_fix
baseurl=file:///var/yum/
gpgcheck=0
enabled=1
priority=1
Myrepo.repo
[plus]
name = Centos Linux - $releasever - Plus
baseurl = http://xxx
gpgcheck = 1
gpgkey = http://xxx/RPM-GPG-KEY-ALIYUN
proxy=http://192.168.2.111:3000

位于机房的测试机无法访问yum服务器上的yum仓库yum.conf,需要添加代理:proxy=http://192.168.2.111:3000 可以添加到repo文件中, 也可以统一添加到/etc/yum.conf配置文件中。

案例3: yum下载软件包的三种方法:

downloadonly插件:【只下载不安装】

yumdownloader rpm-build --destdir=/home/qw/

利用yum的缓存功能下载rpm到本地:

vim /etc/yum.conf 将其中 keepcache=0改为keepcache=1
yum clean all && yum makecache

案例4: yum查看yum源内指定rpm包的依赖:

(未安装的,安装的都可以查,只要该包在yum源内就行)

yum deplist +rpm名字

案例5: yum查看下载好的rpm包的依赖与提供的依赖:

办法二:比如依赖为:Requires:libMagickWand.so.5()(64bit)
下载目标rpm(只下载不安装)包: yumdownloader +rpm包名
查看rpm包(未安装)的依赖:    rpm -qp --requires emacs-24.3-23.1.al7.aarch64.rpm | grep libMagickWand
查看rpm包(未安装)提供的依赖  rpm -qp --provides libmspack-0.5-0.4.alpha.1.alios7.x86_64.rpm | egrep "libmspack"


案例6: yum install --nogpgcheck

案例7: yum check-update查询可以升级的rpm包:

[root@bogon src]# yum  check-update |  grep sudo  #查看下是否可以升级该包
sudo.x86_64    1.8.23-4.el7_7.2     updates

[root@bogon src]# yum  update sudo                #升级sudo到最新版本

案例8: yum回滚:

查看yum安装历史:yum history 
取消yum历史安装:yum -y history undo 11

在这里插入图片描述


案例9: yum配置的两种设置方法:

yum install阶段默认会去/etc/yum.repos.d下面找repo进行install packages,但是除了repo放在该目录下,我们还可以放在 /etc/yum.conf文件内

效果一:

当把/etc/yum.repos.d下面的repo都删除后,/etc/yum.conf内写入repo,yum install会去/etc/yum.conf去寻找repo信息

效果二:

当把/etc/yum.repos.d下面的repo不删除,/etc/yum.conf内写入repo,yum install 会去/etc/yum.conf与/etc/yum.repos.d去寻找repo信息

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

yum 的配置方式也分两种:
直接配置/etc目录下的yum.conf文件,增加repository片段
在/etc/yum.repos.d目录下增加.repo文件

【注意】:yum.conf中设置repodir则yum命令只会在/etc/yum.conf中找repo信息


案例10: 修改yum源优先级:

我们在安装一些软件时,可能需要配置多个yum源,这些源中,都存在某些软件包,但有些软件有重复,甚至冲突,能否可以优先从一些软件源中去找,

如果找不到,才去其他源中找呢?这里就涉及到了优先级的问题,

yum提供的插件yum-plugin-priorities.noarch可以解决这个问题

第一:查看系统是否安装了优先级的插件

 rpm -qa | grep yum-plugin-priorities  
 yum search yum-plugin-priorities

第二:安装yum-plugin-priorities.noarch插件

yum -y install yum-plugin-priorities

第三:查看插件是否启用

cat /etc/yum/pluginconf.d/priorities.conf   
enabled = 1    //1为启用;0为禁用

第四:修改本地yum源优先使用

[root@test ~]# ll /etc/yum.repos.d/   
total 8   
-rw-r--r--. 1 root root 2573 May 15  2015 CentOS-Base.repo   
-rw-r--r--. 1 root root   67 Jun 20 06:04 local.repo  

//有两个repo文件   
[root@test ~]# vi /etc/yum.repos.d/local.repo   
[local]   
name=local   
baseurl=file:///mnt/centos   
enabled=1   
gpgcheck=0   
priority=1    //在原基础上加入priority=1 ;数字越小优先级越高   
              //可以继续修改其他源的priority值,经测试仅配置本地源的优先级为priority=1就会优先使用本地源了

第五:yum进行测试安装查看优先级修改是否有效:

案例11:yum配置enablerepo使能repo

# dnf --disablerepo="*" --enablerepo="epel" list available
OR
# yum --disablerepo="*" --enablerepo="epel" list available
# dnf --enablerepo="epel" install <package_name>
OR
# yum --enablerepo="epel" install <package_name>

案例12:查yum repo的详情:

yum repolist -v

在这里插入图片描述

案例13:查询机器内repo状态

yum repolist --all
yum repolist --enabled
yum repolist --disabled

案例14:查询repo的具体信息(包括url)

yum repolist -v

案例15:centos8系查找某一文件的提供者:

 dnf   provides /bin/bash
 yum provides /bin/bash
 dnf   whatprovides /bin/bash
 yum whatprovides /bin/bash

案例16:centos8系通过文件来安装指定父包

yum reinstall /usr/bin/wget
dnf reinstall /usr/bin/wget

yum的报错汇总:

yum makecache报错:(原因:没有足够的cache了)

报错信息:

[root@host cache]# yum makecache fast
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror
Determining fastest mirrors

 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

Insufficient space in download directory /var/cache/yum/sw_64/$releasever/alios_sw_myyum
    * free   0
    * needed 100 k

yum安装遇到rpm数据库报错:

报错信息:

在这里插入图片描述

在这里插入图片描述

解决办法:

【解决办法:重新构建rpm数据库】

[root@cly ~]# cd /var/lib/rpm
[root@cly rpm]# ls
Basenames     __db.001  __db.003  Group       Name          Packages     Requirename  Sigmd5
Conflictname  __db.002  Dirnames  Installtid  Obsoletename  Providename  Sha1header   Triggername
[root@cly rpm]# rm -rf __db*
[root@cly rpm]# rpm --rebuilddb

在这里插入图片描述

yum自动更新机制自动激活了yum进程导致的报错:

在这里插入图片描述

原因:

yum自动更新机制自动激活了yum进程

解决:

办法好几个具体如下
 rm -f /var/run/yum.pid

 /etc/init.d/yum-updatesd stop

 如果我们不需要自动更新服务,可以直接删除它:yum remove yum-updatesd

不过删除该服务之后,以后的更新要用下面的命令手工来完成了:yum update

yum list安装中yum-plugin-local插件影响checkout KEY

问题:

在批量安装yum list,突然FAIL了,由于rpm包yum安装时我的配置文件默认设置 gpgcheck=0 不检查key 但是还是报错了

原因 :

批量脚本安装了yum-plugin-local.noarch ,该包安装后会在/etc/yum/pluginconf.d/ 生成 local.conf

当我们yum一个新的数据包时:、/etc/yum.repos.d 会多生成_local.repo 这个文件,该文 中 gpgcheck=true 默认开启了 key的检查,可能由于_local.repo的优先级相比较高(准确原因待学习) 源repo文件失效

复现:

[root@localhost ~]# yum -y install yum-plugin-local.noarch   【误安装yum-plugin-local.noarch】
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package yum-plugin-local.noarch 0:1.1.31-52.el7 will be installed
--> Processing Dependency: createrepo for package: yum-plugin-local-1.1.31-52.el7.noarch
--> Running transaction check
---> Package createrepo.noarch 0:0.9.9-28.el7 will be installed
--> Processing Dependency: python-deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Processing Dependency: deltarpm for package: createrepo-0.9.9-28.el7.noarch
--> Running transaction check
---> Package deltarpm.x86_64 0:3.6-3.el7 will be installed
---> Package python-deltarpm.x86_64 0:3.6-3.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================
 Package                             Arch                      Version                           Repository               Size
===============================================================================================================================
Installing:
 yum-plugin-local                    noarch                    1.1.31-52.el7                     base                     29 k
Installing for dependencies:
 createrepo                          noarch                    0.9.9-28.el7                      base                     94 k
 deltarpm                            x86_64                    3.6-3.el7                         base                     82 k
 python-deltarpm                     x86_64                    3.6-3.el7                         base                     31 k

Transaction Summary
===============================================================================================================================
Install  1 Package (+3 Dependent packages)

Total download size: 236 k
Installed size: 587 k
Downloading packages:
(1/4): deltarpm-3.6-3.el7.x86_64.rpm                                                                    |  82 kB  00:00:00
(2/4): python-deltarpm-3.6-3.el7.x86_64.rpm                                                             |  31 kB  00:00:00
(3/4): yum-plugin-local-1.1.31-52.el7.noarch.rpm                                                        |  29 kB  00:00:00
(4/4): createrepo-0.9.9-28.el7.noarch.rpm                                                               |  94 kB  00:00:00
-------------------------------------------------------------------------------------------------------------------------------
Total                                                                                          426 kB/s | 236 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : deltarpm-3.6-3.el7.x86_64                                                                                   1/4
  Installing : python-deltarpm-3.6-3.el7.x86_64                                                                            2/4
  Installing : createrepo-0.9.9-28.el7.noarch                                                                              3/4
  Installing : yum-plugin-local-1.1.31-52.el7.noarch                                                                       4/4
  Verifying  : createrepo-0.9.9-28.el7.noarch                                                                              1/4
  Verifying  : deltarpm-3.6-3.el7.x86_64                                                                                   2/4
  Verifying  : yum-plugin-local-1.1.31-52.el7.noarch                                                                       3/4
  Verifying  : python-deltarpm-3.6-3.el7.x86_64                                                                            4/4

Installed:
  yum-plugin-local.noarch 0:1.1.31-52.el7

Dependency Installed:
  createrepo.noarch 0:0.9.9-28.el7           deltarpm.x86_64 0:3.6-3.el7           python-deltarpm.x86_64 0:3.6-3.el7

Complete!
---------------------------------------------------------------------------------------------------------------------------------------
[root@localhost ~]# yum -y install wget   【此时在随便安装一个包】
Loaded plugins: fastestmirror, local
Loading mirror speeds from cached hostfile
 * base: mirrors.huaweicloud.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.14-18.el7_6.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================
 Package                   Arch                        Version                                 Repository                 Size
===============================================================================================================================
Installing:
 wget                      x86_64                      1.14-18.el7_6.1                         base                      547 k

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

Total download size: 547 k
Installed size: 2.0 M
Downloading packages:
wget-1.14-18.el7_6.1.x86_64.rpm                                                                         | 547 kB  00:00:00
Could not find valid repo at: /var/lib/yum/plugins/local 
 注意:此时/etc/yum.repos.d/下面生成了_local.repo,这个repo会致使其他repo失效
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : wget-1.14-18.el7_6.1.x86_64                                                                                 1/1
  Verifying  : wget-1.14-18.el7_6.1.x86_64                                                                                 1/1

Installed:
  wget.x86_64 0:1.14-18.el7_6.1

Complete!
--------------------------------------------------------------------------------------------------------
[root@localhost ~]# yum -y install zziplib-utils.sw_64  【安装yum-plugin-local.noarch,在用yum不能正常使用】
Failed to set locale, defaulting to C
Loaded plugins: fastestmirror, local, refresh-packagekit
Unable to connect to dbus
You have enabled checking of packages via GPG keys. This is a good thing.
However, you do not have any GPG public keys installed. You need to download
the keys for packages you wish to install and install them.
You can do that by running the command:
rpm --import public.gpg.key
Alternatively you can specify the url to the key you would like to use
for a repository in the 'gpgkey' option in a repository section and yum
will install it for you.
For more information contact your distribution or package provider.
Problem repository: _local


yum 安装包阶段报错:/usr/bin/yum

在这里插入图片描述

安装rpm包时,如果不慎按了Ctrl+C中止了安装,那么继续安装时将会提示warning: waiting for transaction lock,从而安装不能继续。

这是由于前次安装没有完毕,安装步骤被锁。可以删除/var/lib/rpm/RPMLOCK 和rpmdb_deadlock等文件,如果没有这些文件的话,可以到/var/lock/rpm/目录下找到一个transaction文件,将其删掉,rpm包的安装就可以继续下去了

报错:

Running transaction
Traceback (most recent call last):
  File "/usr/bin/yum", line 29, in <module>
    yummain.user_main(sys.argv[1:], exit_code=True)
  File "/usr/share/yum-cli/yummain.py", line 375, in user_main
    errcode = main(args)
  File "/usr/share/yum-cli/yummain.py", line 281, in main
    return_code = base.doTransaction()
  File "/usr/share/yum-cli/cli.py", line 816, in doTransaction
    resultobject = self.runTransaction(cb=cb)
  File "/usr/lib/python2.7/site-packages/yum/__init__.py", line 1833, in runTransaction
    lastdbv = self.history.last()
  File "/usr/lib/python2.7/site-packages/yum/history.py", line 1271, in last
    ret = self.old([], 1, complete_transactions_only)
  File "/usr/lib/python2.7/site-packages/yum/history.py", line 1220, in old
    executeSQL(cur, sql, params)
  File "/usr/lib/python2.7/site-packages/yum/sqlutils.py", line 166, in executeSQLQmark
    return cursor.execute(query)
sqlite3.OperationalError: database is locked

分析:

注意:报错信息 sqlite3.OperationalError: database is locked

ls -l /var/lib/yum/history #查看一下这个目录下的文件,有一个类似这个history-2019-08-22.sqlite的文件。 然后移除此文件与journal文件,重新安装包,可以了。 大致猜想是缓存导致,或者之前有yum安装包,但是手动kill掉了。数据保存在这个history目录下。

Yum正常后,/var/lib/yum/history/ /var/lib/rpm/变化情况:

在这里插入图片描述
在这里插入图片描述

yum报错except KeyboardInterrupt, e:

在这里插入图片描述

分析:

yum依赖的python(/bin/yum),与系统内python版本不匹配

分析过程:


A:先看下系统python命令,所在系统位置(which python)---> /bin/python
B:先看下有多少python命令文件:ls /bin | grep python

在这里插入图片描述

C:查下python命令行详情:

在这里插入图片描述

D:在查看下python2命令行详情:

在这里插入图片描述

E:修改 yum依赖的python(/bin/yum)文件:

在这里插入图片描述

yum报错except OSError, e:

原因:

因为yum采用python作为命令解释器,原来系统自带的python解释器为python2.7

报错信息:

在这里插入图片描述

解决:

vim /usr/libexec/urlgrabber-ext-down
#! /usr/bin/python改成#! /usr/bin/python2

报错 File “/usr/bin/yum”, line 30

报错信息:

File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:

原因:

yum包管理是使用python2.x写的,将python2.x升级到python3.1.3以后,由于python版本语法兼容性导致问题出现

解决办法:

修改yum配置文件,将python版本指向以前的旧版本

# vi /usr/bin/yum
1.	#!/usr/bin/python2.
2.	修改/usr/libexec/urlgrabber-ext-down文件,更改python版本
1.	# vi /usr/libexec/urlgrabber-ext-down
2.	#!/usr/bin/python2.7

错误File “/usr/bin/yum”, line 30 except KeyboardInterrupt, e:

同上

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值