redhat7初始化yum源


1、卸载原有的yum

 1 [app@localhost ~]$ su - root
 2 Password: 
 3 Last login: Wed Apr 24 17:18:09 CST 2019 on pts/1
 4 [root@localhost ~]# cd /etc/yum.repos.d/
 5 [root@localhost yum.repos.d]# ll
 6 total 4
 7 -rw-r--r--. 1 root root 358 Apr 24 06:16 redhat.repo
 8 [root@localhost yum.repos.d]# tail redhat.repo 
 9 #
10 # Certificate-Based Repositories
11 # Managed by (rhsm) subscription-manager
12 #
13 # *** This file is auto-generated.  Changes made here will be over-written. ***
14 # *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
15 #
16 # If this file is empty and this system is subscribed consider
17 # a "yum repolist" to refresh available repos
18 #
19 [root@localhost yum.repos.d]# yum repolist
20 Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
21 This system is not registered with an entitlement server. You can use subscription-manager to register.
22 repolist: 0
23 [root@localhost yum.repos.d]# rpm -qa | grep yum 
24 yum-utils-1.1.31-50.el7.noarch
25 yum-metadata-parser-1.1.4-10.el7.x86_64
26 yum-3.4.3-161.el7.noarch
27 PackageKit-yum-1.1.10-1.el7.x86_64
28 yum-rhn-plugin-2.0.1-10.el7.noarch
29 yum-langpacks-0.4.2-7.el7.noarch
30 [root@localhost yum.repos.d]# rpm -qa|grep yum|xargs rpm -e --nodeps

2、联网下载yum

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm  
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm  
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm    
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/PackageKit-yum-1.1.10-1.el7.centos.x86_64.rpm   
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-rhn-plugin-2.0.1-10.el7.noarch.rpm 
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.el7.noarch.rpm  
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/PackageKit-1.1.10-1.el7.centos.x86_64.rpm 
wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/PackageKit-glib-1.1.10-1.el7.centos.x86_64.rpm

3、安装yum

[root@localhost yum]# rpm -ivh yum-*
warning: yum-3.4.3-161.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 17%]
   2:yum-plugin-fastestmirror-1.1.31-5################################# [ 33%]
   3:yum-3.4.3-161.el7.centos         ################################# [ 50%]
   4:yum-langpacks-0.4.2-7.el7        ################################# [ 67%]
   5:yum-rhn-plugin-2.0.1-10.el7      ################################# [ 83%]
   6:yum-utils-1.1.31-50.el7          ################################# [100%]
[root@localhost yum]# 

4、获取阿里云repo

[root@localhost yum]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total 4
-rw-r--r--. 1 root root 358 Apr 24 06:16 redhat.repo
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
--2019-04-25 18:58:57--  http://mirrors.aliyun.com/repo/Centos-7.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 27.221.93.99, 27.221.93.94, 27.221.56.136, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|27.221.93.99|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2523 (2.5K) [application/octet-stream]
Saving to: ‘Centos-7.repo’

100%[==================================================================================================>] 2,523       --.-K/s   in 0s      

2019-04-25 18:58:57 (8.27 MB/s) - ‘Centos-7.repo’ saved [2523/2523]

[root@localhost yum.repos.d]# ls
Centos-7.repo  redhat.repo
[root@localhost yum.repos.d]# 

5、替换repo里的版本号

[root@localhost yum.repos.d]#  sed -i 's/$releasever/7/g' /etc/yum.repos.d/Centos-7.repo  
[root@localhost yum.repos.d]#

6、清理,重建缓存,查看repolist

[root@localhost yum.repos.d]# yum clean all
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: base extras updates
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                 | 3.6 kB  00:00:00     
extras                                                                                                               | 3.4 kB  00:00:00     
updates                                                                                                              | 3.4 kB  00:00:00     
(1/12): base/x86_64/group_gz                                                                                         | 166 kB  00:00:00     
(2/12): extras/x86_64/prestodelta                                                                                    |  52 kB  00:00:00     
(3/12): base/x86_64/other_db                                                                                         | 2.6 MB  00:00:01     
(4/12): extras/x86_64/primary_db                                                                                     | 188 kB  00:00:01     
(5/12): extras/x86_64/filelists_db                                                                                   | 236 kB  00:00:01     
(6/12): base/x86_64/filelists_db                                                                                     | 7.1 MB  00:00:05     
(7/12): updates/x86_64/prestodelta                                                                                   | 511 kB  00:00:03     
(8/12): updates/x86_64/other_db                                                                                      | 488 kB  00:00:00     
(9/12): updates/x86_64/filelists_db                                                                                  | 3.0 MB  00:00:05     
updates/x86_64/primary_db      FAILED                                          ========-                  ] 1.2 MB/s |  14 MB  00:00:07 ETA 
http://mirrors.cloud.aliyuncs.com/centos/7/updates/x86_64/repodata/77e1064f4695d093417e973b314fbb8199458df1af4428ee452be30159ee5598-primary.sqlite.bz2: [Errno -1] Metadata file does not match checksum
Trying other mirror.
(10/12): updates/x86_64/primary_db                                                                                   | 3.4 MB  00:00:01     
base/x86_64/primary_db         FAILED                                          
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/repodata/6614b3605d961a4aaec45d74ac4e5e713e517debb3ee454a1c91097955780697-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused"
Trying other mirror.
extras/x86_64/other_db         FAILED                                          =======================    ] 600 kB/s |  22 MB  00:00:03 ETA 
http://mirrors.cloud.aliyuncs.com/centos/7/extras/x86_64/repodata/e3fc99b365562ee4f9dbd898f8acbbad55e2a5e5cf787dab83017026971ccbc9-other.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.cloud.aliyuncs.com:80; Connection refused"
Trying other mirror.
(11/12): extras/x86_64/other_db                                                                                      | 120 kB  00:00:00     
(12/12): base/x86_64/primary_db                                                                                      | 6.0 MB  00:00:02     
Metadata Cache Created
[root@localhost yum.repos.d]# yum repolist
Loaded plugins: fastestmirror, langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
repo id                                               repo name                                                                       status
base/x86_64                                           CentOS-7 - Base - mirrors.aliyun.com                                            10,019
extras/x86_64                                         CentOS-7 - Extras - mirrors.aliyun.com                                             386
updates/x86_64                                        CentOS-7 - Updates - mirrors.aliyun.com                                          1,580
repolist: 11,985
[root@localhost yum.repos.d]# 

猜你喜欢

转载自www.cnblogs.com/kevinlights/p/10779901.html