说明

  • 以下环境无特别说明,均在 VMware® Workstation 17 Pro 17.5.2 build-23775571 虚拟机发生

centos7-mini

说明

  • 系统为 CentOS-7-x86_64-Minimal-2009.iso

基础环境

  • ifconfig: yum install net-tools

非 root 每次执行需要输入 sudo

  • 修改 /etc/sudoers,加入以下内容,god 是用户名 => root 用户改了,没生效,但是 god 用户改了,生效?

    1
    god     ALL=(ALL)       NOPASSWD: ALL

ip addr 无 ipv4 地址

  • 修改 /etc/sysconfig/network-scripts/ifcfg-ens33,将 ONBOOT NO 修改为 NOBOOT YES,重启虚拟机后,即有 ipv4 地址
  • 具体修改文件,以显示的网卡为准,不一定为 ifcfg-ens33
  • 参考 centos7的yum命令无法使用解决方法

无法使用 yum 安装

  • 报错如下

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    Loading mirror speeds from cached hostfile
    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; Unknown error"


    One of the configured repositories failed (Unknown),
    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
  • 修改 /etc/yum.repos.d/CentOS-Base.repo,配置为国内源(快捷替换为 aliyun 源: curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    [base]  
    name=CentOS-$releasever - Base
    baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
    http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #released updates
    [updates]
    name=CentOS-$releasever - Updates
    baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
    http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #additional packages that may be useful
    [extras]
    name=CentOS-$releasever - Extras
    baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
    http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #additional packages that extend functionality of existing packages
    [centosplus]
    name=CentOS-$releasever - Plus
    baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
    http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    #contrib - packages by Centos Users
    [contrib]
    name=CentOS-$releasever - Contrib
    baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
    http://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/contrib/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

    # 使用failovermethod指定优先级,这里设置为随机(roundrobin),也可以改为priority并指定每个URL的优先级
    failovermethod=roundrobin
  • 配置生效

    1
    2
    3
    yum clean all
    yum makecache
    yum update