1. 程式人生 > >Linux Server release 7.3 更換阿裏網絡yum源

Linux Server release 7.3 更換阿裏網絡yum源

軟件包 gpo nature sign ada cache plugin 配置 repos

查看當前系統下的yum源

[root@localhost ~]# rpm -qa |grep yum
yum-3.4.3-150.el7.noarch
yum-utils-1.1.31-40.el7.noarch
yum-langpacks-0.4.2-7.el7.noarch
PackageKit-yum-1.0.7-6.el7.x86_64
yum-rhn-plugin-2.0.1-6.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
[root@localhost ~]# 

刪除當前yum源

[root@localhost ~]# rpm -qa|grep
yum|xargs rpm -e --nodeps

到阿裏雲去找對應得yum源得rpm對應安裝包:

https://mirrors.aliyun.com/centos/7/os/x86_64/Packages

例如:

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
頁面中使用Ctrl+F搜索步驟3中的文件,不要帶版本號:比如yum-utils-1.1.31-24.el7.noarch只需搜索yum-utils即可

cd /mnt 下載:

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-42.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-metadata-parser-1.1.4-10.el7.x86_64.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-rhn-plugin-2.0.1-9.el7.noarch.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/PackageKit-yum-1.1.5-1.el7.centos.x86_64.rpm

wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-3.4.3-154.el7.centos.noarch.rpm

在當前目錄執行 rpm -ivh *.rpm

如果出現依賴關系錯誤裝不上例如:

[root@localhost xx]# rpm -ivh *.rpm
warning: PackageKit-yum-1.1.5-1.el7.centos.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
        PackageKit(x86-64) = 1.1.5-1.el7.centos is needed by PackageKit-yum-1.1.5-1.el7.centos.x86_64
        rpm >= 0:4.11.3-22 is needed by yum-3.4.3-154.el7.centos.noarch
        yum-plugin-fastestmirror is needed by yum-3.4.3-154.el7.centos.noarch
[root@localhost xx]# 

故此處可以加上下面兩個參數強制安裝:

  1. --force 即使覆蓋屬於其它包的文件也強迫安裝
  2. --nodeps 如果該RPM包的安裝依賴其它包,即使其它包沒裝,也強迫安裝。
    [root@localhost xx]# rpm -ivh *.rpm --force --nodeps 
    warning: PackageKit-yum-1.1.5-1.el7.centos.x86_64.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-3.4.3-154.el7.centos         ################################# [ 33%]
       3:PackageKit-yum-1.1.5-1.el7.centos################################# [ 50%]
       4:yum-langpacks-0.4.2-7.el7        ################################# [ 67%]
       5:yum-rhn-plugin-2.0.1-9.el7       ################################# [ 83%]
       6:yum-utils-1.1.31-42.el7          ################################# [100%]
    [root@localhost xx]# 

    安裝成功

進入到yum的配置文件目錄
[root@localhost xx]# cd /etc/yum.repos.d/

下載 wget http://mirrors.aliyun.com/repo/Centos-7.repo或者curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

修改$releasever的值

我們獲取到的配置文件Centos-7.repo打開後有個$releasever,這個是yum變量,我們需要替換掉,否則源沒法使用,如果不替換可以試一下yum的命令查看顯示什麽就知道了。

使用如下命令替換$releasever,

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

yum clean all #清理yum緩存,使設置生效 yum makecache #將服務器上的軟件包信息緩存到本地,以提高搜索安裝軟件的速度

其他的源(以下是搭好的163的yum源的rpm包)

[root@desktop-s4l5vlm /]# rpm -qa |grep yum 
yum-plugin-fastestmirror-1.1.31-42.el7.noarch
yum-utils-1.1.31-40.el7.noarch
yum-rhn-plugin-2.0.1-6.el7.noarch
yum-3.4.3-150.el7.noarch
yum-langpacks-0.4.2-7.el7.noarch
yum-cron-3.4.3-154.el7.centos.noarch
PackageKit-yum-1.0.7-6.el7.x86_64
yum-metadata-parser-1.1.4-10.el7.x86_64
[root@desktop-s4l5vlm /]# 

已下是163的鏈接

http://mirrors.163.com/centos/7.4.1708/os/x86_64/Packages/ 、

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

Linux Server release 7.3 更換阿裏網絡yum源