[toc]

yum使用功能

yum安装、更新和删除

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# 语法结构
yum 选项 软件

# yum安装(自动解决依赖)
yum install 软件名 # 在当前源搜索软件进行安装,自动解决依赖软件
yum install -y 软件名 # 免交互安装软件
yum localinstall rpm包所在路径 # 使用本地现有的rpm包进行安装
yum install -y URL # 使用URL链接进行安装
yum reinstall 软件名 # 重新安装软件(软件的配置文件缺失可以使用此命令重新安装)

# yum更新

yum check-update # 检查哪个软件可以进行更新(有bug需要tab快捷输入)
yum update 软件名 # 更新单个软件
yum update # 更新本机所有软件(危险!!包括系统内核)
yum update -y # 更新本机所有软件且免交互(危险!!包括系统内核)

# yum删除
yum erase -y 软件名 # 删除指定软件和 相关依赖!!
yum remove -y 软件名 # 删除指定软件和 相关依赖!!

yum缓存

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
## 语法结构
yum 选项 软件

# 选项
yum makecache # 加载缓存
yum clean all # 清除所有yum缓存
yum clean 软件包 # 只清除单个软件的缓存

# 默认缓存软件包, 修改yum全局配置文件
vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1 //启动缓存

ls /var/cache/yum/x86_64/7/base/packages # 查看缓存的rpm包(base代表从此源下载)

# 将软件下载至指定目录 例:
yum install -y 软件名 --downloadonly --downloaddir=/存放路径
--downloadonly # 仅下载不安装
--downloaddir # 指定下载的目录

#PS: 需先安装以下插件
yum install -y yum-plugin-downloadonly

yum历史记录

1
2
3
4
5
6
7
## 语法结构
yum 选项 软件

# 选项
yum history # 查看历史执行yum命令
yum history info N # 查询历史执行yum命令ID详细信息
yum history undo N # 撤销历史执行过的yum命令

yum全局配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# yum全局配置文件
/etc/yum.conf # 全局配置文件
/etc/yum.repos.d/目录下的所有.repo文件 # 子配置文件(下载源)

vim /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever //缓存目录
keepcache=0 //缓存软件包, 1启动 0 关闭
debuglevel=2 //调试级别
logfile=/var/log/yum.log //日志记录位置
exactarch=1 //检查平台是否兼容
obsoletes=1 //检查包是否废弃
gpgcheck=1 //检查来源是否合法,需要有制作者的公钥信息
plugins=1 //是否启用查询
installonly_limit=5

bugtracker_url
# metadata_expire=90m //每小时手动检查元数据
# in /etc/yum.repos.d //包含repos.d目录

yum源管理

换源

1
2
3
4
5
6
7
# Base源配置的两种方法
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

# epel源配置的两种方法
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

yum查询

1
2
3
4
5
# 语法结构
yum 选项
# 选项
yum list # 展开yum源可安装的软件列表(可以通过管道符配合'grep'命令进行模糊搜索)
yum info # 展开软件包的详情信息(后跟软件名)

yum仓库

1
2
3
4
5
6
7
8
## 语法结构
yum 选项 软件

# 选项
yum repolist # 列出yum源可用的软件仓库
yum repolist all # 列出全部yum源可用和禁用的仓库
yum provide`yums` 文件或命令 # 查看这个文件或命令属于哪个包
`yum-config-manager --enable # 启用软件包(建议直接修改配置文件)

yum包组

1
2
3
4
5
6
7
8
9
10
11
## 语法结构
yum 选项 软件

# 选项
yum groups list # 列出已经安装和所有可使用的软件组

#安装一整个组的软件
`yum groups install 软件包组名 \
..

yum groups remove -y 软件包组名 # yum删除软件包组

制作企业级yum仓库

安装并启动vsftpd服务

1
2
yum install -y vsftpd		# 安装一个vsftpd服务,让机器编程网络服务
systemctl start vsftpd # 启动ftp服务

关闭seLinux和防火墙

1
2
3
4
5
6
7
# 关闭seLinux
getenforce 0 # 关闭selinux(临时关闭)
vim /etc/sysconfig/selinux # 永久关闭selinux
SELINUX=disabled ## 修改配置文件
# 关闭防火墙
systemctl stop firewalld # 停止防火墙(临时关闭)
systemctl disable firewalld # 永久关闭防火墙

