一、前言
作为一名小小java程序媛,面对领导安排的Linux/Unix部署任务而言有点小小的惶恐,刚拿到服务器先瞎jb操作了一番,查阅资料,跟着步骤怀着忐忑的心强制删除系统yum。。。完了还没开始就已经结束(PS:别骂,容易心碎!),刚好又是对接其他公司的服务器,传文件权限比较特殊,下面详细补救操作流程show time:
1.1.0:再次查看,已经什么都没有了
1.1.1:使用阿里云镜像源下载 yum-plugin-fastestmirror
包:
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
安装 yum-plugin-fastestmirror
包:
sudo rpm -ivh yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
1.1.2:使用 wget
命令从阿里云镜像源下载 yum-metadata-parser
包:
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
安装 yum-metadata-parser
包:
sudo rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
1.1.3: 下载 yum
包:
wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
安装 yum
包:
sudo rpm -ivh yum-3.4.3-168.el7.centos.noarch.rpm
懒人也可以使用 rpm -Uvh
命令来升级或安装所有以 yum-
开头的 RPM 包:
sudo rpm -Uvh yum-*.rpm
1.1.4:导入证书:
sudo rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
1.1.5:使用 wget
命令下载 GPG 密钥文件并将其保存到特定位置是一个常见的步骤。当你设置或更新 YUM 仓库配置时,可以确保软件包的完整性和来源可信
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7 http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-7
注:在使用 rpm -ivh
命令安装 RPM 包时,如果遇到依赖性问题,可以使用 --nodeps
选项来忽略依赖关系
sudo rpm -ivh --nodeps yum-3.4.3-168.el7.centos.noarch.rpm
1.1.6:清除缓存,生成新的缓存:
sudo yum clean all
sudo yum makecache
1.1.7:重新安装 yum
包管理器本身。这在 yum
相关文件损坏或遇到功能异常时可能会有所帮助。重新安装会覆盖已安装的 yum
文件,但不会更改配置文件中已经修改的内容
sudo yum reinstall yum
二、验证yum命令有正确版本信息后,还是无法使用yum命令安装相关的包:
[root@svrysldb ~]# yum --version
3.4.3
Installed: rpm-4.11.3-45.el7.x86_64 at 2023-10-26 02:50
Built : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2020-06-02 12:11
Committed: Michal Domonkos <mdomonko@redhat.com> at 2020-06-02
Installed: subscription-manager-1.24.42-1.el7.x86_64 at 2023-10-26 02:50
Built : Red Hat, Inc. <http://bugzilla.redhat.com/bugzilla> at 2020-06-20 03:47
Committed: Christopher Snyder <csnyder@redhat.com> at 2020-06-19
Installed: yum-3.4.3-168.el7.centos.noarch at 2024-08-19 03:28
Built : CentOS BuildSystem <http://bugs.centos.org> at 2020-10-01 17:03
Committed: CentOS Sources <bugs@centos.org> at 2020-09-29
Installed: yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch at 2024-08-19 03:28
Built : CentOS BuildSystem <http://bugs.centos.org> at 2020-05-12 16:27
Committed: Michal Domonkos <mdomonko@redhat.com> at 2020-03-12
2.1.1:访问阿里云网址正常打开:curl -I http://mirrors.aliyun.com/centos
尝试随便安装个东西看报什么错?yum install zlib-devel
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
http://mirrors.aliyun.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article
https://access.redhat.com/articles/1320623
If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.
http://mirrors.cloud.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
Trying other mirror.
One of the configured repositories failed (CentOS-7Server - Base - mirrors.aliyun.com),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=base ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable base
or
subscription-manager repos --disable=base
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=base.skip_if_unavailable=true
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
http://mirrors.aliyun.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
http://mirrors.cloud.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com; Unknown error"
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
http://mirrors.aliyuncs.com/centos/7Server/os/x86_64/repodata/repomd.xml: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
发现"7Server"版本在官方网站没有的,修改vim/etc/yum.repos.d/CentOS-Base.repo 把其中$releasever
为对应的系统版本路径改为7代替:
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
2.2.2:接下来尝试下载:
[root@svryslapp yum.repos.d]# sudo yum --disablerepo=base install pcre-devel
Loaded plugins: 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 | 4.3 kB 00:00:00
extras | 2.9 kB 00:00:00
file:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
Trying other mirror.
One of the configured repositories failed (local),
and yum doesn't have enough cached data to continue. At this point the only
safe thing yum can do is fail. There are a few ways to work "fix" this:
1. Contact the upstream for the repository and get them to fix the problem.
2. Reconfigure the baseurl/etc. for the repository, to point to a working
upstream. This is most often useful if you are using a newer
distribution release than is supported by the repository (and the
packages for the previous distribution release still work).
3. Run the command with the repository temporarily disabled
yum --disablerepo=local ...
4. Disable the repository permanently, so yum won't use it by default. Yum
will then just ignore the repository until you permanently enable it
again or use --enablerepo for temporary usage:
yum-config-manager --disable local
or
subscription-manager repos --disable=local
5. Configure the failing repository to be skipped, if it is unavailable.
Note that yum will try to contact the repo. when it runs most commands,
so will have to try and fail each time (and thus. yum will be be much
slower). If it is a very temporary problem though, this is often a nice
compromise:
yum-config-manager --save --setopt=local.skip_if_unavailable=true
failure: repodata/repomd.xml from local: [Errno 256] No more mirrors to try.
file:///mnt/repodata/repomd.xml: [Errno 14] curl#37 - "Couldn't open file /mnt/repodata/repomd.xml"
报错:"couldn't open file /mnt/repodata/repomd.xml",应该是配置本地源了,它去本地找文件去了,切换目录至/etc/yum.repos.d下 将所有文件打开看有没有下面这些配置:
注释掉红框里的内容,后重新清除 Yum 缓存并重新生成缓存 :
sudo yum clean all
sudo yum makecache
后测试安装几个命令没有报错啦:
yum install zlib-devel bzip2-devel opssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc libffi-devel
三、后绪
以上就是全部个人删除yum到重新安装再到正常使用yum安装依赖包的所有过程,每个人遇到的问题会不一样,希望小编的这篇文章能给你们带来帮助,留下美赞不然喊胖虎来揍你!!!