centos7 更換yum為阿里源或者別的源

coke12138發表於2020-10-19

原理:更改yum配置原檔案或新增檔案(新增檔案可以從網上直接wget或者直接複製內容)

修改檔案內容最為簡單,直接把.repo配置檔案裡的網址改成新的格式(注意變數)。

放幾個yum源取決於你。但要保證有可用的源。

檢視當前yum源:

yum repolist enabled

位置:

/etc/yum.repos.d/

採用新增檔案的方法:

新建備份目錄

mkdir /etc/yum.repos.d.bak

把全部檔案mv到另一個備份目錄

mv *.repo ../yum.repos.d.bak/

新建一個.reop檔案

vi centos-7-aliyun.repo

檔案內容可如果沒有以從真實機上下載下來(‘http://mirrors.aliyun.com/repo/Centos-7.repo’)用記事本開啟復制裡面的內容。

但是,直接把這個下載的檔案“Cnetos-7.repo”移動到配置目錄下也是可以的。

再次檢視當前yum源,字尾顯示為-aliyun或新增的源,而且最後一項狀態值不為0即為連線正常。

如果 意外 情況出現“另外一個程式鎖定了 yum;等待它退出……”可執行 rm -f /var/run/yum.pid 強行關閉yum程式。

 

下載的Cnetos-7.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-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/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-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/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-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

 

相關文章