【linux】centos yum 换源

一、问题描述

CentOS 7 更换yum源后,无法正常使用,报错信息如下:

复制代码
[root@host-10-43-1-3 ~]# yum install tmux
Loaded plugins: fastestmirror, langpacks
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                                                                   |  15 kB  00:00:00     
 * base: mirrors.aliyun.com
 * epel: mirrors.tuna.tsinghua.edu.cn
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                   | 3.6 kB  00:00:00     
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
Trying other mirror.
https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: [Errno 12] Timeout on https://download.docker.com/linux/centos/7/x86_64/stable/repodata/repomd.xml: (28, 'Connection timed out after 30001 milliseconds')
Trying other mirror.

二、解决方案

1、删除yum配置中的原先依赖库

复制代码
sudo rm -rf /etc/yum.repos.d/*

2、下载163源

复制代码
sudo wget -qO- http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm
sudo wget -qO- http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
sudo wget -qO- http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm
sudo wget -qO- http://mirrors.163.com/centos/7.9.2009/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

3、依次安装

复制代码
rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm
rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh yum-3.4.3-168.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

4、进入配置文件夹

复制代码
cd /etc/yum.repos.d

5、 下载最新依赖

复制代码
sudo wget http://mirrors.163.com/.help/CentOS7-Base-163.repo

6、修改配置项

复制代码
vim CentOS7-Base-163.repo

7、更换 $releasever 为centos版本号

我这里的centos版本号是7.9.2009

复制代码
# 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-7.9.2009 - Base - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7.9.2009/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-7.9.2009 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7.9.2009/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-7.9.2009 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=7.9.2009&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7.9.2009/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7.9.2009 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7.9.2009/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

8、 清理yum缓存的各个部分

复制代码
yum clean all

9、重新生成yum新缓存,完成换源

复制代码
yum makecache

Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
base                                   | 3.6 kB     00:00     
extras                                 | 2.9 kB     00:00     
updates                                | 2.9 kB     00:00     
(1/10): base/7/x86_64/group_gz           | 153 kB   00:01     
(2/10): base/7/x86_64/primary_db         | 6.1 MB   01:24     
(3/10): extras/7/x86_64/filelists_db     | 305 kB   00:03     
(4/10): extras/7/x86_64/other_db         | 154 kB   00:00     
(5/10): extras/7/x86_64/primary_db       | 253 kB   00:04     
(6/10): base/7/x86_64/filelists_db       | 7.2 MB   01:41     
(7/10): base/7/x86_64/other_db           | 2.6 MB   00:27     
(8/10): updates/7/x86_64/filelists_db    |  15 MB   03:24     
(9/10): updates/7/x86_64/other_db        | 1.6 MB   00:15     
(10/10): updates/7/x86_64/primary_db     |  27 MB   06:03     
Metadata Cache Created

10、尝试下载新的工具包

复制代码
yum install tmux

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package tmux.x86_64 0:1.8-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

==============================================================
 Package     Arch          Version          Repository   Size
==============================================================
Installing:
 tmux        x86_64        1.8-4.el7        base        243 k

Transaction Summary
==============================================================
Install  1 Package

Total download size: 243 k
Installed size: 558 k
Is this ok [y/d/N]: y
Downloading packages:
tmux-1.8-4.el7.x86_64.rpm                | 243 kB   00:03     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Installing : tmux-1.8-4.el7.x86_64                      1/1 
  Verifying  : tmux-1.8-4.el7.x86_64                      1/1 

Installed:
  tmux.x86_64 0:1.8-4.el7                                     

Complete!

搞定!

附加:

centos7 卸载docker

复制代码
yum remove docker docker-common docker-selinux docker-engine

centos7 安装docker

复制代码
yum install docker
相关推荐
还是鼠鼠21 分钟前
Node.js Session 原理简单介绍 + 示例代码
linux·javascript·vscode·node.js·编辑器·vim·express
紫菜(Nori)39 分钟前
Jenkins 代理自动化-dotnet程序
运维·自动化·jenkins
DDDiccc1 小时前
黑马商城项目(一)MybatisPlus
运维·服务器
offerwa1 小时前
Linux命令行精通:提高工作效率的终端技能
linux
mosaicwang1 小时前
OpenSSH版本的重大升级 :OpenSSH 10
linux
庸子2 小时前
Active Directory域服务管理与高级应用技术白皮书
运维·服务器·网络·windows·ad
奔驰的小野码2 小时前
本地实现Rtsp视频流推送
java·linux·后端·ffmpeg
正点原子2 小时前
【正点原子STM32MP257连载】第四章 ATK-DLMP257B功能测试——USB测试 #USB HOST #USB 鼠标
linux·功能测试·stm32·嵌入式硬件·计算机外设·usb
淋过很多场雨2 小时前
现代c++获取linux系统版本号
linux·开发语言·c++
运维老司机2 小时前
FRP内网穿透代理两个web页面(多端口内网穿透)
linux·frp·内网穿透