如何把镜像站的资源弄到本地

我们设置yum后,发现安装程序经常网络原因下载很慢,要不就是直接下载到一半GG,所以搞个本地的yum还是非常重要的


1.安装rpm包构建工具

yum install createrepo yum-utils

2.移除不用的yum源

[root@localhost yum.repos.d]# mv /etc/yum.repos.d/CentOS-* /opt/
[root@localhost yum.repos.d]# ls

3.创建你自己需要下载到本地的yum

我这里拿openstack-pike为列,使用的是阿里的镜像站提供的源

vi pike.repo

[pike]
name=pike
baseurl=https://mirrors.aliyun.com/centos/7/cloud/x86_64/openstack-pike/
gpgcheck=0
enabled=1

删除那些不用的yum只是为了不要混了,现在 /etc/yum.repo/ 下面就只有一个源了

[root@localhost yum.repos.d]# ls
pike.repo

4.清理一下,然后查看当前的yum

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: pike
Cleaning up everything
你会发现有一个pike的源,就是我们刚刚创建的

[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror
pike                                                                                                                           | 2.9 kB  00:00:00     
pike/primary_db                                                                                                                | 927 kB  00:00:00     
Determining fastest mirrors
repo id                                                                  repo name                                                              status
pike                                                                     pike                                                                   2,182
repolist: 2,182

5.缓存到本地

reposync -r [你要缓存下来的那个源的名字]

[root@localhost yum.repos.d]# reposync -r pike
(1/2182): GitPython-1.0.1-5.el7.noarch.rpm                                                                                     | 501 kB  00:00:00     
(2/2182): PyQt4-devel-4.12-1.el7.x86_64.rpm                                                                                    | 419 kB  00:00:02     
(3/2182): PyQt4-4.12-1.el7.x86_64.rpm                                                                                          | 2.9 MB  00:00:07     
(4/2182): PyQt4-qsci-api-4.12-1.el7.x86_64.rpm                                                                                 | 156 kB  00:00:00     
(5/2182): XStatic-Angular-common-1.5.8.0-1.el7.noarch.rpm                                                                      | 455 kB  00:00:02     
(6/2182): Xaw3d-1.6.2-4.el7.x86_64.rpm                                                                                         | 170 kB  00:00:00     
(7/2182): Xaw3d-devel-1.6.2-4.el7.x86_64.rpm   
...
...
...耐心等待

6.创建索引, 很重要如果不创建就无法使用

进入刚刚缓存下来的文件夹中,执行createrepo .

[root@localhost yum.repos.d]# cd pike
[root@localhost pike]# createrepo .
Spawning worker 0 with 2182 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

执行完上诉命令命令会生成一个叫repodata的文件夹,可以去看看

[root@localhost pike]# cd repodata/
[root@localhost repodata]# ls
00007899bb2ef33f791537ad8b4bf7668affe30251cec2ce433b6d1512e7d0e0-filelists.xml.gz
1fa2c23114687bd2ed800bdc1dd47d6c2b4e28f6a382ff693b408090681a74bc-other.sqlite.bz2
2945b8d6955c5f93a6852603f31e64ba561c7e472435337d79e6aaceb8166094-primary.sqlite.bz2
3ed291aa3bc7567f7ce784475e9715ca31f12893f7d25f4c916f021b74fbd864-primary.xml.gz
4e9a0a1c08f404c0cd9f63dcdcbbdb86f43736d744b9a1ac09da52e74f0defd1-other.xml.gz
6b44c2a3aaed9fdb7c6afa7169cff92714c185c5bb091d26f93f691fb6de8fe7-filelists.sqlite.bz2
repomd.xml

7.本地源完成,你要怎么用自己看着办,也可以打包传出来耍

tar -zcvf pike.tar.gz pike#打包压缩
tar -zxvf pike.tar.gz#解压缩


你可能感兴趣的:(LINUX,yum,本地源,createrepo,OpenStack)