redhat7初始化yum源

时间:2023-03-08 15:36:35
redhat7初始化yum源

1、卸载原有的yum

 [app@localhost ~]$ su - root
Password:
Last login: Wed Apr :: CST on pts/
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total
-rw-r--r--. root root Apr : redhat.repo
[root@localhost yum.repos.d]# tail redhat.repo
#
# Certificate-Based Repositories
# Managed by (rhsm) subscription-manager
#
# *** This file is auto-generated. Changes made here will be over-written. ***
# *** Use "subscription-manager repo-override --help" if you wish to make changes. ***
#
# If this file is empty and this system is subscribed consider
# a "yum repolist" to refresh available repos
#
[root@localhost yum.repos.d]# yum repolist
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.
repolist:
[root@localhost yum.repos.d]# rpm -qa | grep yum
yum-utils-1.1.-.el7.noarch
yum-metadata-parser-1.1.-.el7.x86_64
yum-3.4.-.el7.noarch
PackageKit-yum-1.1.-.el7.x86_64
yum-rhn-plugin-2.0.-.el7.noarch
yum-langpacks-0.4.-.el7.noarch
[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.-.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Preparing... ################################# [%]
Updating / installing...
:yum-metadata-parser-1.1.-.el7 ################################# [ %]
:yum-plugin-fastestmirror-1.1.-################################# [ %]
:yum-3.4.-.el7.centos ################################# [ %]
:yum-langpacks-0.4.-.el7 ################################# [ %]
:yum-rhn-plugin-2.0.-.el7 ################################# [ %]
:yum-utils-1.1.-.el7 ################################# [%]
[root@localhost yum]#

4、获取阿里云repo

[root@localhost yum]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ll
total
-rw-r--r--. root root Apr : redhat.repo
[root@localhost yum.repos.d]# wget http://mirrors.aliyun.com/repo/Centos-7.repo
---- ::-- 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|:... connected.
HTTP request sent, awaiting response... OK
Length: (.5K) [application/octet-stream]
Saving to: ‘Centos-.repo’ %[==================================================================================================>] , --.-K/s in 0s -- :: (8.27 MB/s) - ‘Centos-.repo’ saved [/] [root@localhost yum.repos.d]# ls
Centos-.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-.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 ::
extras | 3.4 kB ::
updates | 3.4 kB ::
(/): base/x86_64/group_gz | kB ::
(/): extras/x86_64/prestodelta | kB ::
(/): base/x86_64/other_db | 2.6 MB ::
(/): extras/x86_64/primary_db | kB ::
(/): extras/x86_64/filelists_db | kB ::
(/): base/x86_64/filelists_db | 7.1 MB ::
(/): updates/x86_64/prestodelta | kB ::
(/): updates/x86_64/other_db | kB ::
(/): updates/x86_64/filelists_db | 3.0 MB ::
updates/x86_64/primary_db FAILED ========- ] 1.2 MB/s | MB :: 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.
(/): updates/x86_64/primary_db | 3.4 MB ::
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 ======================= ] kB/s | MB :: 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.
(/): extras/x86_64/other_db | kB ::
(/): base/x86_64/primary_db | 6.0 MB ::
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- - Base - mirrors.aliyun.com ,
extras/x86_64 CentOS- - Extras - mirrors.aliyun.com
updates/x86_64 CentOS- - Updates - mirrors.aliyun.com ,
repolist: ,
[root@localhost yum.repos.d]#