RedHat6.7切換yum源,很詳細,爲防止地址失效,給大家提供查找的方法。

引言:redhat自帶的yum源好像是需要註冊還是什麼的,也沒有做過詳細的瞭解,這裏對大家講解的是切換CentOS的yum源,自己在網上看到了很多這樣的文章,但是不是地址失效就是造成系統命令都無法執行了。

所以在此自己總結了一下,分享給大家。

首先,爲大家提供三個鏡像站:

網易鏡像站的地址:http://mirrors.163.com/
CentOS鏡像站地址:http://mirror.centos.org/
阿里雲鏡像站地址:https://opsx.alibaba.com/mirror/

無論是我們下載的yum包,還是通過yum命令下載的包,一般的話都是這兩個鏡像站的資源。在後面我們修改yum的配置文件時會切換到這兩個鏡像地址。希望大家記下這兩個地址,想查詢一些依賴包時可去這裏查詢。

其次,爲大家講下切換yum源的方法,以及要注意的東西,沒有什麼地址會永久不變的,所以網上有很多文章中的地址都已經失效了。如果原封不動的去搬過來只能導致系統出錯,所以在這裏我要跟大家講下怎麼避免這個錯誤。

先確認地址是否失效:把我下面提供的地址先粘貼到瀏覽器中,看看是否會出現下載頁面,如果出現則證明沒有失效,如果出現404,不用說已經失效了。

那失效了,怎麼找呢?這就用到了上面這兩個地址了,通過自己系統的版本與系統位數(32/64)來網站上自己查找。

選擇版本:可能你的系統版本是6.7,但是發現鏡像站中6.7的鏈接裏沒有包,那麼就去找大版本的包,也就是說去6.0或者6的鏈接中區尋找。

如果不知道版本信息,請參考:https://blog.csdn.net/qq_36007926/article/details/88713879

  • 這裏是163鏡像站的部分截圖,點擊centos就可以選擇版本了。


 

接下來,進入正題,切換yum源

這裏是我爲大家提供的yum所需要的包的地址:

1.下載yum所需要的包

wget http://mirrors.163.com/centos/6/os/x86_64/Packages/python-urlgrabber-3.9.1-11.el6.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm
wget http://mirrors.163.com/centos/6/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.30-41.el6.noarch.rpm

2.檢查系統自帶的yum包
    rpm -qa |grep yum
3.刪除自帶包
    rpm -aq | grep yum | xargs rpm -e --nodeps    
4.再檢查一下
    rpm -qa |grep yum    
5.執行安裝
    rpm -ivh yum-*    

如果這裏執行報錯的話

[root@redhat67 lib]# rpm -ivh yum-*
    warning: yum-3.2.29-81.el6.centos.noarch.rpm: Header V3 RSA/SHA1 Signature, key ID c105b9de: NOKEY
    error: Failed dependencies:
        python-urlgrabber >= 3.9.1-10 is needed by yum-3.2.29-81.el6.centos.noarch
[root@redhat67 lib]#

說明你需要更新python-urlgrabber的版本,我們先前已經下載完成了直接更新就可以了
    rpm -Uvh python-urlgrabber-3.9.1-11.el6.noarch.rpm

然後在執行

    rpm -ivh yum-*    
6.下面修改yum的配置文件(這裏需要在鏡像站下載一個配置文件CentOS6-Base-163.repo)
    cd /etc/yum.repos.d/
    mv redhat.repo redhat.repo.bak
    mv rhel-source.repo rhel-source.repo.bak
    wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
    vi CentOS6-Base-163.repo

配置文件中需要去檢查一下地址是否有效,在我下方標記紅色的地方是需要修改的,藍色的地方是需要查看是否有效的。

配置文件中標記紅色的url中的“$releasever”是需要修改爲你係統的版本的與上面查找版本類似,修改完成後,粘貼在瀏覽器中查看時候有效。粘貼是請不要粘貼“$basearch/”因爲這個是你的版本號。

如果下載配置文件CentOS6-Base-163.repo的地址失效的話,就手動添加。

7.清理緩存
    yum clean all
8.將服務器上的軟件包信息下載到現在本地緩存,以提高 搜索 安裝軟件的速度
    yum makecache

如果這步報錯的話,查看錯誤信息,如果發現

    Determining fastest mirrors

    http://mirrors.163.com/centos/%24releasever/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"
    Trying other mirror.
    To address this issue please refer to the below knowledge base article 

    https://access.redhat.com/articles/1320623

    If above article doesn't help to resolve this issue please open a ticket with Red Hat Support.

    Error: Cannot retrieve repository metadata (repomd.xml) for repository: base. Please verify its path and try again

這樣的錯誤信息,請仔細查詢配置文件,看是否有哪裏忘記修改了。
9.驗證
    yum install telnet

  • 這裏是手動添加配置文件的內容

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

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

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

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - 163.com
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

到這裏就已經給大家介紹完成了,大家有什麼問題的話,或者我哪裏寫錯的話,希望大家評論出來,我們再慢慢探討,謝謝大家!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章