部署yum仓库
一. Yum概述
1.yum简介
- 基于RPM包构建的软件更新机制
- 可以自动解决依赖关系
- 所有软件包由集中到YUM软件仓库提供
2.yum工作原理
c/s模式
- 客户端根据配置文件找到yum仓库服务器的位置
- 服务端向客户端发送元数据包(包含 软件依赖关系 软件的位置) #相当于软件安装目录
- 客户端下载后,在元数据包中的查找到目标,发送请求
- 服务器响应并将相关软件包和依赖关系发送给客户端,客户端下载安装
二. yum配置文件
1.yum主配置文件
[root@Root1 ~]# vim /etc/yum.conf
1 [main]
2 cachedir=/var/cache/yum/$basearch/$releasever
3 keepcache=0
4 debuglevel=2
5 logfile=/var/log/yum.log
6 exactarch=1
7 obsoletes=1
8 gpgcheck=1
9 plugins=1
10 installonly_limit=5
11 bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs .centos.org/bug_report_page.php?category=yum
12 distroverpkg=centos-release
#2行:yum下载的RPM包的缓存目录 $basearch代表硬件架构 $releasever系统版本比如7
#3行:是否保存缓存 0代表不保存,1代表保存
#4行:调试级别了解即可
#5行:日志文件位置
#6行:是否允许不同版本的rpm安装
#7行:update 的一个参数是否可以允许旧版本的运行
#8行:验证秘钥
#9行:是否允许插件,1代表可以
#10行:保存几个内核,5代表5个
2.yum仓库设置文件
[root@Root1 ~]# cd /etc/yum.repos.d/
[root@Root1 yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo CentOS-Sources.repo
#yum.repos.d目录下均为仓库设置文件
3.配置文件主要格式
1 [local] #描述信息
2 name=local #描述信息
3 baseurl=file:///mnt #提供仓库的路径,这里是本地源,也可以是存放源的网站,比如阿里云,各大高校的源网址
4 gpgcheck=0 #是否开启校验,这里为0,代表关闭校验
4.软件仓库的提供方式
- FTP服务
baseurl=ftp://ip地址/地址内的路径
- HTTP服务
baseurl=http://域名或者ip地址/地址里的路径
- 本地目录
baseurl=file://绝对路径
三. yum命令
1.安装
[root@Root1 /]# yum -y install ftp
.
.
.
已安装:
ftp.x86_64 0:0.17-67.el7
2.更新
[root@Root1 /]# yum -y install ftp
.
.
.
软件包 ftp-0.17-67.el7.x86_64 已安装并且是最新版本
3.查询
- 显示可用的安装包——yum list
[root@Root1 /]# yum list [软件名]
[root@Root1 /]# yum list ftp
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
已安装的软件包
ftp.x86_64 0.17-67.el7 @base
- 显示安装包详情——yum info
[root@Root1 /]# yum info [软件名]
[root@Root1 /]# yum info ftp
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
已安装的软件包
名称 :ftp
架构 :x86_64
版本 :0.17
发布 :67.el7
大小 :96 k
源 :installed
来自源:base
简介 : The standard UNIX FTP (File Transfer Protocol) client
网址 :ftp://ftp.linux.org.uk/pub/linux/Networking/netkit
协议 : BSD with advertising
描述 : The ftp package provides the standard UNIX command-line FTP (File
: Transfer Protocol) client. FTP is a widely used protocol for
: transferring files over the Internet and for archiving files.
:
: If your system is on a network, you should install ftp in order to do
: file transfers.
- 根据关键字查找软件安装包——yum search
[root@Root1 /]# yum search vsf
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
================================== N/S matched: vsf ===================================
vsftpd-sysvinit.x86_64 : SysV initscript for vsftpd daemon
vsftpd.x86_64 : Very Secure Ftp Daemon
名称和简介匹配 only,使用“search all”试试。
- 根据命令名查找对应的软件包——yum provides
[root@Root1 /]# yum provides ftp
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.bupt.edu.cn
* extras: mirrors.bupt.edu.cn
* updates: mirrors.bupt.edu.cn
ftp-0.17-67.el7.x86_64 : The standard UNIX FTP (File Transfer Protocol) client
源 :base
ftp-0.17-67.el7.x86_64 : The standard UNIX FTP (File Transfer Protocol) client
源 :@base
- 查询安装包组——yum grouplist
yum grouplist [包组名] #安装包组的查询 不加包组名 就是显示所有
- 查询安装包组的详细信息——yum groupinfo
yum groupinfo <包组名> #显示包组的详细信息
#yum groupinfo Minimal Install #最小化安装包组的详细信息
- 查看yum的历史使用记录——yum history
yum history
已加载插件:fastestmirror, langpacks
ID | 登录用户 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------
4 | root <root> | 2024-05-05 14:49 | Install | 1
3 | root <root> | 2024-05-05 14:48 | Install | 1
2 | root <root> | 2024-04-30 09:09 | I, O, U | 978 EE
1 | 系统 <空> | 2024-03-28 09:37 | Install | 1372
history list
4.卸载
- 卸载已安装的软件——yum remove
[root@Root1 /]# yum remove tree #移除tree软件
已加载插件:fastestmirror, langpacks
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 删除
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在删除:
tree x86_64 1.6.0-10.el7 @base 87 k
事务概要
=======================================================================================
移除 1 软件包
安装大小:87 k
是否继续?[y/N]:y #二次确认
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
删除:
tree.x86_64 0:1.6.0-10.el7 #成功移除
完毕!
- 删除和恢复所有的依赖——yum history undo
yum history
已加载插件:fastestmirror, langpacks
ID | 登录用户 | 日期和时间 | 操作 | 变更数
-------------------------------------------------------------------------------
4 | root <root> | 2024-05-05 14:49 | Install | 1
3 | root <root> | 2024-05-05 14:48 | Install | 1
2 | root <root> | 2024-04-30 09:09 | I, O, U | 978 EE
1 | 系统 <空> | 2024-03-28 09:37 | Install | 1372
history list
yum history undo n
yum history redo n
#n为历史记录中的ID
- 只下载不安装——yum install --downloadonly [软件名] --downloaddir [指定rpm包存放路径]
当内网的一台主机安装某个软件包却缺少依赖包时,可以先由一台可连接外网的服务器下载依赖包,之后共享给这台主机
四. yum仓库搭建
1.搭建本地yum仓库
- 挂载
[root@Root1 /]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
- 备份yum网络
[root@Root1 yum.repos.d]# mkdir bak
[root@Root1 yum.repos.d]# mv *.repo bak
[root@Root1 yum.repos.d]# ls
bak
- 新建配置文件
[root@Root1 yum.repos.d]# vim local.repo
1 [local] #描述信息
2 name=local #描述信息
3 baseurl=file:///mnt #提供仓库的路径,这里是本地源,也可以是存放源的网站,比如阿里云,各大高校的源网址
4 gpgcheck=0 #是否开启校验,这里为0,代表关闭校验
- 清除yum缓存
yum clean all
- 建立本地源
yum makecache
- 安装软件查看源的变化
[root@Root1 yum.repos.d]# yum -y install tree
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
tree x86_64 1.6.0-10.el7 local 46 k #源已变成local
事务概要
=======================================================================================
安装 1 软件包
总下载量:46 k
安装大小:87 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7
完毕!
2.使用http搭建yum仓库
- 配置服务端
[root@localhost ~]# yum -y install httpd #安装httpd服务程序
[root@localhost ~]# systemctl disable firewalld #关闭防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0 #降低限制权限
[root@localhost ~]# mount /dev/sr0 /var/www/html #挂载
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# systemctl start httpd #启动http服务
[root@localhost ~]# systemctl status httpd #查看http服务状态是否正常
- 配置客户端
[root@localhost ~]# systemctl disable firewalld #关闭防火墙
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# setenforce 0 #降低限制权限
[root@Root2 ~]# cd /etc/yum.repos.d/ #进入配置文件路径
[root@Root2 yum.repos.d]# mkdir bak #备份repo配置文件
[root@Root2 yum.repos.d]# mv *.repo bak #移动repo配置文件至bak中
[root@Root2 yum.repos.d]# vim http.repo #创建http的yum仓库配置文件
[http]
name=http
baseurl=http://192.168.137.101
gpgcheck=0
:wq #保存退出
[root@Root2 yum.repos.d]# yum clean all #清除网络源缓存
[root@Root2 yum.repos.d]# yum makecache #建立元数据缓存
[root@Root2 yum.repos.d]# yum -y install tree #安装tree软件
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
tree x86_64 1.6.0-10.el7 http 46 k #源已变为http
事务概要
=======================================================================================
安装 1 软件包
总下载量:46 k
安装大小: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
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7 #安装完成
完毕!
3.使用FTP搭建yum仓库
- 服务端配置
[root@localhost ~]# systemctl disable firewalld #关闭防火墙
[root@localhost ~]# setenforce 0 #降低限制权限
[root@localhost ~]# yum -y install vsftpd #安装ftp服务端软件:vsftpd
[root@localhost ~]# cd /var/ftp #进入ftp目录
[root@localhost ftp]# mkdir test #创建文件保存目录test
[root@localhost ftp]# mount /dev/sr0 /var/ftp/test #挂载到ftp服务的文件保存路径
[root@localhost ~]# systemctl start vsftpd #开启vsftp服务
[root@localhost ~]# systemctl status vsftpd #查看vsftp服务状态是否正常
[root@Root2 ~]# cd /etc/yum.repos.d/ #进入配置文件路径
[root@Root2 yum.repos.d]# mkdir bak #备份repo配置文件
[root@Root2 yum.repos.d]# mv *.repo bak #移动repo配置文件至bak中
[root@Root2 yum.repos.d]# vim ftp.repo #创建ftp的yum仓库配置文件
[ftp]
name=ftp
baseurl=ftp://192.168.137.101/test
gpgcheck=0
:wq #保存退出
[root@Root2 yum.repos.d]# yum clean all #清除网络源缓存
[root@Root2 yum.repos.d]# yum makecache #建立元数据缓存
[root@Root2 yum.repos.d]# yum -y install tree #安装任意程序,这里以tree为例
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================================
Package 架构 版本 源 大小
=======================================================================================
正在安装:
tree x86_64 1.6.0-10.el7 ftp 46 k #源已变为ftp
事务概要
=======================================================================================
安装 1 软件包
总下载量:46 k
安装大小: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
警告:RPM 数据库已被非 yum 程序修改。
正在安装 : tree-1.6.0-10.el7.x86_64 1/1
验证中 : tree-1.6.0-10.el7.x86_64 1/1
已安装:
tree.x86_64 0:1.6.0-10.el7 #安装完成
完毕!