站在巨人的肩膀上
有的时候,我们在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安装就比以前快很多了。