在使用yum安装之前是必须配置yum源的, 在不能联网的情况下, 可使用DVD光盘或ISO文件做本地yum源。下面以RHEL6.0为例,其它版本类似。
1. 建立ISO文件存放目录(/repo/iso)和ISO文件的挂载目录(/repo/rhel6)
# mkdir -p /repo/iso
# mkdir -p /repo/rhel6
2.如果有现成的ISO文件可以直接上传至/repo/iso目录下.
[root@node1 ~]# ll /repo/iso/CentOS-6.7-x86_64-bin-DVD1.iso
-rw-r–r–. 1 root root 3895459840 Feb 23 20:15 /repo/iso/CentOS-6.7-x86_64-bin-DVD1.iso
3. 挂载ISO文件
# mount -o loop /repo/iso/CentOS-6.7-x86_64-bin-DVD1.iso /repo/rhel6
[root@node1 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda5 44G 12G 31G 27% /
tmpfs 1.2G 72K 1.2G 1% /dev/shm
/dev/sda1 113M 41M 67M 38% /boot
/dev/sda3 3.8G 10M 3.6G 1% /tmp
/repo/iso/CentOS-6.7-x86_64-bin-DVD1.iso
3.7G 3.7G 0 100% /repo/rhel6
4. 确保系统中已经安装了yum相关软件包
[root@node1 ~]# rpm -qa |grep yum
yum-3.2.29-69.el6.centos.noarch
yum-plugin-security-1.1.30-30.el6.noarch
PackageKit-yum-0.5.8-25.el6.x86_64
yum-utils-1.1.30-30.el6.noarch
yum-metadata-parser-1.1.2-16.el6.x86_64
PackageKit-yum-plugin-0.5.8-25.el6.x86_64
yum-plugin-fastestmirror-1.1.30-30.el6.noarch
版本号可能有所不同, 如果缺少, 请自行安装(这些包基本都默认安装了).
5. 编辑repo文件
[root@MySQL ~]# cd /etc/yum.repos.d/
[root@mysql yum.repos.d]# ll
total 24
-rw-r–r–. 1 root root 1991 Aug 4 2015 CentOS-Base.repo
-rw-r–r–. 1 root root 647 Aug 4 2015 CentOS-Debuginfo.repo
-rw-r–r–. 1 root root 289 Aug 4 2015 CentOS-fasttrack.repo
-rw-r–r–. 1 root root 630 Aug 4 2015 CentOS-Media.repo
-rw-r–r–. 1 root root 6259 Aug 4 2015 CentOS-Vault.repo
[root@mysql yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@mysql yum.repos.d]# mv CentOS-Debuginfo.repo CentOS-Debuginfo.repo.bak
[root@mysql yum.repos.d]# mv CentOS-fasttrack.repo CentOS-fasttrack.repo.bak
[root@mysql yum.repos.d]# mv CentOS-Vault.repo CentOS-Vault.repo.bak
[root@mysql yum.repos.d]# ll
total 28
-rw-r–r–. 1 root root 1991 Aug 4 2015 CentOS-Base.repo.bak
-rw-r–r–. 1 root root 647 Jun 1 22:48 CentOS-Debuginfo.repo.bak
-rw-r–r–. 1 root root 289 Aug 4 2015 CentOS-fasttrack.repo.bak
-rw-r–r–. 1 root root 630 Aug 4 2015 CentOS-Media.repo
-rw-r–r–. 1 root root 6259 Aug 4 2015 CentOS-Vault.repo.bak
说明:/etc/yum.repos.d/ 下的文件都是有用的,防止以后有用,这里我们mv改名做备份。
CentOS-Media 这个是使用光盘挂载后调用的文件
CentOS-Base 这个是联网后基础的源
CentOS-Vault 这个是最近新版本的加入的老版本的yum源配置
CentOS-Debuginfo debug包尤其和内核相关的更新和软件安装
— 只剩下 CentOS-Media.repo ,我们用它来做光盘挂载后调用的文件
[root@mysql yum.repos.d]# cat CentOS-Media.repo
[c6-media]
name=CentOS-$releasever – Media
baseurl=file:///repo/rhel6/
# file:///media/cdrom/
# file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
解析:
6.清空yum缓存
[root@mysql yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, refresh-packagekit, security
Cleaning repos: c6-media
Cleaning up Everything
[root@mysql yum.repos.d]# yum makecache
Metadata Cache Created
7.生成列表
[root@mysql yum.repos.d]# yum list
8. 测试
[root@mysql yum.repos.d]# yum -y install glibc*
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Package glibc-devel-2.12-1.166.el6.x86_64 already installed and latest version
Package glibc-2.12-1.166.el6.x86_64 already installed and latest version
Package glibc-headers-2.12-1.166.el6.x86_64 already installed and latest version
Package glibc-common-2.12-1.166.el6.x86_64 already installed and latest version
。。。省略输出
9.将mount命令写入fstab ## 说明,这步没有测试。
为方便,把这些mount写进/etc/fstab,以便开机就挂载:
/repo/iso/rhel-server-6.0-x86_64-dvd.iso /repo/rhel6 iso9660 loop 0 0
更多YUM相关教程见以下内容:
RHEL7 本地yum源配置 http://www.linuxidc.com/Linux/2017-01/139140.htm
CentOS 6.5 配置本地Yum源 http://www.linuxidc.com/Linux/2017-04/143127.htm
CentOS 7 使用阿里云的yum源、PIP源 http://www.linuxidc.com/Linux/2017-01/13966.htm
CentOS及Red Hat Linux安装yum源 http://www.linuxidc.com/Linux/2017-02/140205.htm
CentOS 7更改yum源与更新系统 http://www.linuxidc.com/Linux/2017-01/140067.htm
RedHat7.0配置本地yum源 http://www.linuxidc.com/Linux/2017-01/139148.htm
RedHat Linux 7安装CentOS 7 yum源 http://www.linuxidc.com/Linux/2017-04/142444.htm
软件包管理之前端管理工具yum http://www.linuxidc.com/Linux/2017-02/140270.htm
CentOS 7 使用阿里云的yum源、PIP源 http://www.linuxidc.com/Linux/2017-01/13966.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2017-06/144821.htm