Centos7更換倉庫源為阿里云鏡像的詳細(xì)步驟
服務(wù)器鏡像如下:/etc/yum.repos.d
[root@ecs-q97onp yum.repos.d]# ll
total 44
-rw-r--r-- 1 root root 2523 Mar 18 21:42 CentOS-Base.repo
-rw-r--r-- 1 root root 1309 Mar 2 2021 CentOS-CR.repo
-rw-r--r-- 1 root root 649 Mar 2 2021 CentOS-Debuginfo.repo
-rw-r--r-- 1 root root 326 Mar 2 2021 CentOS-fasttrack.repo
-rw-r--r-- 1 root root 630 Mar 2 2021 CentOS-Media.repo
-rw-r--r-- 1 root root 1331 Mar 2 2021 CentOS-Sources.repo
-rw-r--r-- 1 root root 7577 Mar 2 2021 CentOS-Vault.repo
-rw-r--r-- 1 root root 640 Mar 2 2021 CentOS-x86_64-kernel.repo
-rw-r--r-- 1 root root 664 Mar 18 21:25 epel.repo
這里默認(rèn)是清華源,但是在使用yum安裝的時候提示找不到鏡像,故而更換阿里源。
更換基礎(chǔ)源配置文件
# CentOS 基礎(chǔ)源---這句話很重要哦 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
修改后的阿里云EPEL源配置
sudo tee /etc/yum.repos.d/epel.repo <<'EOF'
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch - Aliyun
baseurl=https://mirrors.aliyun.com/epel/7/$basearch
#baseurl=https://mirrors.aliyun.com/epel/7/$basearch
metalink=
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug - Aliyun
baseurl=https://mirrors.aliyun.com/epel/7/$basearch/debug
#baseurl=https://mirrors.aliyun.com/epel/7/$basearch/debug
metalink=
failovermethod=priority
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
gpgcheck=1
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source - Aliyun
baseurl=https://mirrors.aliyun.com/epel/7/SRPMS
#baseurl=https://mirrors.aliyun.com/epel/7/SRPMS
metalink=
failovermethod=priority
enabled=0
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
gpgcheck=1
EOF
修改說明
鏡像地址變更:
- 將原地址 mirrors.tuna.tsinghua.edu.cn 改為 mirrors.aliyun.com
- 去除了 metalink 參數(shù)(阿里云鏡像不需要該參數(shù))
GPG密鑰地址:
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
+ gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
倉庫命名標(biāo)識:
- name=Extra Packages for Enterprise Linux 7 - $basearch
+ name=Extra Packages for Enterprise Linux 7 - $basearch - Aliyun
操作步驟
備份原有配置:
sudo cp /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.bak
應(yīng)用新配置:
sudo curl -o /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
清理并重建緩存:
sudo yum clean all sudo yum makecache
驗證配置:
yum repolist epel
應(yīng)該看到類似輸出:
repo id repo name
epel/7/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 - Aliyun
注意事項
如果遇到 GPG key retrieval failed 錯誤,可臨時禁用 GPG 檢查:
sudo yum install --nogpgcheck [package-name]
建議保留原始清華源配置備份,以便需要時恢復(fù):
sudo mv /etc/yum.repos.d/epel.repo.bak /path/to/backup/
阿里云鏡像地址支持 HTTPS 協(xié)議訪問,如果系統(tǒng)未安裝 SSL 證書,可以改用 HTTP:
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
其他相關(guān)鏡像源推薦配置:
# CentOS 基礎(chǔ)源---這句話很重要哦 sudo curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo # Docker CE 源 sudo curl -o /etc/yum.repos.d/docker-ce.repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
配置前后對比圖
- baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/$basearch
+ baseurl=https://mirrors.aliyun.com/epel/7/$basearch
- gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
+ gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-7
yum安裝的時候指定使用某個鏡像
sudo yum install --disablerepo=* --enablerepo=epel[epel為倉庫ID] 軟件包名
知識擴(kuò)展
centos7更換阿里云鏡像源步驟
在CentOS 7上更換為阿里云的鏡像源可以通過以下步驟進(jìn)行:
備份當(dāng)前的YUM源配置文件
sudo cp -a /etc/yum.repos.d /etc/yum.repos.d.backup
清理原有的YUM源配置文件
sudo rm -f /etc/yum.repos.d/*.repo
下載阿里云的CentOS 7源配置文件
sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
清除YUM緩存并生成新的緩存
sudo yum clean all sudo yum makecache
完成以上步驟后,您的系統(tǒng)就會使用阿里云的鏡像源進(jìn)行軟件包的安裝和更新。
Centos7更換阿里云鏡像
1.安裝wget
yum -y install wget
2.建議備份原有的yum源文件,不要直接刪除
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
3.下載阿里云鏡像文件
cd /etc/yum.repos.d wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
4.清理緩存
yum clean all
5.生成緩存
yum makecache
6.更新最新源設(shè)置
yum update -y
到此這篇關(guān)于Centos7更換倉庫源為阿里云鏡像的詳細(xì)步驟的文章就介紹到這了,更多相關(guān)Centos7更換阿里云鏡像內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
在CentOS 7上安裝Node.js 18.20.4全過程
本文指導(dǎo)在CentOS7上安裝不支持的Node.js18.20.4,通過非官方構(gòu)建版本實(shí)現(xiàn),涵蓋下載解壓、環(huán)境變量配置及npm鏡像源設(shè)置,同時提醒依賴glibc時建議使用Docker或更換系統(tǒng)2025-10-10
解析Linux高性能網(wǎng)絡(luò)IO和Reactor模型
網(wǎng)絡(luò)I/O,可以理解為網(wǎng)絡(luò)上的數(shù)據(jù)流。通常我們會基于socket與遠(yuǎn)端建立一條TCP或者UDP通道,然后進(jìn)行讀寫。單個socket時,使用一個線程即可高效處理;然而如果是10K個socket連接,或者更多,我們?nèi)绾巫龅礁咝阅芴幚?/div> 2021-06-06
Linux如何使用 MyCat 實(shí)現(xiàn) MySQL 主從讀寫分離
這篇文章主要介紹了Linux如何 MyCat 實(shí)現(xiàn) MySQL 主從讀寫分離,感興趣并且想詳情了解的小伙伴接著看下文吧2021-08-08
Ubuntu系統(tǒng)網(wǎng)絡(luò)故障排查的方法
最近在使用Ubuntu系統(tǒng)的時候碰到一個問題,連接無線網(wǎng)絡(luò)的時候,發(fā)現(xiàn)右上角網(wǎng)絡(luò)設(shè)置中沒有 Enable Wi-Fi 這個選項了,所以通過一步步排查,終于找了解決辦法,現(xiàn)在分享給大家,有需要的朋友們可以參考借鑒。2016-10-10
Linux下安裝MariaDB數(shù)據(jù)庫問題及解決方法(二進(jìn)制版本的安裝)
MariaDB數(shù)據(jù)庫 分為源代碼版本和二進(jìn)制版本,源代碼版本需要cmake編譯,這里是二進(jìn)制版本的安裝。下面通過本文給大家介紹Linux下安裝MariaDB數(shù)據(jù)庫問題及解決方法(二進(jìn)制版本的安裝),感興趣的朋友參考下吧2016-11-11最新評論

