centos7或centos8配置本地yum源

1.简介

Yum源是一种软件仓库,用于存储和分发Linux操作系统下的软件包。Yum是Yellowdog Updater Modified的缩写,它是Red Hat Linux中用于管理RPM包的软件包管理器。Yum源中包含了众多的软件包,可以方便用户进行系统更新、安装软件等操作。用户可以通过添加和配置不同的Yum源,来获取不同的软件包和更新。常见的Yum源包括CentOS、Red Hat、EPEL等。

(1)常用命令

#一些常用的命令, -y 参数是全部选是
yum check          检查 RPM 数据库问题
yum check-update   检查是否有可用的软件包更新
yum clean          删除缓存数据
yum deplist        列出软件包的依赖关系
yum distribution-synchronization 已同步软件包到最新可用版本
yum downgrade      降级软件包
yum erase          从系统中移除一个或多个软件包
yum fs             Acts on the filesystem data of the host, mainly for removing docs/lanuages for minimal hosts.
yum fssnapshot     Creates filesystem snapshots, or lists/deletes current snapshots.
yum groups         显示或使用、组信息
yum help           显示用法提示
yum history        显示或使用事务历史
yum info           显示关于软件包或组的详细信息
yum install        向系统中安装一个或多个软件包
yum langavailable  Check available languages
yum langinfo       List languages information
yum langinstall    Install appropriate language packs for a language
yum langlist       List installed languages
yum langremove     Remove installed language packs for a language
yum list           列出一个或一组软件包
yum load-transaction 从文件名中加载一个已存事务
yum makecache      创建元数据缓存
yum provides       查找提供指定内容的软件包
yum reinstall      覆盖安装软件包
yum repo-pkgs      将一个源当作一个软件包组,这样我们就可以一次性安装/移除全部软件包。
yum repolist       显示已配置的源
yum search         在软件包详细信息中搜索指定字符串
yum shell          运行交互式的 yum shell
yum swap           Simple way to swap packages, instead of using shell
yum update         更新系统中的一个或多个软件包
yum update-minimal Works like upgrade, but goes to the 'newest' package match which fixes a problem that affects your system
yum updateinfo     Acts on repository update information
yum upgrade        更新软件包同时考虑软件包取代关系
yum version        显示机器和/或可用的源版本。

(2)常用参数选项

  -h, --help            显示此帮助消息并退出
  -t, --tolerant        忽略错误
  -C, --cacheonly       完全从系统缓存运行,不升级缓存
  -c [config file], --config=[config file]
                        配置文件路径
  -R [minutes], --randomwait=[minutes]
                        命令最长等待时间
  -d [debug level], --debuglevel=[debug level]
                        调试输出级别
  --showduplicates      在 list/search 命令下,显示源里重复的条目
  -e [error level], --errorlevel=[error level]
                        错误输出级别
  --rpmverbosity=[debug level name]
                        RPM 调试输出级别
  -q, --quiet           静默执行
  -v, --verbose         详尽的操作过程
  -y, --assumeyes       回答全部问题为是
  --assumeno            回答全部问题为否
  --version             显示 Yum 版本然后退出
  --installroot=[path]  设置安装根目录
  --enablerepo=[repo]   启用一个或多个软件源(支持通配符)
  --disablerepo=[repo]  禁用一个或多个软件源(支持通配符)
  -x [package], --exclude=[package]
                        采用全名或通配符排除软件包
  --disableexcludes=[repo]
                        禁止从主配置,从源或者从任何位置排除
  --disableincludes=[repo]
                        disable includepkgs for a repo or for everything
  --obsoletes           更新时处理软件包取代关系
  --noplugins           禁用 Yum 插件
  --nogpgcheck          禁用 GPG 签名检查
  --disableplugin=[plugin]
                        禁用指定名称的插件
  --enableplugin=[plugin]
                        启用指定名称的插件
  --skip-broken         忽略存在依赖关系问题的软件包
  --color=COLOR         配置是否使用颜色
  --releasever=RELEASEVER
                        在 yum 配置和 repo 文件里设置 $releasever 的值
  --downloadonly        仅下载而不更新
  --downloaddir=DLDIR   指定一个其他文件夹用于保存软件包
  --setopt=SETOPTS      设置任意配置和源选项
  --bugfix              Include bugfix relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory=ADVS, --advisories=ADVS
                        Include packages needed to fix the given advisory, in
                        updates
  --bzs=BZS             Include packages needed to fix the given BZ, in
                        updates
  --cves=CVES           Include packages needed to fix the given CVE, in
                        updates
  --sec-severity=SEVS, --secseverity=SEVS
                        Include security relevant packages matching the
                        severity, in updates

 

2.在线环境更新源 

这里就不多说,联网的环境可以将源替换成阿里或者清华源,下载速度也许会快点。略过

以centos7举一个例子,本文主要描述离线配置

#备份
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
#联网获取配置文件
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
或者
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
#生成缓存
yum makecache

3.离线环境配置本地yum源

(1)centos7

        ①离线环境,当你使用yum命令时发现报错

        先mount /dev/cdrom  /mnt  挂载后,再使用yum命令查找会报错,这里就是本地源没有配置的问题

        ②配置7的本地repo

#备份所有的repo文件,并重新编辑一个,重新挂载光驱
mkdir /etc/yum.repos.d/bak
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak
cat > /etc/yum.repos.d/base.repo <<eof
[base]
name=base
baseurl=file:///mnt
enabled=1
gpgcheck=1
eof
mount /dev/cdrom /mnt

这里是最简单的配置,文件名可以随便改,但是注意一定是以.repo 结尾的文件

这里是挂载到mnt本地目录上,enabled=1就是源名允许使用,gpgcheck就是检验,这里写成0或者1都行,里面配置的name或者[base]名称可以自己配置

查看源,发现就有一个基本的源base就是我们配置的name

这就配置完成了,以后使用就是挂载一下光驱就行

(2)centos8

        ①对比区别

centos7,

centos8 

对比2个版本光驱的挂载情况,centos8软件包拆成了2部分,所以这里配置本地的repo文件的时候也需要配置2个源,才能使用centos8的本地yum

         ②配置8的本地repo

#我这里光驱换成centos8,但是还是用的centos7的源,所以先执行清楚
yum clean all
#创建目录
mkdir /mnt/BaseOS
mkdir /mnt/AppStream

#备分/etc/yum.repos.d下的repo文件,略

cat > /etc/yum.repos.d/centos8.repo <<eof
[base]
name=centos 8 base
baseurl=file:///mnt/BaseOS
enabled=1
gpgcheck=0

[app]
name=centos 8 app
baseurl=file:///mnt/AppStream
enabled=1
gpgcheck=0
eof

#重新挂载
mount /dev/cdrom /mnt
yum repolist

 这里一般挂载就选则mnt目录挂载光驱,完成后可以使用yum list 会刷出软件列表,配到这一步就成功了

 后续使用直击挂载光驱就可以了

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值