yum基本配置

了解常见的yum源

掌握本地和网络yum源配置

能够使用yum工具安装软件包

rpm -ivh xxx

手动安装

网络yum源

aliyun

163源

sohu源

清华源

centos源

redhat源

epel‘源

特定软件

nginx   mysql  zabbix  

    [root@nova ~]# ls -l /etc/yum.repos.d/    #查看现有的yum仓库镜像yum repolist all
ls -1 /etc/yum.repos.d/
tar -zcvf /etc/yum.repos.d/bak.tar.gz /etc/yum.repos.d/*
1s -1 /etc/yum.repos.d/
rm -rf /etc/yum.repos.d/ *. repo
ls -1 /etc/yum.repos.d/

yum clean
yum makecache
yum repolist all 

ro = read only

lsblk 

回顾

安装本地yum源

挂载光盘,虚拟光盘

1.在虚拟机添加光盘

2.在linux清空/mnt目录中的所有的文件

3.lsbak 查看挂载情况sr0的块没有刮在/mnt

4.mount -o ro /dev/sr0 /mnt

5.Isblk

6.配置repo文件

sr0挂载到/mnt上

[仓库名称]

name=名称

baseurl=源文件的位置  file://mnt ftp://  http:// https://

gpgcheck=0 1 本地仓库,不需要检测

本地yum源备份
1.找到源⽂件
# 当前在etc⽬录,跳转到yum.repos.d⽬录
[root@localhost etc]# cd yum.repos.d/
#查看默认的源⽂件
[root@localhost yum.repos.d]# ls
CentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
mysql-community.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community
debuginfo.repo
[root@localhost yum.repos.d]# pwd
/etc/yum.repos.d
2.将所有的repo⽂件做成压缩包,命名为repo.tar.gz
[root@localhost yum.repos.d]# tar -zcvf repo.tar.gz ./*.repo
./CentOS-Base.repo
./CentOS-CR.repo
./CentOS-Debuginfo.repo
./CentOS-fasttrack.repo
./CentOS-Media.repo
./CentOS-Sources.repo
./CentOS-Vault.repo
./CentOS-x86_64-kernel.repo
./mysql-community-debuginfo.repo
./mysql-community.repo
./mysql-community-source.repo
您在 /var/spool/mail/root 中有新邮件
# 查看⽂件信息
[root@localhost yum.repos.d]# lsCentOS-Base.repo CentOS-fasttrack.repo CentOS-Vault.repo
mysql-community.repo
CentOS-CR.repo CentOS-Media.repo CentOS-x86_64-kernel.repo
mysql-community-source.repo
CentOS-Debuginfo.repo CentOS-Sources.repo mysql-community
debuginfo.repo repo.tar.gz
3.删除所有的repo⽂件
[root@localhost yum.repos.d]# rm -rf ./*.repo
您在 /var/spool/mail/root 中有新邮件
[root@localhost yum.repos.d]# ls
repo.tar.gz
本地yum源光盘配置
1. 查看本地源
1. 使⽤光盘作为 yum 源仓库
1. 在 vmware 中装载 centos7.6 光盘镜像
Loading mirror speeds from cached hostfile
repolist: 0
# 所有的 yum 都已经被删除了 2. 把光盘挂载到指定⽬录下
1. 删除 /mnt ⽬录下所有的⽂件
2.lsblk
3.mount -o ro /dev/sr0 /mnt
选项 -o 表示挂载⽅式
ro=readonly
rw=read and write
[root@localhost ~] # mount /dev/sr0 /mnt/ -o ro
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~] # ls /mnt/
CentOS_BuildTag EULA images LiveOS repodata RPM
GPG-KEY-CentOS-Testing-7
EFI GPL isolinux Packages RPM-GPG-KEY-CentOS-7
TRANS.TBL 4. 解除挂载
4. 将挂载添加到开机启动⽂件中
chmod +x /etc/rc.local
添加权限
echo 'mount -o ro /dev/sr0 /mnt' >> /etc/rc.local
向⽂件中添加⼀⾏
# 查看磁盘挂载情况
[root@localhost ~] # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8 :0 0 20G 0 disk
"#sda1 8 :1 0 1G 0 part /boot
$#sda2 8 :2 0 19G 0 part
"#centos-root 253 :0 0 17G 0 lvm /
$#centos-swap 253 :1 0 2G 0 lvm [SWAP]
sr0 11 :0 1 8 .8G 0 rom /mnt
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~] # umount /mnt
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~] # ls /mnt/
[root@localhost ~] # lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8 :0 0 20G 0 disk
"#sda1 8 :1 0 1G 0 part /boot
$#sda2 8 :2 0 19G 0 part
"#centos-root 253 :0 0 17G 0 lvm /
$#centos-swap 253 :1 0 2G 0 lvm [SWAP]
sr0 11 :0 1 8 .8G 0 rom 5. 编写本地 repo ⽂件
1. 创建⼀个 repo ⽂件
2. 编辑内容
yum 仓库的格式
[root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# echo 'mount -o or /dev/sr0 /mnt' >> /etc/rc.local
[root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# vim /etc/rc.local
[root@localhost ~]# ls -l /etc/rc.local
lrwxrwxrwx. 1 root root 13 6 ⽉ 16 20:18 /etc/rc.local -> rc.d/rc.local 编号
属性
1
[ 仓库名称 ] 可以有多个仓库
2
name= 仓库名称
3
baseurl= 仓库的路径,⽀持多种格式 file:// ftp:// http/s://
4
gpgcheck= gpg 秘钥检测 0 不检测, 1 检测,如果需要配置秘钥链接
5
enable= 0|1 是否启⽤当前仓库
6, 清理缓存,查看源列表
[root@localhost ~] # ls /etc/yum.repos.d/
repo.tar.gz
[root@localhost ~] # vim /etc/yum.repos.d/20240714001.repo
[local]
[local]
name = local0
baseurl = file : ///mnt
gpgcheck = 0
enable = 1
# 清理缓存
[root@localhost ~] # yum clear all
已加载插件: fastestmirror
没有该命令: clear 。请使⽤ /usr/bin/yum --help
# 创建缓存
[root@localhost ~] # yum makecache
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
local
| 3 .6 kB 00 :00:00
(1/2): local/other_db
| 2 .5 MB 00 :00:00 7. 测试 yum
(2/2): local/filelists_db
| 6 .9 MB 00 :00:00
元数据缓存已建⽴
您在 /var/spool/mail/root 中有新邮件
# 查看源仓库列表
[root@localhost ~] # yum repolist
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称
状态
local local0
9 ,911
repolist: 9 ,911
[root@localhost ~] # yum repolist all
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
源标识 源名称
状态
local local0
启⽤ : 9 ,911 # 软件数量
repolist: 9 ,911
# 查看是否安装 httpd
[root@localhost ~] # rpm -q httpd
httpd-2.4.6-99.el7.centos.1.x86_64 # 卸载 httpd
[root@localhost ~] # yum remove httpd
已加载插件: fastestmirror
正在解决依赖关系
-- > 正在检查事务
--- > 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 删除
-- > 解决依赖关系完成
依赖关系解决
=======================================================================
=========================================
Package 架构 版本
源 ⼤⼩
=======================================================================
=========================================
正在删除 :
httpd x86_64 2 .4.6-99.el7.centos.1
@updates 9 .4 M
事务概要
=======================================================================
=========================================
移除 1 软件包
安装⼤⼩: 9.4 M
是否继续? [y/N] : y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在删除 : httpd-2.4.6-99.el7.centos.1.x86_64
1 /1
验证中 : httpd-2.4.6-99.el7.centos.1.x86_64
1 /1 删除 :
httpd.x86_64 0 :2.4.6-99.el7.centos.1
完毕!
# 再次查看是否安装 httpd
[root@localhost ~] # rpm -q httpd
未安装软件包 httpd
[root@localhost ~] # yum -y install httpd
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
正在解决依赖关系
-- > 正在检查事务
--- > 软件包 httpd.x86_64.0.2.4.6-80.el7.centos 将被 安装
-- > 正在处理依赖关系 httpd-tools = 2 .4.6-80.el7.centos ,它被软件包 httpd-
2.4.6-80.el7.centos.x86_64 需要
-- > 解决依赖关系完成
错误:软件包: httpd-2.4.6-80.el7.centos.x86_64 (local)
需要: httpd-tools = 2 .4.6-80.el7.centos
已安装 : httpd-tools-2.4.6-99.el7.centos.1.x86_64 (@updates)
httpd-tools = 2 .4.6-99.el7.centos.1
可⽤ : httpd-tools-2.4.6-80.el7.centos.x86_64 (local)
httpd-tools = 2 .4.6-80.el7.centos
您可以尝试添加 --skip-broken 选项来解决该问题
您可以尝试执⾏: rpm -Va --nofiles --nodigest
您在 /var/spool/mail/root 中有新邮件
[root@localhost ~] # rpm -q httpd
未安装软件包 httpd
# 缺少依赖,安装失败 2. 下载软件,使⽤软件包,作为 yum 源仓库
⽹络yum源的分离
1. 知名站点
1. 搜索阿⾥镜像源
2. 根据官⽅提示配置 yum 源
https://developer.aliyun.com/mirror/centos # 复制阿⾥云提供的 url ,下载⽂件
[root@localhost yum.repos.d] # wget -O /etc/yum.repos.d/CentOS-Base.repo
https://mirrors.aliyun.com/repo/Centos-7.repo
--2024-07-14 20 :00:04-- https://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 117 .23.49.221,
117 .23.49.224, 58 .222.47.210, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|117.23.49.221|:443... 已
连接。
已发出 HTTP 请求,正在等待回应 ... 200 OK
⻓度: 2523 (2.5K) [application/octet-stream]
正在保存⾄ : “/etc/yum.repos.d/CentOS-Base.repo” 100 %
[======================================================================
>] 2 ,523 -- .-K/s ⽤时 0s
2024 -07-14 20 :00:04 (469 MB/s) - 已保存 “/etc/yum.repos.d/CentOS
Base.repo” [2523/2523])
# 查看下载的⽂件
[root@localhost yum.repos.d] # ls
20240714001 .repo CentOS-Base.repo repo.tar.gz
[root@localhost yum.repos.d] #
3. 运⾏ yum makecache ⽣成缓存 yum clear
4. 查看源
[root@localhost yum.repos.d] # yum repolist all
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称
状态
base/7/x86_64 CentOS-7 - Base -
mirrors.aliyun.com 启⽤ : 10 ,072 centosplus/7/x86_64 CentOS-7 - Plus -
mirrors.aliyun.com 禁⽤
contrib/7/x86_64 CentOS-7 - Contrib -
mirrors.aliyun.com 禁⽤
extras/7/x86_64 CentOS-7 - Extras -
mirrors.aliyun.com 启⽤ : 526
local local0
启⽤ : 9 ,911
updates/7/x86_64 CentOS-7 - Updates -
mirrors.aliyun.com 启⽤ : 6 ,173
repolist: 26 ,682
5. 再次安装 httpd
[root@localhost yum.repos.d]# yum -y install httpd
已加载插件: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 安装
--> 解决依赖关系完成
依赖关系解决
=======================================================================
=========================================
Package 架构 版本
源 ⼤⼩
=======================================================================
=========================================
正在安装 : httpd x86_64 2.4.6-99.el7.centos.1
updates 2.7 M
事务概要
=======================================================================
=========================================
安装 1 软件包
总下载量: 2.7 M
安装⼤⼩: 9.4 M
Downloading packages:
httpd-2.4.6-99.el7.centos.1.x86_64.rpm
| 2.7 MB 00:00:02
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
正在安装 : httpd-2.4.6-99.el7.centos.1.x86_64
1/1
验证中 : httpd-2.4.6-99.el7.centos.1.x86_64
1/1
已安装 :
httpd.x86_64 0:2.4.6-99.el7.centos.1
完毕!
[root@localhost yum.repos.d]

  • 3
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值