Yum简单配置
Yum 简介
Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。
yum命令参数
-e [error level], --errorlevel=[error level] 错误输出级别
-q, --quiet 安静的操作
-t 忽略错误
-R[分钟] 设置等待时间
-y 自动应答yes
--skip-broken 忽略依赖问题
--nogpgcheck 忽略GPG验证
check-update 检查可更新的包
clean all 清除全部
clean packages 清除临时包文件(/var/cache/yum 下文件)
clean headers 清除rpm头文件
clean oldheaders 清除旧的rpm头文件
deplist 列出包的依赖
list 可安装和可更新的RPM包
list installed 已安装的包
list extras 已安装且不在资源库的包
info 可安装和可更新的RPM包 信息
info installed 已安装包的信息(-qa 参数相似)
install[RPM包] 安装包
localinstall 安装本地的 RPM包
update[RPM包] 更新包
upgrade 升级系统
search[关键词] 搜索包
provides[关键词] 搜索特定包文件名
reinstall[RPM包] 重新安装包
repolist 显示资源库的配置
resolvedep 指定依赖
remove[RPM包] 卸载包
例子
安装:
[root@localhost ~]# yum install php53 #安装php5.3及其相关依赖包
[root@localhost ~]# yum groupinstall "MySQL Server" #安装mysql数据库组
查找和显示:
[root@localhost ~]# yum info php53 #查看php53的安装信息
[root@localhost ~]# yum list #列出所有可安装的程序包
[root@localhost ~]# yum list php53 #列出所有php53的程序包
[root@localhost ~]# yum groupinfo "MySQL Server" #查看mysql服务组的,相关安装包
[root@localhost ~]# yum deplist php53 #查看php53依赖情况
卸载:
[root@localhost ~]# yum remove php53 #删除php53
[root@localhost ~]# yum groupremove "MySQL Server" #删除mysql服务组
清除缓存:
[root@localhost ~]# yum clean packages #清除缓存目录下的软件包
[root@localhost ~]# yum clean headers #清除缓存目录下的 headers
[root@localhost ~]# yum clean oldheaders #清除缓存目录下旧的 headers
[root@localhost ~]# yum clean, yum clean all #清除所有
等待补充:
配置yum源
配置本地yum源
将系统镜像挂载
[root@node1 ~]# mount /dev/sr0 /media/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@node1 ~]# ll /media/
总用量 694
-rw-rw-r--. 1 root root 14 9月 10 2019 CentOS_BuildTag
drwxr-xr-x. 3 root root 2048 9月 6 2019 EFI
-rw-rw-r--. 1 root root 227 8月 30 2017 EULA
-rw-rw-r--. 1 root root 18009 12月 10 2015 GPL
drwxr-xr-x. 3 root root 2048 9月 10 2019 images
drwxr-xr-x. 2 root root 2048 9月 10 2019 isolinux
drwxr-xr-x. 2 root root 2048 9月 6 2019 LiveOS
drwxrwxr-x. 2 root root 671744 9月 12 2019 Packages
drwxrwxr-x. 2 root root 4096 9月 12 2019 repodata
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-7
-rw-rw-r--. 1 root root 1690 12月 10 2015 RPM-GPG-KEY-CentOS-Testing-7
-r--r--r--. 1 root root 2883 9月 12 2019 TRANS.TBL
配置yum源文件
cd /etc/yum.repos.d/
vi base.repo
[base]#仓库的名字
name=base#描述
baseurl=file:///media#服务器软件包所在的绝对路径 (ftp:// or http:// or file:// )
gpgcheck=0#对包是否进行检测(1检测,0不检测)
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release #gpgkey的绝对路径
enable=1#是否启用(1启用,0关闭)
[root@node1 ~]# yum repolist
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称 状态
base base 4,067
repolist: 4,067
显示有源及源的包的数量即可安装,不同的软件包需要配置不同的源,一般配置网络源
[root@localhost ~]# yum -y install ntpdate
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
--> 正在检查事务
---> 软件包 ntpdate.x86_64.0.4.2.6p5-29.el7.centos 将被 安装
--> 解决依赖关系完成
依赖关系解决
===================================================================================================================
Package 架构 版本 源 大小
===================================================================================================================
正在安装:
ntpdate x86_64 4.2.6p5-29.el7.centos base 86 k
事务概要
===================================================================================================================
安装 1 软件包
总下载量:86 k
安装大小:121 k
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : ntpdate-4.2.6p5-29.el7.centos.x86_64 1/1
验证中 : ntpdate-4.2.6p5-29.el7.centos.x86_64 1/1
已安装:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos
完毕!
配置网络yum源
大致同上,至修改其中的配置文件即可
配置yum源文件
wget获取阿里源
[root@master ~]# wget -O /etc/yum.repos.d/Centos-8.repo http://mirrors.aliyun.com/repo/Centos-8.repo
--2024-12-19 17:27:24-- http://mirrors.aliyun.com/repo/Centos-8.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 175.12.102.187, 113.219.178.241, 219.153.157.235, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|175.12.102.187|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2590 (2.5K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/Centos-8.repo’
/etc/yum.repos.d/Centos-8.repo 100%[=======================================================================================>] 2.53K --.-KB/s in 0.001s
2024-12-19 17:27:24 (3.08 MB/s) - ‘/etc/yum.repos.d/Centos-8.repo’ saved [2590/2590]
[root@master yum.repos.d]# ll
total 8
drwxr-xr-x. 2 root root 4096 Dec 19 17:24 bak
-rw-r--r--. 1 root root 2590 Aug 4 2022 Centos-8.repo
手动写入
[root@master ~]# cd /etc/yum.repos.d/
[root@master yum.repos.d]# vi Centos-8.repo
# 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 - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
#failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)