工作上,我们需要使用网上的epel源。可是工作环境网络不通。确定需要的包,一个一个的下载,太繁琐,另外也不知道以后会使用其他的什么包,想着将网上aliyun的镜像同步到本地。
步骤一:在本地CentOS服务器上(虚拟机即可),配置好本地的base源(base源比较容易解决,直接使用光盘镜像就好。)并确保主机可以连接外网。
下载新的CentOS-Base.repo 到/etc/yum.repos.d/
]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
我们需要进入CentOS-Base.repo文件
yum.repos.d]# vim CentOS-Base.repo
修改文件中的baseurl地址
修改前:
修改后:
清除原有yum缓存 yum clean all
生成缓存yum makecache
到这里就配置完成啦!
步骤二:配置好aliyun的epel源。
[root@CentOS7 ~]# wget http://mirrors.aliyun.com/repo/epel-7.repo -O /etc/yum.repos.d/epel-7.repo
--2018-09-13 09:15:54-- http://mirrors.aliyun.com/repo/epel-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 123.6.30.220, 123.6.30.185, 123.6.30.219, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|123.6.30.220|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 664 [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/epel-7.repo’
100%[=============================>] 664 --.-K/s in 0s
2018-09-13 09:15:54 (51.7 MB/s) - ‘/etc/yum.repos.d/epel-7.repo’ saved [664/664]
再次清除缓存,查看
[root@CentOS7 ~]# yum clean all
[root@CentOS7 ~]# yum repolist
步骤三:安装reposync命令。该命令来自于“yum-utils-1.1.31-45.el7.noarch”包,该包在base源中。
[root@CentOS7 ~]# yum install yum-utils-1.1.31-45.el7.noarch -y
注意:reposync命令用于从epel源中下载包。
步骤四:安装createrepo命令。该命令来自“createrepo-0.9.9-28.el7.noarch”包,该包在base源中。
[root@CentOS7 ~]# yum install createrepo-0.9.9-28.el7.noarch -y
注意:createrepo命令用于根据同步到本地的包,重新生成repodata目录。
步骤五:以上是准备操作,现在开始同步操作。
[root@CentOS7 ~]# reposync -r epel -p /root/ # 此处所需时间根据个人网速决定。
注意:将epel源中的rpm包,同步到本地的/root目录下。
步骤六:制作本地仓库。
[root@CentOS7 ~]# createrepo -v /root/epel 由于epep源比较大,此步骤需要比较长的时间;
[root@CentOS7 ~]# ls /root/epel/
Packages Repodata
注意:看到/root/epel目录下多了一个repodata目录,即表示完成
步骤七:如果想要验证的话,将本地的baseurl地址改成:baseurl=file:///root/epel
]# vim epel.repo
[epel]
name=epel
baseurl=file://root/epel
enabled=1
gpgcheck=0
]# yum clean all
]# yum repolist
已加载插件:langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
源标识 源名称 状态
!epel epel 13,204
rhel rhel 9,591
repolist: 22,795