yum源一般分为两种,本地yum源和本地网络yum源,前者是通过文件提供安装包,后者是通过网络下载安装包;
由于Redhat7.3的yum源需要注册付费,所以往往会出现下载yum源安装包失败,如下图:
(1)上传安装包
把Redhat的安装包传到root下某个路径;
(2)挂载镜像文件
进入到安装包的目录,执行:
mount -o loop rhel-server-7.3-x86_64-dvd.iso /cdrom
(3)复制镜像文件
#最好选择空间较大的路径
执行:
cp -r /cdrom /* /opt/yum/rhel-server-7.3-x86_64-dvd
(4)生成repodata
cd /opt/yum/rhel-server-7.3-x86_64-dvd
createrepo .
会在/opt/yum/rhel-server-7.3-x86_64-dvd下生成repodata文件夹,下面有filelists.xml.gz other.xml.gz primary.xml.gz repomd.xml这些文件
(5)配置客户端/etc/yum.repos.d/源配置文件, 创建rhel-source.repo
[root@redhat73 selinux]# cd /etc/yum.repos.d/
[root@redhat73 yum.repos.d]# ls
dave.repo.bak epel.repo.bak epel-testing.repo.bak redhat.repo redhat.repo.bak rhel-source.repo
[root@redhat73 yum.repos.d]# more rhel-source.repo
[rhel-source]
baseurl=file:///opt/yum/rhel-server-7.3-x86_64-dvd
enabled=1
gpgcheck=0
gpgkey=file:///opt/yum/rhel-server-7.3-x86_64-dvd/RPM-GPG-KEY-redhat-release
(6)搭建的过程中出现的问题
运行createrepo .出错,下面是出错的信息
[root@localhost rhel-server-7.3-x86_64-dvd]# createrepo .
Traceback (most recent call last):
File "/usr/share/createrepo/genpkgmetadata.py", line 28, in <module>
import createrepo
File "/usr/lib/python2.7/site-packages/createrepo/__init__.py", line 21, in <module>
import yumbased
File "/usr/lib/python2.7/site-packages/createrepo/yumbased.py", line 27, in <module>
from yum.packages import YumLocalPackage
ImportError: No module named yum.packages
解决方法:
执行了以下三条命令安装createrepo:
[root@localhost Packages]# rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost Packages]# rpm -ivh yum-3.4.3-150.el7.noarch.rpm
[root@localhost Packages]# rpm -ivh createrepo-0.9.9-26.el7.noarch.rpm
最后执行createrepo .命令