centos7 curl#6 - Could not resolve host mirrorlist.centos.org; 未知的错误 解决方案

问题描述

centos7系统安装完成后,yum安装软件时报错"curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误""

bash 复制代码
[root@192 ~]# yum install vim -y
已加载插件:fastestmirror
Determining fastest mirrors
Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: base/7/x86_64

解决方案

1)执行如下命令:

bash 复制代码
vi /etc/yum.repos.d/CentOS-Base.repo

2)修改如下:

bash 复制代码
# 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/
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/
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/
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/
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/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

3)配置成阿里云镜像

bash 复制代码
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

4)执行如下命令

bash 复制代码
yum repolist
yum clean all
yum makecache

Centos7安装gcc8

方法 1:使用 devtoolset安装 GCC 8(推荐)

1)安装 centos-release-scl

bash 复制代码
sudo yum install -y centos-release-scl

2)安装gcc 8

bash 复制代码
sudo yum install -y devtoolset-8

报错如下:

bash 复制代码
[root@192 yum.repos.d]# sudo yum install -y devtoolset-8
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
Could not retrieve mirrorlist http://mirrorlist.centos.org?arch=x86_64&release=7&repo=sclo-rh error was
14: curl#6 - "Could not resolve host: mirrorlist.centos.org; 未知的错误"


 One of the configured repositories failed (未知),
 and yum doesn't have enough cached data to continue. At this point the only
 safe thing yum can do is fail. There are a few ways to work "fix" this:

     1. Contact the upstream for the repository and get them to fix the problem.

     2. Reconfigure the baseurl/etc. for the repository, to point to a working
        upstream. This is most often useful if you are using a newer
        distribution release than is supported by the repository (and the
        packages for the previous distribution release still work).

     3. Run the command with the repository temporarily disabled
            yum --disablerepo=<repoid> ...

     4. Disable the repository permanently, so yum won't use it by default. Yum
        will then just ignore the repository until you permanently enable it
        again or use --enablerepo for temporary usage:

            yum-config-manager --disable <repoid>
        or
            subscription-manager repos --disable=<repoid>

     5. Configure the failing repository to be skipped, if it is unavailable.
        Note that yum will try to contact the repo. when it runs most commands,
        so will have to try and fail each time (and thus. yum will be be much
        slower). If it is a very temporary problem though, this is often a nice
        compromise:

            yum-config-manager --save --setopt=<repoid>.skip_if_unavailable=true

Cannot find a valid baseurl for repo: centos-sclo-rh/x86_64

解决方案:

修改CentOS-SCLo-scl.repo:

bash 复制代码
vi /etc/yum.repos.d/CentOS-SCLo-scl.repo

修改如下:

bash 复制代码
[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/sclo/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-sclo
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

修改CentOS-SCLo-scl-rh.repo:

bash 复制代码
vi /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

修改如下:

bash 复制代码
[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://mirrors.aliyun.com/centos/7/sclo/x86_64/rh/
# mirrorlist=http://mirrorlist.centos.org?arch=$basearch&release=7&repo=sclo-rh
gpgcheck=0
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-SIG-SCLo

执行如下命令:

bash 复制代码
yum repolist
yum clean all
yum makecache

3)重新执行命令

bash 复制代码
sudo yum install -y devtoolset-8

4)每次使用 GCC 8 时,需要运行:

bash 复制代码
scl enable devtoolset-8 bash

或者执行:

bash 复制代码
source /opt/rh/devtoolset-8/enable

5)如需永久启动gcc 8,执行如下命令:

bash 复制代码
echo "source /opt/rh/devtoolset-8/enable" >> ~/.bashrc
source ~/.bashrc

方法 2:使用 yum 直接安装 GCC 8(可能需要额外配置)

1)启用 EPELSCLo 仓库

bash 复制代码
sudo yum install -y epel-release
sudo yum install -y centos-release-scl

2)安装 GCC 8

bash 复制代码
sudo yum install -y gcc-toolset-8

3)启用 GCC 8

bash 复制代码
scl enable gcc-toolset-8 bash

4)检查 GCC 版本

bash 复制代码
gcc --version

方法 3:手动编译 GCC 8(适用于特殊需求)

1)安装依赖

bash 复制代码
sudo yum groupinstall -y "Development Tools"
sudo yum install -y gcc gcc-c++ make wget bzip2

2)下载 GCC 8 源码

bash 复制代码
wget http://ftp.gnu.org/gnu/gcc/gcc-8.5.0/gcc-8.5.0.tar.xz
tar -xf gcc-8.5.0.tar.xz
cd gcc-8.5.0

3)下载依赖库

bash 复制代码
./contrib/download_prerequisites

4)编译安装

bash 复制代码
mkdir build && cd build
../configure --enable-languages=c,c++ --disable-multilib
make -j$(nproc)
sudo make install

5)检查 GCC 版本

bash 复制代码
gcc --version
相关推荐
知远同学4 分钟前
docker学习笔记2-最佳实践
运维·docker·容器
哈哈幸运1 小时前
MySQL运维三部曲初级篇:从零开始打造稳定高效的数据库环境
linux·运维·数据库·mysql·性能优化
soulermax1 小时前
数字ic后端设计从入门到精通2(含fusion compiler, tcl教学)
java·linux·服务器
黑心老人1 小时前
Mac OS系统下kernel_task占用大量CPU资源导致系统卡顿
linux·运维·服务器·macos
光算科技2 小时前
服务器在国外国内用户访问慢会影响谷歌排名吗?
运维·服务器·c++
Zenexus2 小时前
Linux学习笔记协议篇(六):SPI FLASH设备驱动
linux·笔记·arm
口嗨农民工2 小时前
ubuntu18.04启动不了修复
linux·运维·ubuntu
YUELEI1182 小时前
Centos9 安装 nginx 及配置
nginx·centos
塔能物联运维2 小时前
双轮驱动能源革命:能源互联网与分布式能源赋能工厂能效跃迁
大数据·运维
辣个蓝人QEX3 小时前
【ZYNQ MP开发】Linux下使用bootgen命令生成BOOT.bin报错架构不对问题探究
linux·arm开发·xilinx·zynq·mpsoc·bootgen·u-boot移植