Linux:設置CentOS7的yum源爲阿里的源:Cannot find a valid baseurl for repo: base/7/x86_64

參考:

  1. https://www.cnblogs.com/muyunren/p/7221505.html

  2. https://blog.csdn.net/fay462298322/article/details/76033136

  3. https://blog.csdn.net/zhugq_1988/article/details/47784031

    在一個剛安裝好的centos7上使用yum install的時候,報出了Cannot find a valid baseurl for repo: base/7/x86_64這個錯誤,很明顯是源的訪問問題,於是在網上搜了相關解決方案,全是什麼改DNS、/etc/sysconfig/network-scripts/ifcfg-ens33什麼的,跟這些基本沒關係,這些只是你的網絡沒設置好,而根本原因就是訪問yum相關資源找不到,國內很多時候資源都是被牆了,於是我用了阿里的yum源地址,http://mirrors.aliyun.com/repo/Centos-7.repo替換/etc/yum.repos.d/CentOS-Base.repo 就可以了;

    由於我選擇的安裝方式是最小安裝,所以所有的工具基本都是沒有的。網上使用的方式使用wget去獲取yum源的配置文檔,而現在我們的系統是沒有wget這個工具的。有兩個方式去解決這個問題。一個是安裝wget這個工具,另一個是不是用這個工具,直接同過Xhell直接copy yum的配置文檔保存使用。

copy的方式

1.瀏覽器打開http://mirrors.aliyun.com/repo/Centos-7.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


2.使用Notepad++打開該文件,複製全部內容

在這裏插入圖片描述

3.編輯CentOS-Base.repo文件

到達/etc/yum.repos.d文件夾下,修改CentOS-Base.repo爲CentOS-Base.repo.bak以取消系統對於該文件的依賴。
在這裏插入圖片描述

4.輸入:1,$d刪除全部內容

在這裏插入圖片描述

5.使用XShell將下載的文件內容複製到該文檔中,退出並保存

在這裏插入圖片描述

6.執行yum源更新命令

yum clean all
yum makecache
yum update

7.yum 安裝出錯

[root@iz25m0z7ik3z ~]#yum install mysql
Loaded plugins: security
http://mirrors.aliyun.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyun.com'"
Trying other mirror.
http://mirrors.aliyuncs.com/centos/6/os/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyuncs.com'"
Trying other mirror.
http://mirrors.aliyun.com/epel/6/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyun.com'"
Trying other mirror.
http://mirrors.aliyuncs.com/epel/6/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyuncs.com'"
Trying other mirror.
http://mirrors.aliyun.com/centos/6/extras/x86_64/repodata/repomd.xml: [Errno 14] PYCURL ERROR 6 - "Couldn't resolve host 'mirrors.aliyun.com'"

1. 修改dns

[root@iz25m0z7ik3z ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

文末添加

DNS1=8.8.8.8
DNS2=8.8.4.4

--網關不對也會導致連不上網

2. 重啓network 服務

[root@iz25m0z7ik3z ~]# service network restart

Shutting down interface eth0:  Device state: 3 (disconnected)
                                                           [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
FATAL: Module off not found.
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2
                                                           [  OK  ]
Bringing up interface eth1:  RTNETLINK answers: File exists
RTNETLINK answers: File exists
                                                           [  OK  ]
FATAL: Module off not found.

3. 如下提示表示network 服務 與 NetworkManager服務衝突

Bringing up interface eth0:  Active connection state: activated
Active connection path: /org/freedesktop/NetworkManager/ActiveConnection/2
                                                           [  OK  ]

應該是之前安裝了圖形界面“X Window System”導致。

4. 停止NetworkManager

解決方式:禁用NetworkManager

  1. systemctl stop NetworkManager
  2. systemctl disable NetworkManager

5. 再次重啓 network 服務

[root@iz25m0z7ik3z ~]#  service network restart

Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
FATAL: Module off not found.
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:  Determining if ip address 10.44.153.37 is already in use for device eth0...
                                                           [  OK  ]
Bringing up interface eth1:  Determining if ip address 101.200.188.182 is already in use for device eth1...
RTNETLINK answers: File exists
                                                           [  OK  ]
FATAL: Module off not found.

我到這裏就好了,下面的是原文作者所報的錯誤,僅供參考

6. 該警告一般是由於網卡解析arp協議導致的,可在網卡的配置文件中加入ARPCHECK=NO參數來屏蔽該檢查

[root@iz25m0z7ik3z ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0

文末添加

ARPCHECK=no

再次啓動網卡

Shutting down interface eth0:                              [  OK  ]
Shutting down interface eth1:                              [  OK  ]
Shutting down loopback interface:                          [  OK  ]
FATAL: Module off not found.
Bringing up loopback interface:                            [  OK  ]
Bringing up interface eth0:                                [  OK  ]
Bringing up interface eth1:  RTNETLINK answers: File exists
                                                           [  OK  ]
FATAL: Module off not found.

至此yum update 一切正常。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章