溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

centos6.8中怎么使用外網(wǎng)yum源

發(fā)布時間:2021-07-12 14:54:57 來源:億速云 閱讀:216 作者:Leah 欄目:云計算

本篇文章給大家分享的是有關(guān)centos6.8中怎么使用外網(wǎng)yum源,小編覺得挺實用的,因此分享給大家學(xué)習(xí),希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。


1、設(shè)置/etc/profile
在最后添加兩行:
http_proxy=代理的IP:端口
export http_proxy
然后保存
source /etc/profile

2、配置/etc/yum.conf文件
里面加一句
proxy=代理的IP:端口
然后保存

3、下載外網(wǎng)的yum源repo文件

例如:下載國內(nèi)網(wǎng)易對應(yīng)版本repo文件
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo

把文件拷貝到/etc/yum.repos.d目錄下

檢查這個repo文件,修改如下兩處

enabled=1 #將原本的0改成1
gpgcheck=0 #將原本的1改成0

4、運行以下命令生成緩存

yum clean all

yum makecache

5、然后就可以用了

當(dāng)然也可以直接修改repo文件

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

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
baseurl=http://mirrors.163.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-6

[root@bastion-IDC ~]# yum clean all
[root@bastion-IDC ~]# yum makecache //將服務(wù)器上的軟件包信息緩存到本地,以提高搜索安裝軟件的速度
[root@bastion-IDC ~]# yum update //更新系統(tǒng)

依照上面操作后,yum源就更換成網(wǎng)易的了,并能正常使用。

要特別注意的是:如果要想CentOS使用yum update更新時不升級內(nèi)核,方法如下:
[root@bastion-IDC ~]# cp /etc/yum.conf /etc/yum.confbak
方法一)修改yum的配置文件
[root@bastion-IDC ~]# vim /etc/yum.conf
在[main]的最后添加 exclude=kernel*

方法二)直接在yum的命令后面加上如下的參數(shù):
[root@bastion-IDC ~]# yum --exclude=kernel* update


如果要更換成阿里云的yum源,只需要將/etc/yum.repos.d/CentOS-Base.repo內(nèi)容替換成下面內(nèi)容即可,然后yum clean all、yum makecache、yum update

[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/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#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/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#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/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#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/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

#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/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-6

[root@bastion-IDC ~]# yum clean all
[root@bastion-IDC ~]# yum makecache
如果出現(xiàn)下面報錯:
https://mirrors.aliyun.com/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 22 - "The requested URL returned error: 404 Not Found"

原因分析:
$releasever這個變量在CentOS-Base.repo文件中沒有被識別出來。可以去aliyun的鏡像官網(wǎng)上查看下正確地址:
centos6.8中怎么使用外網(wǎng)yum源
即正確地址是:https://mirrors.aliyun.com/centos/6.9/os/x86_64/repodata/repomd.xml
解決辦法:將$releasever換成6.9
[root@bastion-IDC ~]# sed -i 's/$releasever/6.9/g' CentOS-Base.repo

以上就是centos6.8中怎么使用外網(wǎng)yum源,小編相信有部分知識點可能是我們?nèi)粘9ぷ鲿姷交蛴玫降摹OM隳芡ㄟ^這篇文章學(xué)到更多知識。更多詳情敬請關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI