CentOs更改yum源为阿里云yum源
程序员文章站
2022-07-13 13:29:33
...
注意:更改的前提是CentOs可以上网
查看是否能上网的方法
[aaa@qq.com ~]# ping www.baidu.com
PING www.a.shifen.com (61.135.169.125) 56(84) bytes of data.
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=1 ttl=128 time=22.8 ms
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=2 ttl=128 time=25.0 ms
64 bytes from 61.135.169.125 (61.135.169.125): icmp_seq=3 ttl=128 time=25.1 ms
1. 清理原有的yum配置
首先切换到存放yum文件的目录中,移除所有的文件。
[aaa@qq.com ~]# cd /etc/yum.repos.d/
[aaa@qq.com yum.repos.d]# pwd
/etc/yum.repos.d
[aaa@qq.com yum.repos.d]# ls
CentOS-Base.repo CentOS-Debuginfo.repo CentOS-Media.repo CentOS-Vault.repo
CentOS-CR.repo CentOS-fasttrack.repo CentOS-Sources.repo
[aaa@qq.com yum.repos.d]# mv * /tmp/
[aaa@qq.com yum.repos.d]# ls
[aaa@qq.com yum.repos.d]#
2.下载阿里官网的配置
(1)用百度搜索“阿里巴巴开源镜像站”。(以CentOs7为例)
(2)下载基础包
复制链接地址
将链接地址粘贴到终端,下载基础包
[aaa@qq.com yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
--2020-02-26 21:04:16-- http://mirrors.aliyun.com/repo/Centos-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 182.118.16.175, 182.118.16.168, 182.118.16.176, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|182.118.16.175|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:2523 (2.5K) [application/octet-stream]
正在保存至: “/etc/yum.repos.d/CentOS-Base.repo”
100%[=============================================>] 2,523 --.-K/s 用时 0.001s
2020-02-26 21:04:20 (3.01 MB/s) - 已保存 “/etc/yum.repos.d/CentOS-Base.repo” [2523/2523])
您在 /var/spool/mail/root 中有新邮件
[aaa@qq.com yum.repos.d]# ls
CentOS-Base.repo
[aaa@qq.com yum.repos.d]# pwd
/etc/yum.repos.d
[aaa@qq.com yum.repos.d]# vim CentOS-Base.repo
(3)下载扩展包(epel)
复制链接地址
将链接地址粘贴到终端,下载扩展包
[aaa@qq.com yum.repos.d]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
--2020-02-26 21:09:28-- http://mirrors.aliyun.com/repo/epel-7.repo
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 123.138.154.36, 61.168.101.116, 113.200.15.241, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|123.138.154.36|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:664 [application/octet-stream]
正在保存至: “/etc/yum.repos.d/epel.repo”
100%[=============================================>] 664 792B/s 用时 0.8s
2020-02-26 21:09:34 (792 B/s) - 已保存 “/etc/yum.repos.d/epel.repo” [664/664])
[aaa@qq.com yum.repos.d]# ls
CentOS-Base.repo epel.repo
3.更新yum仓库
[aaa@qq.com yum.repos.d]# yum makecache
[aaa@qq.com yum.repos.d]# cd ~
[aaa@qq.com ~]# yum repolist //列出库
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
源标识 源名称 状态
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,097
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,195
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 323
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 1,475
repolist: 25,090
4.执行安装并检测
(1)安装httpd程序并使用
[aaa@qq.com ~]# yum install -y httpd //安装程序
[aaa@qq.com ~]# systemctl start httpd //开启httpd程序
[aaa@qq.com ~]# systemctl stop firewalld //关闭防火墙
(2)浏览器访问127.0.0.1查看是否安装成功
若出现以下界面则为成功