文档 · 2018年12月19日 0

redhat配置yum源

看过网上介绍如何配置yum源的,但是很多都解决不了问题,下面我来说一下基本小白都能看懂,欢迎大佬指正或者私聊反馈问题

首先确认你现有的yum这个命令是否是正常得。

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

呐,基本上面那样就说明yum这个命令是可用的。

如过出现其他提示,例如下面这样就是有问题,你可能需要检查python软件包,或者重新安装yum

[root@woniusnail ~]# yum
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
   No module named yum
Please install a package which provides this module, or
verify that the module is installed correctly.
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.12 (default, Feb  5 2018, 03:00:27)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-18)]
If you cannot solve this problem yourself, please go to
the yum faq at:
  http://yum.baseurl.org/wiki/Faq

好了,废话不多说,开始配置源,个人一直使用centos的源,其他的如果你有途径自己找也行。

首先进入/etc/yum.repo.d

新建一个Centos-base.repo的文件并写入以下内容
[root@wserver2 /]# cd /etc/yum.repos.d/
[root@wserver2 yum.repos.d]# vim CentOS-Base.repo
name=CentOS-5 - Base
baseurl=http://vault.centos.org/5.5/os/x86_64/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

保存退出后不要忘了导入秘钥文件
rpm -import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

呐 ,现在我们解释一下这个源文件

CentOS-5 - Base #名字不多说
baseurl=http://vault.centos.org/5.5/os/x86_64/ #软件包的下载仓库地址 如果你有自己仓库比如U盘 你可以挂载上写挂载路径。非常重要 5.5表示系统版本,x86_x64系统64位 如果你系统是32位那就选i386
gpgcheck=1 #是否开gpg启验证,我用的官方源所以开启了,也可以不开启
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5 #这个就是gpg验证要用的到的秘钥,可以在软件包官网获取,用哪个版本的包酒就导入哪个版本的秘钥
enable=0 #表示不开启这个配置,也就是说当你yum安装或者更新的时候不会去加载这个配置下的仓库。设置为1表示开启。或者不设置也为开启仓库

秘钥 及 仓库地址  跳转:点我跳转

上面配置完了 备份一下原有的*.repo文件更新yum缓存

yum clean all

yum makecache

[root@jrfwserver2 yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, rhnplugin, security
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@jrfwserver2 yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
Determining fastest mirrors
addons                                                                                                                                                                                                                                                 | 2.1 kB     00:01     
addons/filelists_db                                                                                                       5% [======                                                                                                        ] 7.7 kB/s | 240 kB     08:20 ETA 
等他加载完就OK

大功告成。

打赏