制作本地yum源有两种方式,第一种是使用光盘镜像,然后在本地进行安装。第二种是我们自己创建一个本地yum仓库,然后使用file的形式来向本地提供yum repo(也可以使用http的方式向外部提供,我们这里就自己给自己创建yum仓库)
1、把从网上下载的rpm包放在本地的某个文件夹里面
我们可以这样子下载,使用yum下载rpm包但是并不安装
yum groupinstall "Development tools" --downloadonly --downloaddir=./
[root@chaofeng yum]# pwd/data/yum #我是把RPM包放在了/data/yum目录下[root@chaofeng yum]# lsautoconf-2.69-11.el7.noarch.rpm intltool-0.50.2-7.el7.noarch.rpmautomake-1.13.4-3.el7.noarch.rpm libquadmath-devel-4.8.5-36.el7.x86_64.rpmbison-3.0.4-2.el7.x86_64.rpm libtool-2.4.2-22.el7_3.x86_64.rpmbyacc-1.9.20130304-3.el7.x86_64.rpm patch-2.7.1-10.el7_5.x86_64.rpmcscope-15.8-10.el7.x86_64.rpm patchutils-0.3.3-4.el7.x86_64.rpmctags-5.8-13.el7.x86_64.rpm perl-Git-1.8.3.1-20.el7.noarch.rpmdiffstat-1.57-4.el7.x86_64.rpm rcs-5.9.0-5.el7.x86_64.rpmdoxygen-1.8.5-3.el7.x86_64.rpm redhat-rpm-config-9.1.0-87.el7.centos.noarch.rpmflex-2.5.37-6.el7.x86_64.rpm rpm-build-4.11.3-35.el7.x86_64.rpmgcc-4.8.5-36.el7.x86_64.rpm rpm-sign-4.11.3-35.el7.x86_64.rpmgcc-c++-4.8.5-36.el7.x86_64.rpm subversion-1.7.14-14.el7.x86_64.rpmgcc-gfortran-4.8.5-36.el7.x86_64.rpm swig-2.0.10-5.el7.x86_64.rpmgettext-devel-0.19.8.1-2.el7.x86_64.rpm systemtap-3.3-3.el7.x86_64.rpmgit-1.8.3.1-20.el7.x86_64.rpm systemtap-devel-3.3-3.el7.x86_64.rpmindent-2.2.11-13.el7.x86_64.rpm
2、下载制作本地yum的命令程序包
创建仓库需要特定的程序包来完成。我们下载这个程序包
yum install createrepo
3、确保防火墙关闭状态
4、开始创建yum仓库,在rpm包存放的所在的目录下执行createrepo命令。
[root@chaofeng yum]# createrepo ./Spawning worker 0 with 29 pkgsWorkers FinishedSaving Primary metadataSaving file lists metadataSaving other metadataGenerating sqlite DBsSqlite DBs complete
创建完成后我们会看到这个目录repodata,这个目录很是关键,
5、在/etc/yum.repos.d目录下创建配置文件。(我这里是以本地file的形式给自己的主机提供yum源,如果你要在局域网内的其他主机可以访问到,则使用http或ftp的形式进行,比如:base=http://{当前yum源所在主机的IP}/{RPM软件包目录})
[root@chaofeng yum.repos.d]# cat CentOS-BenDi.repo[Centos-BenDi]name=centos yum repobaseurl=file:///data/yumenabled=1gpgcheck=0priority=1
7、更新本地缓存即可
yum clean allyum makecache
8、尝试安装一个本地存在的软件包gcc
[root@chaofeng yum.repos.d]# yum install gcc已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.163.com * updates: centos.mirrors.estointernet.in正在解决依赖关系--> 正在检查事务---> 软件包 gcc.x86_64.0.4.8.5-36.el7 将被 安装--> 解决依赖关系完成依赖关系解决======================================================================================================== Package 架构 版本 源 大小========================================================================================================正在安装: gcc x86_64 4.8.5-36.el7 Centos-BenDi 16 M事务概要========================================================================================================安装 1 软件包总下载量:16 M安装大小:37 MIs this ok [y/d/N]: y
上面我们可以看到下载gcc包使用的正是我们刚刚我们制作的本地yum源。
9、我们还可以这样子检测是否使用了本地yum源
[root@chaofeng yum]# yum repolist已加载插件:fastestmirror, langpacksLoading mirror speeds from cached hostfile * base: mirrors.zju.edu.cn * epel: mirrors.tuna.tsinghua.edu.cn * extras: mirrors.163.com * updates: centos.mirrors.estointernet.in源标识 源名称 状态Centos-BenDi centos yum repo 29base/7/x86_64 CentOS-7 - Base 10,019epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 12,851extras/7/x86_64 CentOS-7 - Extras 321updates/7/x86_64 CentOS-7 - Updates 625repolist: 23,845
你看第一个就是我们自己制作的本地yum源。