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

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_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

  • 解决

    和前边的版本冲突,卸载一个版本再安装即可。(前边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

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) <docker@docker.com>"
指纹       : 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) <security@centos.org>"
指纹       : 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
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

玄德公笔记

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值