YUM概述
借助于YUM 软件仓厍,可以元成女农、卸载、自动升级 rpm 软件包等任务,能够自动查找并解决rpm 包之间的K要天系,而无须管理员逐个、手工地去安装每一个rpm包,使管理员仕维护人重 LInux服务器时更加轻松自如。特别是在拥有大量 Linux主机的本地网络中,构建一台源服务器可以大大缓解软件安装、升级等对 Internet的依赖。
YUM工具概述
YUM的配置文件
基本设置:/etc/yum.conf
仓库设置: /etc/yum.repos.d/*.repo
日志文件: /var/log/yum.log
YUM缓存目录
存放下载的软件包、仓库信息等数据
位于 /var/cache/yum/
b
a
s
e
a
r
c
h
/
basearch/
basearch/releasever
yum chean all
yum makecache 清理缓存数据
构建YUM软件仓库
安装 vsftpd服务
[root@server ~]# yum -y install vsftpd
[root@localhost ~]# rpm -q vsftpd
vsftpd-3.0.2-28.el7.x86_64
准备软件仓库目录
[root@localhost ~]# mkdir /var/ftp/centos7
[root@localhost ~]# ls /var/ftp
centos7 pub
[root@localhost ~]# mount /dev/sr0 /mnt #挂载光盘
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# cp -rf /mnt/* /var/ftp/centos7/ #将光盘的内容复制到目录中
[root@localhost ~]# systemctl start vsftpd
#重启vsftpd
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[root@localhost yum.repos.d]# rm -rf *
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]#
配置软件仓库的位置(客户机)
[root@localhost ~]# vim /etc/yum.repos.d/ftp.repo
[root@localhost ~]# cat /etc/yum.repos.d/ftp.repo
[FTP] //标识仓库类别
name=FTP //仓库名称
baseurl=ftp://192.168.30.4/ftp //访问路径
enable=1 //启用此仓库
gpgcheck=0 //不验证软件包的签名
清缓存
[root@localhost ~]# yum clean all //清除缓存
已加载插件:fastestmirror, langpacks
正在清理软件源: FTP
Cleaning up list of fastest mirrors
Other repos take up 401 M of disk space (use --verbose for details)
[root@localhost ~]# yum makecache //建立元数据缓存
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
FTP | 3.6 kB 00:00:00
(1/4): FTP/group_gz | 166 kB 00:00:00
(2/4): FTP/primary_db | 3.1 MB 00:00:00
(3/4): FTP/filelists_db | 3.2 MB 00:00:00
(4/4): FTP/other_db | 1.3 MB 00:00:00
元数据缓存已建立
[root@localhost ~]# yum repolist //显示软件源
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识 源名称 状态
FTP FTP 4,021
repolist: 4,021
本地源
软件仓库
[root@localhost ~]# mount /dev/sr0 /mnt //挂载光盘充当yum仓库
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /mnt //查看挂载后的目录有哪些内容(Packages内为rpm软件包)
CentOS_BuildTag EULA images LiveOS repodata RPM-GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7 TRANS.TBL
配置仓库位置
[root@localhost ~]# vim /etc/yum.repos.d/local.repo //yum软件仓库载此目录下,在创建一个
[local] //表示仓库类别
name=local //仓库名称(说明)
baseurl=file:///mnt //访问路径
enable=1 //启用此仓库
gpgcheck=0 //不验证软件包的签名
清缓存
[root@localhost ~]# yum clean all //清除缓存
已加载插件:fastestmirror, langpacks
正在清理软件源: FTP local
Cleaning up list of fastest mirrors
Other repos take up 401 M of disk space (use --verbose for details)
[root@localhost ~]# yum makecache //建立元数据缓存
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
FTP | 2.9 kB 00:00:00
local | 3.6 kB 00:00:00
(1/7): FTP/filelists_db | 3.2 MB 00:00:00
(2/7): FTP/primary_db | 3.2 MB 00:00:00
(3/7): local/group_gz | 166 kB 00:00:00
(4/7): FTP/other_db | 1.3 MB 00:00:00
(5/7): local/filelists_db | 3.2 MB 00:00:00
(6/7): local/primary_db | 3.1 MB 00:00:00
(7/7): local/other_db | 1.3 MB 00:00:00
元数据缓存已建立
[root@localhost ~]#
查看软件源
[root@localhost ~]# yum repolist
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
源标识 源名称 状态
local local 4,021
repolist: 4,021
安装httpd
[root@localhost ~]# yum -y install httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-88.el7.centos 将被 安装
--> 解决依赖关系完成
依赖关系解决
====================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================
正在安装:
httpd x86_64 2.4.6-88.el7.centos local 2.7 M
事务概要
====================================================================================================================
安装 1 软件包
总下载量:2.7 M
安装大小:9.4 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : httpd-2.4.6-88.el7.centos.x86_64 1/1
验证中 : httpd-2.4.6-88.el7.centos.x86_64 1/1
已安装:
httpd.x86_64 0:2.4.6-88.el7.centos
完毕!
测试安装httpd(客户机)
[root@localhost ~]# yum -y install httpd //安装httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-88.el7.centos 将被 安装
--> 正在处理依赖关系 httpd-tools = 2.4.6-88.el7.centos,它被软件包 httpd-2.4.6-88.el7.centos.x86_64 需要
====================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================
正在安装:
httpd x86_64 2.4.6-88.el7.centos FTP 2.7 M
为依赖而安装:
httpd-tools x86_64 2.4.6-88.el7.centos FTP 90 k
mailcap noarch 2.1.41-2.el7 FTP 31 k
。。。
已安装:
httpd.x86_64 0:2.4.6-88.el7.centos
作为依赖被安装:
httpd-tools.x86_64 0:2.4.6-88.el7.centos mailcap.noarch 0:2.1.41-2.el7
完毕!
[root@localhost data]# cp * /var/ftp/ftp/Packages/ //将rpm包放到软件仓库中
[root@localhost data]# createrepo --update /var/ftp/ftp/Packages/ //手动更新依赖关系
Could not find valid repo at: /var/ftp/ftp/Packages/
Spawning worker 0 with 2015 pkgs
Spawning worker 1 with 2015 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost data]#
客户机软件仓库位置
[root@localhost ~]# vim /etc/yum.repos.d/ftp.repo
[FTP]
name=FTP
baseurl=ftp://192.168.30.4/ftp/Packages //手动更新Packages目录
enable=1
gpgcheck=0
安装nginx
[root@localhost ~]# yum -y install nginx
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
正在解决依赖关系
。。。
====================================================================================================================
Package 架构 版本 源 大小
====================================================================================================================
正在安装:
nginx x86_64 1:1.16.1-3.el7 FTP 563 k
为依赖而安装:
nginx-all-modules noarch 1:1.16.1-3.el7 FTP 20 k
nginx-filesystem noarch 1:1.16.1-3.el7 FTP 21 k
nginx-mod-http-image-filter x86_64 1:1.16.1-3.el7 FTP 30 k
nginx-mod-http-perl x86_64 1:1.16.1-3.el7 FTP 39 k
nginx-mod-http-xslt-filter x86_64 1:1.16.1-3.el7 FTP 29 k
nginx-mod-mail x86_64 1:1.16.1-3.el7 FTP 57 k
nginx-mod-stream x86_64 1:1.16.1-3.el7 FTP 85 k
openssl11-libs x86_64 1:1.1.1g-3.el7 FTP 1.5 M
。。。。
已安装:
nginx.x86_64 1:1.16.1-3.el7
作为依赖被安装:
nginx-all-modules.noarch 1:1.16.1-3.el7 nginx-filesystem.noarch 1:1.16.1-3.el7
nginx-mod-http-image-filter.x86_64 1:1.16.1-3.el7 nginx-mod-http-perl.x86_64 1:1.16.1-3.el7
nginx-mod-http-xslt-filter.x86_64 1:1.16.1-3.el7 nginx-mod-mail.x86_64 1:1.16.1-3.el7
nginx-mod-stream.x86_64 1:1.16.1-3.el7 openssl11-libs.x86_64 1:1.1.1g-3.el7
完毕!