RHEL7 更换阿里源
环境RHEL7系统
参考:https://blog.csdn.net/qq_31725371/article/details/82766436
https://www.cnblogs.com/zlg88/p/11978529.html
1. 首先核对一下当前系统使用的yum版本
[root@localhost ~]# rpm -qa | grep yum
2. su到root账号,使用命令删除yum相关文件
[root@localhost ~]# rpm -qa | grep yum | xargs rpm -e --nodeps
3. 先打开浏览器打开https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/核对一下以下软件包版本,建议使用最新的软件包。然后下载到/tmp/install里
[root@localhost ~]# mkdir /tmp/install [root@localhost ~]# cd /tmp/install [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
4. 下载的软件包由于直接安装会有依赖的问题,所以加上--force参数强制安装
[root@localhost install]# rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm \ python-urlgrabber-3.10-10.el7.noarch.rpm \ yum-3.4.3-168.el7.centos.noarch.rpm \ yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm \ yum-utils-1.1.31-54.el7_8.noarch.rpm \ --force --nodeps
5. 下载阿里yum镜像配置文件到/etc/yum.repos.d/目录
[root@localhost install]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
6. 编辑刚下载的yum配置文件 将所有$releasever替换为7(文章末尾附有CentOS-Base.repo更改后文档)
[root@localhost yum.repos.d]# vim /etc/yum.repos.d/CentOS-Base.repo
:%s/$releasever/7/g #替换命令
这里将163、Centos源一并加入 http://mirrors.aliyun.com/centos/7/ http://mirrors.163.com/centos/7/ http://centos.ustc.edu.cn/centos/7/
7. 关闭订阅管理器
[root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/subscription-manager.conf 将 enabled=1 更改为 enabled=0
8. 运行以下命令更新yum源
[root@localhost yum.repos.d]# yum clean all [root@localhost yum.repos.d]# yum makecache [root@localhost yum.repos.d]# yum update #线上服务器建议不执行此条命令
其他
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-7 - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/ http://mirrors.163.com/centos/7/os/$basearch/ http://centos.ustc.edu.cn/centos/7/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-7 - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/ http://mirrors.163.com/centos/7/updates/$basearch/ http://centos.ustc.edu.cn/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/ http://mirrors.163.com/centos/7/extras/$basearch/ http://centos.ustc.edu.cn/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/ http://mirrors.163.com/centos/7/centosplus/$basearch/ http://centos.ustc.edu.cn/centos/7/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-7 - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/ http://mirrors.163.com/centos/7/contrib/$basearch/ http://centos.ustc.edu.cn/centos/7/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
换源操作记录
[root@localhost ~]# rpm -qa | grep yum yum-utils-1.1.31-24.el7.noarch yum-langpacks-0.4.2-3.el7.noarch yum-metadata-parser-1.1.4-10.el7.x86_64 yum-rhn-plugin-2.0.1-4.el7.noarch PackageKit-yum-0.8.9-11.el7.x86_64 yum-3.4.3-118.el7.noarch [root@localhost ~]# rpm -qa | grep yum | xargs rpm -e --nodeps [root@localhost ~]# mkdir /tmp/install [root@localhost ~]# cd /tmp/install [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm --2021-03-03 01:11:14-- https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 180.97.148.111, 58.215.146.115, 218.94.206.240, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|180.97.148.111|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 28348 (28K) [application/x-redhat-package-manager] Saving to: ‘yum-metadata-parser-1.1.4-10.el7.x86_64.rpm’ 100%[======================================>] 28,348 --.-K/s in 0s 2021-03-03 01:11:14 (198 MB/s) - ‘yum-metadata-parser-1.1.4-10.el7.x86_64.rpm’ saved [28348/28348] [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm --2021-03-03 01:11:48-- https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 58.216.16.39, 58.221.54.118, 218.94.206.240, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|58.216.16.39|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 1298856 (1.2M) [application/x-redhat-package-manager] Saving to: ‘yum-3.4.3-168.el7.centos.noarch.rpm’ 100%[======================================>] 1,298,856 7.49MB/s in 0.2s 2021-03-03 01:11:48 (7.49 MB/s) - ‘yum-3.4.3-168.el7.centos.noarch.rpm’ saved [1298856/1298856] [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm --2021-03-03 01:12:10-- https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 218.94.206.248, 180.97.148.39, 58.215.146.120, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|218.94.206.248|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 35216 (34K) [application/x-redhat-package-manager] Saving to: ‘yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm’ 100%[======================================>] 35,216 --.-K/s in 0.001s 2021-03-03 01:12:10 (26.9 MB/s) - ‘yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm’ saved [35216/35216] [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm --2021-03-03 01:12:21-- https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 61.147.223.239, 58.215.146.121, 58.221.54.119, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|61.147.223.239|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 124852 (122K) [application/x-redhat-package-manager] Saving to: ‘yum-utils-1.1.31-54.el7_8.noarch.rpm’ 100%[======================================>] 124,852 --.-K/s in 0.06s 2021-03-03 01:12:22 (2.14 MB/s) - ‘yum-utils-1.1.31-54.el7_8.noarch.rpm’ saved [124852/124852] [root@localhost install]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm --2021-03-03 01:12:34-- https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 58.221.54.115, 61.147.223.242, 218.94.206.248, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|58.221.54.115|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 111048 (108K) [application/x-redhat-package-manager] Saving to: ‘python-urlgrabber-3.10-10.el7.noarch.rpm’ 100%[======================================>] 111,048 --.-K/s in 0.03s 2021-03-03 01:12:39 (3.10 MB/s) - ‘python-urlgrabber-3.10-10.el7.noarch.rpm’ saved [111048/111048] [root@localhost install]# ll total 1572 -rw-r--r--. 1 root root 111048 Apr 3 2020 python-urlgrabber-3.10-10.el7.noarch.rpm -rw-r--r--. 1 root root 1298856 Oct 14 15:21 yum-3.4.3-168.el7.centos.noarch.rpm -rw-r--r--. 1 root root 28348 Jul 4 2014 yum-metadata-parser-1.1.4-10.el7.x86_64.rpm -rw-r--r--. 1 root root 35216 May 13 2020 yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm -rw-r--r--. 1 root root 124852 May 13 2020 yum-utils-1.1.31-54.el7_8.noarch.rpm [root@localhost install]# ls python-urlgrabber-3.10-10.el7.noarch.rpm yum-3.4.3-168.el7.centos.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm yum-utils-1.1.31-54.el7_8.noarch.rpm [root@localhost install]# [root@localhost install]# [root@localhost install]# [root@localhost install]# rpm -ivh yum-metadata-parser-1.1.4-10.el7.x86_64.rpm \ > python-urlgrabber-3.10-10.el7.noarch.rpm \ > yum-3.4.3-168.el7.centos.noarch.rpm \ > yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm \ > yum-utils-1.1.31-54.el7_8.noarch.rpm \ > --force --nodeps warning: yum-metadata-parser-1.1.4-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:python-urlgrabber-3.10-10.el7 ################################# [ 20%] 2:yum-metadata-parser-1.1.4-10.el7 ################################# [ 40%] 3:yum-plugin-fastestmirror-1.1.31-5################################# [ 60%] 4:yum-3.4.3-168.el7.centos ################################# [ 80%] 5:yum-utils-1.1.31-54.el7_8 ################################# [100%] [root@localhost install]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo --2021-03-03 01:13:53-- http://mirrors.aliyun.com/repo/Centos-7.repo Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 218.94.206.241, 221.229.169.243, 117.91.179.110, ... Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|218.94.206.241|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2523 (2.5K) [application/octet-stream] Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’ 100%[======================================>] 2,523 --.-K/s in 0s 2021-03-03 01:13:58 (171 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2523/2523] [root@localhost yum.repos.d]# vi /etc/yum.repos.d/CentOS-Base.repo [root@localhost yum.repos.d]# /etc/yum/pluginconf.d/subscription-manager.conf bash: /etc/yum/pluginconf.d/subscription-manager.conf: Permission denied [root@localhost yum.repos.d]# vim /etc/yum/pluginconf.d/subscription-manager.conf [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# yum clean all Loaded plugins: fastestmirror, product-id Cleaning repos: base extras updates [root@localhost yum.repos.d]# yum makecache Loaded plugins: fastestmirror, product-id Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00 extras | 2.9 kB 00:00 updates | 2.9 kB 00:00 (1/10): base/x86_64/group_gz | 153 kB 00:00 (2/10): base/x86_64/primary_db | 6.1 MB 00:00 (3/10): base/x86_64/other_db | 2.6 MB 00:00 (4/10): extras/x86_64/primary_db | 225 kB 00:00 (5/10): extras/x86_64/filelists_db | 226 kB 00:00 (6/10): extras/x86_64/other_db | 134 kB 00:00 (7/10): updates/x86_64/filelists_db | 3.4 MB 00:00 (8/10): updates/x86_64/other_db | 471 kB 00:00 (9/10): updates/x86_64/primary_db | 5.6 MB 00:01 (10/10): base/x86_64/filelists_db | 7.2 MB 00:05 Metadata Cache Created [root@localhost yum.repos.d]#

浙公网安备 33010602011771号