Linux服務器,centos配置下載yum源倉庫


Linux服務器,centos配置下載yum源倉庫

yum的配置文件
yum 的配置文件在 /etc/yum.repos.d 目錄下, 其中有多個配置文件,每一個配置文件中都可以配置一個或多個repository, 但是最終會被合並為一個交給系統,所以多個文件為了方便管理。

yum倉庫配置

下面提供了 阿里 和 清華大學 兩個鏡像倉庫配置操作說明,實際使用時,選擇其中一個配置即可

進入 阿里巴巴開源鏡像站,包含多種Linux系統的倉庫

以centos為例子:

1. 備份

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2. 下載新的 CentOS-Base.repo 到 /etc/yum.repos.d/

CentOS 6

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

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-6.repo

CentOS 7

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

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

CentOS 8

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

或者

curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

3. 運行 yum makecache 生成緩存

4. 其他

非阿里雲ECS用戶會出現 Couldn't resolve host 'mirrors.cloud.aliyuncs.com' 信息,不影響使用。用戶也可自行修改相關配置: eg:

sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS

配置 清華大學鏡像倉庫

點擊 ? 進入幫助說明頁面 https://mirrors.cnnic.cn/help/centos/。

CentOS 鏡像使用幫助

該文件夾只提供 CentOS 7 與 8,架構僅為 x86_64 ,如果需要較早版本的 CentOS,請參考 centos-vault 的幫助,若需要其他架構,請參考 centos-altarch 的幫助。

建議先備份 /etc/yum.repos.d/ 內的文件。

然后編輯 /etc/yum.repos.d/ 中的相應文件,在 mirrorlist= 開頭行前面加 # 注釋掉;並將 baseurl= 開頭行取消注釋(如果被注釋的話),把該行內的域名(例如mirror.centos.org)替換為 mirrors.tuna.tsinghua.edu.cn

以上步驟可以被下方的命令一步完成

sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \
         -e 's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \
         -i.bak \
         /etc/yum.repos.d/CentOS-*.repo

注意其中的*通配符,如果只需要替換一些文件中的源,請自行增刪。

注意,如果需要啟用其中一些 repo,需要將其中的 enabled=0 改為 enabled=1

最后,更新軟件包緩存

sudo yum makecache


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM