07-服务管理-02-yum常用命令和yum源
创始人
2024-01-29 16:25:44
0

文章目录

  • 1. yum常用命令
    • 1.1 安装卸载服务
      • - 安装
      • - 升级
      • - 卸载
      • - 清空缓存
      • - 只下载不安装
    • 1.2 查看
      • - 查看yum库
      • - 列出所有包
      • - 查看包信息
      • - 查看文件所在包
    • 1.3 包组的使用
  • 2. 指定yum源
  • 3. 常用yum源
    • 1)epel源
    • 2)163源
    • 3)阿里源
    • 4)清华源
  • 4. yum的一些操作
    • 4.1 yum缓存的配置
    • 4.2 yum设置代理
  • 5.FAQ
    • 1)Transaction check error
    • 2)关于镜像不可用

1. yum常用命令

1.1 安装卸载服务

- 安装

# yum install  xxx xxx  -y

- 升级

# yum update xxx -y

- 卸载

# yum remove xxx -y

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

# rpm -e --nodeps xxx

- 清空缓存

# yum clean all

- 只下载不安装

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

1.2 查看

- 查看yum库

# yum repolist

- 列出所有包

# yum list
# yum list 包名

- 查看包信息

# yum info 包名

- 查看文件所在包

# yum provides  /usr/bin/scp

1.3 包组的使用

和包的使用基本相同:

# yum grouplist
# yum groupinstall xxx

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源示例

说明:

  • [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

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

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

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

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      #设定保存时长

4.2 yum设置代理

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

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_64file /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
  • 解决

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

rpm -e docker-ce-cli-1:19.03.8-3.el7.x86_64yum install docker-ce-18.06.0.ce-3.el7.x86_64

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"
  • 解决
    没有yum源的公钥,安装命令去掉 -y
yum install docker-ce

安装的时候会提示没有密钥,选择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

在这里插入图片描述

相关内容

热门资讯

国务院食安办部署加强暑期、汛期...   新华社北京7月26日电 记者26日从市场监管总局获悉,国务院食安办近日印发通知,要求各地食安办切...
石榴花开 籽籽同心丨湖北姑娘在...   石榴云/新疆日报讯(记者 甘兴华报道)七月的哈巴河县彩虹布拉克景区,阳光穿透云层温柔地铺展在起伏...
“中国式现代化的万千气象”网络...   7月25日,“中国式现代化的万千气象”网络名人新疆行活动走进尉犁县兴平镇达西村,感受这里繁荣富裕...
绝不容忍!中国驻日本大使馆向日...   25日,针对日本政府纵容台湾地区外事部门负责人林佳龙入境窜访,中国驻日本大使馆公使施泳紧急向日本...
上半年创新药和医疗器械获批数量...   本报北京7月26日电 (记者申少铁)记者从国家药监局获悉:今年上半年我国批准创新药43个、创新医...
背景调查应守底线,“滥调”恐涉...   近年来,随着市场主体增加、人才流动加速,背景调查越来越频繁地出现在招聘流程中,调查的内容与维度也...
国际观察丨伊朗与欧洲会谈无突破...   新华社伊斯坦布尔7月26日电 题:伊朗与欧洲会谈无突破 核问题“拉锯”走向何方  新华社记者王腾...
特朗普到访英国苏格兰引发民众抗...   新华社伦敦7月26日电(记者 郑博非)大批民众26日走上英国苏格兰地区首府爱丁堡和阿伯丁市街头,...
原来西瓜皮也是一味药 可用来解...   #原来西瓜皮也是一味药 #吃西瓜可以不丢西瓜皮 中医称西瓜皮为“西瓜翠衣”,用来解暑、生津、平心...
72年来首次!中国“最神秘军校...   位于山东青岛的  中国人民解放军海军潜艇学院  是专门培养海军潜艇、防险救生  和水下新质作战力...