美文网首页centos应用服务配置
[Centos7] 怎么建立本地yum源?

[Centos7] 怎么建立本地yum源?

作者: Hellooooooworld | 来源:发表于2017-09-06 17:29 被阅读51次

站在巨人的肩膀上

有的时候,我们在yum 安装软件的时候,会发现下载速度极慢。
那么这时候该怎么办呢?这时候我们就需要建立一个本地的yum源,然后使用http使得这些yum可以让统一网段下的用户,能够方便使用。

part 1 获取yum源的工具

首先我们需要把所有的yum包都下载下来并制作成yum源,这里我们需要使用reposync和createrepo。

[root@localhost ~]# yum install -y yum-utils createrepo

part 2 下载yum源

先创建一个文件夹来放置我们下载的rpm包

[root@localhost ~]# mkdir /repo
[root@localhost ~]# cd /repo

然后进入新建的repo文件夹,然后键入reposync命令

[root@localhost repo]# reposync 

然后就会开始下载rpm包,那么为什么会开始下载呢。
我们可以去/etc/yum.repos.d查看,我们会发现7个repo文件。
并查看CentOS-Base.repo文件。

[root@localhost ~]# cd /etc/yum.repos.d
[root@localhost ~]# vim CentOS-Base.repo

文件内容如下,当我们输入reposync的时候,开始下载的就是下面的这些镜像。

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

part 3 createrepo

下载的时间会比较场,当我们下载好之后,我们会发现repo文件夹下有三个文件夹,分别是 base updates 和extras,然后我们依次对三个文件夹进行createrepo。

[root@localhost ~]# cd /repo
[root@localhost repo]# createrepo base 
[root@localhost repo]# createrepo updates
[root@localhost repo]# createrepo extras

然后在每个文件内都会多出一个repodata/文件夹。

part 4 安装httpd 并进行软连接

这个部分,我在此前的文章内有讲过。附上链接。
centos,安装apache文件下载服务器

part 5 制作自己的repo文件

我们再次进入/etc/yum.repos.d文件夹,创建一个备份文件夹repobck,并把原来的7个repo文件放入备份文件内,创建一个新的repo文件。内容如下

[base]
name=Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://[IP]/base/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


[updates]
name=Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
baseurl=http://[IP]/updates/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
baseurl=http://[IP]/extras/
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

part 6 测试

先删除原来的缓存信息,并列出repo信息

[root@localhost ~]#yum clean all
[root@localhost ~]#yum repolist

若出现一下信息即可

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                                                                    repo name                                                                  status
base                                                                       Base                                                                       9,363
extras                                                                     extras                                                                       579
updates                                                                    Updates                                                                    2,146
repolist: 12,088

这样在局域网下进行yum安装就比以前快很多了。

相关文章

  • 常用yum源介绍及配置

    参考: CentOS 7下配置本地yum源及yum客户端 Centos7 配置本地源+阿里yum源/epel-yu...

  • centos7修改为阿里的yum源

    以centos7为例 ,以 修改为阿里的yum源 1. 备份本地yum源 mv /etc/yum.repos.d/...

  • [Centos7] 怎么建立本地yum源?

    站在巨人的肩膀上 有的时候,我们在yum 安装软件的时候,会发现下载速度极慢。那么这时候该怎么办呢?这时候我们就需...

  • CentOS7建立yum本地源

    建立本地源1、建立yum仓库 建立一个目录将光盘的安装包复制到文件夹/local上 2、建立repo文件 name...

  • 第四周作业

    1、自建yum仓库,分别为网络源和本地源网络源repo配置(centos7): 本地源repo配置(centos7...

  • CentOS UBuntu 软件源

    本地源(把本地安装的软件包制成源) Centos6.4建立本地yum源 Ubuntu创建本地apt源 Ubuntu...

  • centos7下安装mysql

    mysql安装 centos7下使用yum源安装mysql 因为centos7下默认没有mysql的yum源,所以...

  • Centos Issue

    CentOS配置本地Yum源、阿里云Yum源、163Yum源、并配置Yum源的优先级

  • 虚谷数据库集群搭建手册

    搭建yum源 分为两步,先搭建本地yum源,再搭建ftpyum源。 1.本地yum源 内容如下: 然后执行命令,刷...

  • yum源的挂载

    下面是关于本地yum源,联网的yum源,添加其他yum源,三部分 制作本地YUM源 1.准备一台Linux服务器,...

网友评论

    本文标题:[Centos7] 怎么建立本地yum源?

    本文链接:https://www.haomeiwen.com/subject/lmrvjxtx.html