This directory CentOS 6.7使用阿里云CentOS的yum源
1、备份原有repo文件
#cd /etc/yum.repos.d
#mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
## ll
total 16
-rw-r--r--. 1 root root 2572 Jul 2 2014 CentOS-Base.repo
-rw-r--r--. 1 root root 529 Jun 12 2015 CentOS-Base.repo.backup
-rw-r--r--. 1 root root 358 Oct 24 23:23 redhat.repo
-rw-r--r--. 1 root root 3749 Mar 29 2017 repomd.xml
2.下载repo文件
# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
--2017-10-31 19:14:33-- http://mirrors.aliyun.com/repo/Centos-6.repo
Resolving mirrors.aliyun.com... 223.111.244.145, 223.111.244.152, 223.111.244.147, ...
Connecting to mirrors.aliyun.com|223.111.244.145|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2572 (2.5K) [application/octet-stream]
Saving to: “/etc/yum.repos.d/CentOS-Base.repo”
100%[=============================================================================================================================>] 2,572 --.-K/s in 0s
2017-10-31 19:14:33 (204 MB/s) - “/etc/yum.repos.d/CentOS-Base.repo” saved [2572/2572]
3.但在yum makecahe 时候报错
# yum makecache
Loaded plugins: aliases, changelog, kabi, presto, product-id, refresh-packagekit, security, subscription-manager, tmprepo, verify, versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading support for Red Hat kernel ABI
http://mirrors.aliyun.com/centos/6Server/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/6Server/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/6Server/os/x86_64/repodata/repomd.xml: (28, 'connect() timed out!')
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again
4.查看repo文件
## vi CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/# cd /etc/yum.repos.d/
5.查看6.7的readmew文件,还是有些表变化发现小版本不再进行更新
This directory (and version of CentOS) is deprecated. For normal users,
you should use /6/ and not /6.7/ in your path. Please see this FAQ
concerning the CentOS release scheme:
If you know what you are doing, and absolutely want to remain at the 6.7
level, go to http://vault.centos.org/ for packages.
Please keep in mind that 6.0, 6.1, 6.2, 6.3, 6.4 , 6.5, 6.6 and 6.7 no longer gets any updates, norany security fix's..
根据repo文件变量的变化,可以修改repo文件把所有$releasever替换成6
执行替换操作
#sed -i 's/\$releasever/6/' CentOS-Base.repo
6.清理并重新生成yum缓存
# yum clean all
Loaded plugins: aliases, changelog, kabi, presto, product-id, refresh-packagekit, security, subscription-manager, tmprepo, verify, versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading support for Red Hat kernel ABI
Cleaning repos: base extras updates
Cleaning up Everything
0 delta-package files removed, by presto
7.重新yum makecache
# yum makecache
Loaded plugins: aliases, changelog, kabi, presto, product-id, refresh-packagekit, security, subscription-manager, tmprepo, verify, versionlock
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Loading support for Red Hat kernel ABI
base | 3.7 kB 00:00
base/group_gz | 226 kB 00:00
base/filelists_db | 6.4 MB 00:01
base/primary_db | 4.7 MB 00:00
base/other_db | 2.8 MB 00:00
extras | 3.4 kB 00:00
extras/filelists_db | 25 kB 00:00
extras/prestodelta | 1.3 kB 00:00
extras/primary_db | 29 kB 00:00
extras/other_db | 30 kB 00:00
updates | 3.4 kB 00:00
updates/filelists_db | 3.0 MB 00:00
updates/prestodelta | 145 kB 00:00
updates/primary_db | 4.7 MB 00:01
updates/other_db | 66 MB 00:26
Metadata Cache Created
网上还有一个据说完善的方法,不过没有进行测试,有兴趣的同学可以测试一下
sed -i '/mirrorlist/d' CentOS-Base.repo
sed -i 's/\$releasever/6/' CentOS-Base.repo
sed -i '/\ [addons\]/,/^$/d' CentOS-Base.repo