前言!
这里我真是要被Centos6.9给坑惨了,最刚开始学习linux的时候并没有在意那么的,没有考虑到选版本问题,直到23年下半年,官方不维护Centos6.9了,基本上当时配置的文件和安装的依赖都用不了了,而且不更新了,真的崩溃了,所以真心建议大家选版本的时候要多看几篇文章,避免踩坑,后来为了解决这个问题,在网上搜了很多6.9的配置,最后是用的阿里云的解决的。
由于不同的虚拟机的依赖不同,可能会出现与我不同的错误,建议大家重装的时候先存个快照
重装yum和python
重装yum和python的话分为一下几步
1.卸载已有的python和yum
保证把之前的版本卸载干净
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除系统安装程序python包及其相关
whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
whereis python ##验证删除,返回无结果
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps #卸载yum
whereis yum |xargs rm -frv #卸载残余的yum
rpm -qa|grep python|xargs rpm -ev --allmatches --nodeps ##强制删除系统安装程序python包及其相关
whereis python |xargs rm -frv ##删除所有残余文件 ##xargs,允许你对输出执行其他某些命令
whereis python ##验证删除,返回无结果
rpm -qa|grep yum|xargs rpm -ev --allmatches --nodeps #卸载yum
whereis yum |xargs rm -frv #卸载残余的yum
2.下载新的安装包
因为centos6.9已经不维护了, 所以大部分的镜像都失效了,只有下面的镜像可以使用。
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-2.6.6-66.el6_8.x86_64.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-devel-2.6.6-66.el6_8.x86_64.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-libs-2.6.6-66.el6_8.x86_64.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-pycurl-7.19.0-9.el6.x86_64.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-setuptools-0.6.10-3.el6.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/python-iniparse-0.3.1-2.1.el6.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/rpm-python-4.8.0-55.el6.x86_64.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/yum-utils-1.1.30-40.el6.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-40.el6.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/yum-plugin-protectbase-1.1.30-40.el6.noarch.rpm
wget https://vault.centos.org/6.9/os/x86_64/Packages/yum-plugin-aliases-1.1.30-40.el6.noarch.rpm
3.安装
# 安装所有的包并忽略依赖
rpm -Uvh --replacepkgs python*.rpm --nodeps --force
rpm -Uvh --replacepkgs rpm-python*.rpm --nodeps --force
rpm -Uvh --replacepkgs yum*.rpm --nodeps --force
4.测试
yum --version
python -v
配置 CentOS 6.9阿里源
下文以centos6.9 x86_64为例,其他版本和平台可以将下文配置中的相关字段替换(打开浏览器进入相应url对照)
正常情况下应该使用阿里源http://mirrors.aliyun.com/centos/6.9/
根据链接中的readme显示6.9已被弃用
因此需要使用另一路径http://mirrors.aliyun.com/centos-vault/6.9/
1.删除/etc/yum.repos.d路径下所有.repo文件
2.在该路径下建立如下两个文件
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-6.9 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/os/x86_64/
http://mirrors.aliyuncs.com/centos-vault/6.9/os/x86_64/
http://mirrors.cloud.aliyuncs.com/centos-vault/6.9/os/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
#released updates
[updates]
name=CentOS-6.9 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/updates/x86_64/
http://mirrors.aliyuncs.com/centos-vault/6.9/updates/x86_64/
http://mirrors.cloud.aliyuncs.com/centos-vault/6.9/updates/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
#additional packages that may be useful
[extras]
name=CentOS-6.9 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/extras/x86_64/
http://mirrors.aliyuncs.com/centos-vault/6.9/extras/x86_64/
http://mirrors.cloud.aliyuncs.com/centos-vault/6.9/extras/x86_64/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.9 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/centosplus/x86_64/
http://mirrors.aliyuncs.com/centos-vault/6.9/centosplus/x86_64/
http://mirrors.cloud.aliyuncs.com/centos-vault/6.9/centosplus/x86_64/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
#contrib - packages by Centos Users
[contrib]
name=CentOS-6.9 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/contrib/x86_64/
http://mirrors.aliyuncs.com/centos-vault/6.9/contrib/x86_64/
http://mirrors.cloud.aliyuncs.com/centos-vault/6.9/contrib/x86_64/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
CentOS-SCLo-rh.repo:
# CentOS-SCLo-rh.repo
#
# Please see http://wiki.centos.org/SpecialInterestGroup/SCLo for more
# information
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/sclo/x86_64/rh/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
[centos-sclo-rh-testing]
name=CentOS-7 - SCLo rh Testing
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/sclo/x86_64/rh/
gpgcheck=0
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
[centos-sclo-rh-source]
name=CentOS-7 - SCLo rh Sources
baseurl=http://mirrors.aliyun.com/centos-vault/6.9/sclo/Source/rh/
gpgcheck=1
enabled=1
gpgkey=http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6
3.执行yum clean all&&yum makecache
可能发生的问题:
- RPM-GPG-KEY报错:
执行以下命令wget http://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-6 cp RPM-GPG-KEY-CentOS-6 /etc/pki/rpm-gpg/ rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
- NOT FOUND xxx/repodata/repomd.xml
看下报错的repo的相应路径中是否存在repodata/repomd.xml,适当配置中的调整baseurl