若在内网中,无法连接互联网,需要使用 yum,可参考博文 “使用DVD光盘或者ISO作为本地YUM源”。
执行命令 “rpm -qa | grep yum” 没有返回值,或者 执行命令 “yum” 提示:没有那个文件或目录。均为没有安装 yum 服务,如何安装也参考博文 “使用DVD光盘或者ISO作为本地YUM源”。
步入正文,以 Red Hat Enterprese Linux 6.8 环境为例(安装好 redhat 后,不能注册的话,不能使用系统自带的 yum 源)。
只需把如下内容保存到文本中,另存为 “rhel-source.repo” 文件,复制到 Linux 系统 “/etc/yum.repos.d” 目录下即可。
#rhel-source.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-6 - Base - 163.com
baseurl=http://mirrors.163.com/centos/6/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-6 - Updates - 163.com
baseurl=http://mirrors.163.com/centos/6/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-6 - Extras - 163.com
baseurl=http://mirrors.163.com/centos/6/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
参数说明:
1) [repoid] :仓库的名称,不能重复,独一无二。通常 使用 [base](基础包源)、[updates](更新/升级包源)、[extras](扩展包源)三个就够了。
2)name:仓库的描述,若不写将会用repoid当作name。
3)baseurl:必须是有效的路径,务必亲测有效(国内很多 yum 的在线源可能已经失效,也存在镜像的目录已更新,如 系统发行版本的目录名称由 “6.0” 更新为 “6”)。url支持的协议有 http:// ftp:// file:// 三种,baseurl 后可以跟多个 url,但 baseurl 只能有一个。
4)enabled=1|0 激活或禁用仓库,若不写默认启用。
5)gpgcheck=1|0 是否在安装包是检测 gpg 签名,默认检测,即为1。
6)gpgkey:指定 reposity 的 gpg key 路径。通常在各个 repository 站点首页的醒目位置(如 163 源的 CentOS 地址为 http://mirrors.163.com/centos/)。
7)参数中的变量(如果系统获取不到变量或获取不正确,可将变量替换为对应的版本和架构)
- $releasever:发行版的版本。
- $arch:cpu 体系。
- $basearch:cpu 的基本体系组。
另,
安装 EPEL(Extra Packages for Enterprise Linux )源。
yum list | grep epel-release
yum install -y epel-release
yum clean all
yum makecache
yum repolist