• 07-服务管理-02-yum常用命令和yum源


    1. yum常用命令

    1.1 安装卸载服务

    - 安装

    # yum install  xxx xxx  -y
    
    • 1

    - 升级

    # yum update xxx -y
    
    • 1

    - 卸载

    # yum remove xxx -y
    
    • 1

    谨慎使用,因为依赖会被卸载。一般使用以下命令卸载:

    # rpm -e --nodeps xxx
    
    • 1

    - 清空缓存

    # yum clean all
    
    • 1

    - 只下载不安装

    # yum install -y xxx --downloadonly --downloaddir=/usr/local/src
    
    • 1

    1.2 查看

    - 查看yum库

    # yum repolist
    
    • 1

    - 列出所有包

    # yum list
    # yum list 包名
    
    • 1
    • 2

    - 查看包信息

    # yum info 包名
    
    • 1

    - 查看文件所在包

    # yum provides  /usr/bin/scp
    
    • 1

    1.3 包组的使用

    和包的使用基本相同:

    # yum grouplist
    # yum groupinstall xxx
    
    • 1
    • 2

    2. 指定yum源

    示例如下:

    # vim /etc/yum.repos.d/test.repo
    [test]
    name=test
    enabled=1
    gpgcheck=0
    #baseurl=file:///data/ftp/yum_data #本地文件为yum源示例
    #baseurl=ftp://172.16.8.100/centos6u6 #ftp服务器yum源示例
    baseurl=http://yumcto.xxx.com.cn/ #http的yum源示例
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    说明:

    • [test] :仓库ID,有唯一性,根据需求自定义
    • name=test : 仓库名
    • enabled=1 : 1,激活该仓库
    • gpgcheck=0 : 0,不检查软件包签名

    3. 常用yum源

    1)epel源

    wget http://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
    rpm -ivh epel-release-latest-7.noarch.rpm
    
    • 1
    • 2

    2)163源

    # curl -o  /etc/yum.repos.d/CentOS-Base-163.repo  http://mirrors.163.com/.help/CentOS7-Base-163.repo
    # wget -O  /etc/yum.repos.d/CentOS-Base-163.repo http://mirrors.163.com/.help/CentOS7-Base-163.repo
    
    
    • 1
    • 2
    • 3

    3)阿里源

    # wget -O /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    # curl -o /etc/yum.repos.d/CentOS-Base-ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    
    
    • 1
    • 2
    • 3

    4)清华源

    # CentOS-Base.repo
    #
    # The mirror system uses the connecting IP address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  You should use this for CentOS updates
    # unless you are manually picking other mirrors.
    #
    # If the mirrorlist= does not work for you, as a fall back you can try the
    # remarked out baseurl= line instead.
    #
    #
    
    [base]
    name=CentOS-$releasever - Base
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
    #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43

    4. yum的一些操作

    4.1 yum缓存的配置

    [main]
    cachedir=/var/cache/yum      #yum下载的RPM包的缓存目录
    keepcache=0                #缓存是否保存,1保存,0不保存。
    debuglevel=2                #调试级别(0-10),默认为2(并不知道具体作用)。
    logfile=/var/log/yum.log         #yum的日志文件所在的位置
    exactarch=1                 #在更新的时候,是否允许更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。
    obsoletes=1                 #相当于upgrade,允许更新陈旧的RPM包。
    gpgcheck=1                 #是否检查GPG(GNU Private Guard),一种密钥方式签名。
    plugins=1                 #是否允许使用插件,默认是0不允许,但是我们一般会用yum-fastestmirror这个插件。
    installonly_limit=3            #允许保留多少个内核包。
    exclude=selinux*           #屏蔽不想更新的RPM包,可用通配符,多个RPM包之间使用空格分离
    metadata_expire=90m      #设定保存时长
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    4.2 yum设置代理

    #vim /etc/yum.conf
    proxy=http://代理服务器ip:port
    
    • 1
    • 2

    5.FAQ

    1)Transaction check error

    • 报错

      输出如下:

    Transaction check error:
      file /usr/bin/docker from install of docker-ce-18.06.0.ce-3.el7.x86_64 conflicts with file from package docker-ce-cli-1:19.03.8-3.el7.x86_64
      file /usr/share/bash-completion/completions/docker from install of docker-ce-18.06.0.ce-3.el7.x86_64 conflicts with file from package docker-ce-cli-1:19.03.8-3.el7.x86_64
    
    
    • 1
    • 2
    • 3
    • 4
    • 解决

      和前边的版本冲突,卸载一个版本再安装即可。(前边19.03安装失败)

    rpm -e docker-ce-cli-1:19.03.8-3.el7.x86_64
    
    yum install docker-ce-18.06.0.ce-3.el7.x86_64
    
    • 1
    • 2
    • 3

    2)关于镜像不可用

    • 报错
    root@node-02:[/root]yum install docker-ce -y
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
    https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#56 - "Proxy CONNECT aborted"
    正在尝试其它镜像。
    
    .............
    
    failure: repodata/repomd.xml from docker-ce-stable: [Errno 256] No more mirrors to try.
    https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 14] curl#56 - "Proxy CONNECT aborted"
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 解决
      没有yum源的公钥,安装命令去掉 -y
    yum install docker-ce
    
    • 1

    安装的时候会提示没有密钥,选择YES密钥会自动被安装。

    从 https://mirrors.aliyun.com/docker-ce/linux/centos/gpg 检索密钥
    导入 GPG key 0x621E9F35:
    用户ID     : "Docker Release (CE rpm) "
    指纹       : 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
    来自       : https://mirrors.aliyun.com/docker-ce/linux/centos/gpg
    是否继续?[y/N]:y
    从 http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7 检索密钥
    导入 GPG key 0xF4A80EB5:
    用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) "
    指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
    来自       : http://mirrors.cloud.tencent.com/centos/RPM-GPG-KEY-CentOS-7
    是否继续?[y/N]:y
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13

    在这里插入图片描述

  • 相关阅读:
    使用 Postman 实现 API 自动化测试
    制糖行业脱色技术A30MP树脂材料
    【LeetCode】经典的环形链表
    Qt使用Cmake编译时自定义控件找不到的问题
    QT5槽函数的重载问题
    vue面试题:说说vue操作真实dom性能瓶颈
    嵌入式工程师面试题3-硬件
    mysql视图中转换表字段的数据类型
    YOLO算法改进Backbone系列之:EfficientViT
    【电路基础2】电容
  • 原文地址:https://blog.csdn.net/xingzuo_1840/article/details/127406183