本文共 2742 字,大约阅读时间需要 9 分钟。
在数据中心内是不允许直接连外网的,上外网需要通过代理。那么如何使用外网YUM源呢?
1、设置/etc/profile在最后添加两行:http_proxy=代理的IP:端口export http_proxy然后保存source /etc/profile2、配置/etc/yum.conf文件
里面加一句proxy=代理的IP:端口然后保存3、下载外网的yum源repo文件
例如:下载国内网易对应版本repo文件
wget -O /etc/yum.repos.d/CentOS-Base.repo把文件拷贝到/etc/yum.repos.d目录下
检查这个repo文件,修改如下两处
enabled=1 #将原本的0改成1
gpgcheck=0 #将原本的1改成04、运行以下命令生成缓存
yum clean all
yum makecache
5、然后就可以用了
当然也可以直接修改repo文件
[base]
name=CentOS-$releasever - Base#mirrorlist=baseurl=gpgcheck=1gpgkey=#released updates
[updates]name=CentOS-$releasever - Updates#mirrorlist=baseurl=gpgcheck=1gpgkey=#additional packages that may be useful
[extras]name=CentOS-$releasever - Extras#mirrorlist=baseurl=gpgcheck=1gpgkey=#additional packages that extend functionality of existing packages
[centosplus]name=CentOS-$releasever - Plus#mirrorlist=baseurl=gpgcheck=1enabled=0gpgkey=#contrib - packages by Centos Users
[contrib]name=CentOS-$releasever - Contrib#mirrorlist=baseurl=gpgcheck=1enabled=0gpgkey=[root@bastion-IDC ~]# yum clean all
[root@bastion-IDC ~]# yum makecache //将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度[root@bastion-IDC ~]# yum update //更新系统依照上面操作后,yum源就更换成网易的了,并能正常使用。
要特别注意的是:如果要想CentOS使用yum update更新时不升级内核,方法如下:
[root@bastion-IDC ~]# cp /etc/yum.conf /etc/yum.confbak方法一)修改yum的配置文件[root@bastion-IDC ~]# vim /etc/yum.conf在[main]的最后添加 exclude=kernel*方法二)直接在yum的命令后面加上如下的参数:
[root@bastion-IDC ~]# yum --exclude=kernel* update如果要更换成阿里云的yum源,只需要将/etc/yum.repos.d/CentOS-Base.repo内容替换成下面内容即可,然后yum clean all、yum makecache、yum update
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.comfailovermethod=prioritybaseurl=#mirrorlist=gpgcheck=1gpgkey=#released updates
[updates]name=CentOS-$releasever - Updates - mirrors.aliyun.comfailovermethod=prioritybaseurl=#mirrorlist=gpgcheck=1gpgkey=#additional packages that may be useful
[extras]name=CentOS-$releasever - Extras - mirrors.aliyun.comfailovermethod=prioritybaseurl=#mirrorlist=gpgcheck=1gpgkey=#additional packages that extend functionality of existing packages
[centosplus]name=CentOS-$releasever - Plus - mirrors.aliyun.comfailovermethod=prioritybaseurl=#mirrorlist=gpgcheck=1enabled=0gpgkey=#contrib - packages by Centos Users
[contrib]name=CentOS-$releasever - Contrib - mirrors.aliyun.comfailovermethod=prioritybaseurl=#mirrorlist=gpgcheck=1enabled=0gpgkey=[root@bastion-IDC ~]# yum clean all
[root@bastion-IDC ~]# yum makecache如果出现下面报错:: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"原因分析:
$releasever这个变量在CentOS-Base.repo文件中没有被识别出来。可以去aliyun的镜像官网上查看下正确地址:即正确地址是:解决办法:将$releasever换成6.9[root@bastion-IDC ~]# sed -i 's/$releasever/6.9/g' CentOS-Base.repo转载地址:http://smkax.baihongyu.com/