Press "Enter" to skip to content

Red Hat将本地光盘设置为yum更新源

在Red Hat/CentOS系统中,yum是个好东西,可以傻瓜化的快速安装一些软件包和补丁,当要安装的软件包有依赖包时,也可以自动把依赖包也装上(简直是懒人必备神器啊~)。其实很多软件包在Red Hat/CentOS的安装光盘中就已经有了,我们没必要再从远程服务器下载,本文我们教大家如何配置本地的yum源。

1,挂载本地光盘
首先在VMWare中设置好Red Hat的安装镜像,VMWare会自动把此镜像挂载到系统中,我们来看看默认的挂载情况:

[root@localhost ~]# df -l
Filgsystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      19172036   2436096  15746348  14% /
/dev/sda1               101086     12185     83682  13% /boot
tmpfs                   257652         0    257652   0% /dev/shm
/dev/hdc               3038672   3038672         0 100% /media/RHEL_5.5 i386 DVD

VMWare把镜像默认挂在了/media/RHEL_5.5 i386 DVD目录下,但因该目录名中包含了空格,无法使用cd进入该目录,也无法使用ls列出目录内容,所以我们要重新挂载一下。挂载前先记好光盘在系统中的设备名为/dev/hdc。

[root@localhost ~]# umount /dev/hdc               #解除挂载
[root@localhost ~]# mkdir -p /media/cdrom         #创建新的目录用于挂载光盘
[root@localhost ~]# mount /dev/hdc /media/cdrom   #把光盘挂载到新目录
mount: block device /dev/hdc is write-protected, mounting read-only

2,设置本地yum更新源
首先查看一下系统默认的yum更新源设置:

[root@localhost ~]# more /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$base
arch/Debuginfo/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-debuginfo-beta]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/$basearch/D
ebuginfo/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

其中,[rhel-debuginfo]下的内容,便是一个更新源的设置情况,
baseurl 指的是你的YUM源地址
enabled=0 是否启用这个源,1为起用,0为禁用
gpgcheck=1 会让yum检查每个下载的RPM的GnuPG签名。这么做是因为你需要适当的GnuPG key注册到您的RPM数据库。可以防止被欺骗,如:非法入侵发行版网站,木马导入软件包,使不知情用户下载
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release 本机GPGKEY的存放地址

了解完以上内容,我们就可以为本机添加另一个yum更新源。编辑/etc/yum.repos.d/rhel-debuginfo.repo文件,添加另一个[rhel-debuginfo],最终形成如下的格式:

[root@localhost ~]# vi /etc/yum.repos.d/rhel-debuginfo.repo
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-debuginfo-beta]
name=Red Hat Enterprise Linux $releasever Beta - $basearch - Debug
baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/$basearch/Debuginfo/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=file:///media/cdrom/Server
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

然后就可以通过“yum install 软件名”的形式来安装软件或补丁了,前提是本地光盘里得有对应的软件或补丁。

Leave a Reply

Your email address will not be published. Required fields are marked *