准备base源目录和文件

1
2
3
4
mount /dev/cdrom /mnt/			# 挂载磁盘
df -h # 检查磁盘挂载状态
mkdir /var/ftp/base # 在ftp目录下创建好base目录
cp /mnt/Packages/* /var/ftp/base/ # 拷贝所有的安装包到仓库目录

制作仓库

1
2
yum install -y createrepo		# 安装一个仓库制作命令
createrepo /var/ftp/base # 将/var/ftp创建为仓库

配置并使用base源

1
2
3
4
5
6
7
gzip /etc/yum.repos.d/*							# 将原使用的源压缩
vim /etc/yum.repos.d/chaojibaolongzhanshi.repo # 创建新的源文件并进行配置
[chaojibaolongzhanshi]
name=chaojibaolongzhanshi_base
baseurl=ftp://10.0.0.100/base
gpgcheck=0
enabled=1

查看当前所有可用源

1
2
3
4
yum repolist		# 查看当前yum的源
repo id repo name status
chaojibaolongzhanshi chaojibaolongzhanshi_base 0
repolist: 0

检查源是否可用

1
2
3
4
5
6
7
8
9
10
11
yum reinstall -y tree			# 重新安装tree进行测试
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
chaojibaolongzhanshi | 2.9 kB 00:00
chaojibaolongzhanshi/primary_db | 3.1 MB 00:00
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

制作base源和epel源并用另一台设备访问

10.0.0.100设备

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 安装并启动vsftpd服务
yum install -y vsftpd # 安装一个vsftpd服务,让机器编程网络服务
systemctl start vsftpd # 启动ftp服务

# 关闭selinux和防火墙
vim /etc/sysconfig/selinux # 永久关闭selinux
SELINUX=disabled ## 修改配置文件
systemctl disable firewalld # 永久关闭防火墙

# 准备base源和epel源目录和文件
## 准备base源目录和文件
mount /dev/cdrom /mnt/ # 挂载磁盘
df -h # 检查磁盘挂载状态
mkdir /var/ftp/base # 在ftp目录下创建好base目录
cp /mnt/Packages/* /var/ftp/base/ # 拷贝所有的安装包到仓库目录
## 准备epel源目录和文件
mkdir /var/ftp/epel # 创建epel仓库的目录
wget http://rpmfind.net/linux/centos/7.9.2009/os/x86_64/Packages/tree-1.6.0-10.el7.x86_64.rpm -P /var/ftp/epel/ # 将chree的包下载至epel仓库的路径下

# 制作仓库
yum install -y createrepo # 安装一个仓库制作命令
createrepo /var/ftp/base # 将/var/ftp创建为仓库
createrepo /var/ftp/epel # 将/var/ftp创建为仓库

10.0.0.101设备

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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# 配置并使用base源和epel源
gzip /etc/yum.repos.d/* # 将原来使用的源压缩

vim /etc/yum.repos.d/baolongzhanshi # 创建base源文件并进行配置
[baolongzhanshi]
name=baolongzhanshi_base
baseurl=ftp://10.0.0.100/base
gpgcheck=0
enabled=1
vim /etc/yum.repos.d/chaojibaolongzhanshi # 创建epel源文件并进行配置
[chaojibaolongzhanshi]
name=chaojibaolongzhanshi_epel
baseurl=ftp://10.0.0.100/epel
gpgcheck=0
enabled=1

yum repolist # 查看当前yum的源
repo id repo name status
baolongzhanshi baolongzhanshi_base 0
chaojibaolongzhanshi chaojibaolongzhanshi_epel 0
repolist: 0

# 检查源是否可用

​```bash
yum reinstall -y tree # 重新安装tree进行测试
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be reinstalled
--> Finished Dependency Resolution

Dependencies Resolved

========================================================================================
Package Arch Version Repository Size
========================================================================================
Reinstalling:
tree x86_64 1.6.0-10.el7 baolongzhanshi 46 k

Transaction Summary
========================================================================================
Reinstall 1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
tree-1.6.0-10.el7.x86_64.rpm | 46 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : tree-1.6.0-10.el7.x86_64 1/1
Verifying : tree-1.6.0-10.el7.x86_64 1/1

Installed:
tree.x86_64 0:1.6.0-10.el7

Complete!