如何将CentOS的yum源更换为阿里云源

一、yum源简介

Yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。 (来自百度百科)

默认yum源为CentOS官方源:mirrorlist.centos.org。

因其服务器在国外,直接从官方源下载安装软件时稳定性、速度等有时并不是很好,国内有如阿里云源、网易源等镜像站点,比官方源更稳定、速度更快。
二、yum安装软件命令

安装软件(以foo-x.x.x.rpm为例):yum install foo-x.x.x.rpm

删除软件:yum remove foo-x.x.x.rpm或者yum erase foo-x.x.x.rpm

升级软件:yum update foo或者yum update foo

查询信息:yum info foo
三、修改yum源为阿里云
        3.1 yum源配置文件路径:

                /etc/yum.repos.d/CentOS-Base.repo
        3.2 查看CentOS-Base.repo文件内容:

                cat /etc/yum.repos.d/CentOS-Base.repo

[root@sheng yum.repos.d]# cat CentOS-Base.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
[root@sheng yum.repos.d]#

3.3 备份官方源配置:

                cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
        3.4 下载阿里云yum源配置文件覆盖原官方源配置文件:

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

                此时该文件( /etc/yum.repos.d/CentOS-Base.repo)已是阿里云yum源配置文件,可用 cat /etc/yum.repos.d/CentOS-Base.repo 查看文件内容。

        3.5 清理缓存并生成新的缓存:             

                yum clean all

                yum makecache
         3.6 更新软件

                sudo yum -y update

注意:如果Linux 机器中没有CURL 命令,可以COPY 项目aliyun 上面repo 的内容。

配置CentOS 8 Stream使用阿里云的步骤如下: 1. 首先,确保你的CentOS 8 Stream环境可以访问外网,可以通过ping命令测试是否能够ping通mirrors.aliyun.com。 2. 备份原有的官方yum源配置文件: ``` mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup ``` 3. 下载阿里云CentOS 8 Stream配置文件: ``` wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo ``` 4. 清除并生成缓存: ``` yum clean all yum makecache ``` 5. 确认阿里云已经生效: ``` yum list ``` 请注意,以上步骤适用于CentOS 8 Stream版本。如果你使用的是其他版本的CentOS,请根据对应版本的阿里云配置文件进行相应的操作。 #### 引用[.reference_title] - *1* *2* [CentOS7配置阿里云镜像(超详细过程)](https://blog.csdn.net/KingveyLee/article/details/114984534)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [CentOS-Stream-9-latest-x86_64 更换为aliyun 更换阿里](https://blog.csdn.net/y31307/article/details/127456334)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^koosearch_v1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

shenghuiping2001

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值