linux cannot ping the Internet, yum cannot be used, yum local source, ifconfig no command, centos7 mount centos7

1. Problem description

  • I just got a CentOS7 virtual machine. Although I have root permission, I found ifconfig prompt: no command found. The first reaction is that I didn't install net tools, and then Yum install net tools. The following error is reported
Plug in loaded: fastestmirror
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

  • Through online search, most of them said that it was a network configuration problem. Then I checked the / etc / sysconfig / network scripts / ifcfg ensxxx file and found that the network card settings were OK
  • Then I tried the ping command and found that Ping is not available on the external network (of course, the internal network can be pinged)
  • It is found that there may be a problem with yum. Since Yum cannot ping the Internet, Yum will use the local Yum source (local Yum warehouse), and then look for the yum configuration file, which is generally located in / etc / yum repos. d/CentOS-Base. Repo this configuration file, open it and find that it is the same as the configuration file of another intranet server that can use Yum normally. Description is not a problem with the configuration file
  • So far, we can't find out where Yum is configured, so we forcibly copy another good server and Yum related files to the current problematic server. There are two folders to copy, one is: / etc / yum repos. d. The other is / var/cache/yum/x86_64.
  • There may be many problems. First, the server is not configured with a local yum source. Second, although there is a local yum warehouse, a configuration file does not point to the warehouse. At present, we can think of these two reasons.

2. Solutions

  • Because the problem cannot be accurately located, a more violent method is adopted: through CentOS-7-x86_64-Everything-2003.iso (the image file is a system wide file, including some yum sources, which can be understood as encapsulating various rpm packages and some built-in java) is mounted under the current lightweight CentOS server. The specific steps are as follows:

    • Download CentOS-7-x86_64-Everything-2003.iso image

    • Put the image in a directory of the currently problematic server. Now I put it in / home

    • Mount CentOS-7-x86_64-Everything-2003.iso: use the mount command mount -o loop /home/CentOS-7-x86_64-Everything-2003.iso /mnt/cdron, where / mnt/cdron means a directory (not a / mnt/cdron partition). If there is no cdron under / mnt, mkdir cdron the folder first. This directory is not fixed, but it is usually placed under / mnt.

    • After the mount is successful, you can see that ls /mnt/cdron has the corresponding file.

    • Copy all the files in / MNT / cdron / directory to / opt / yumcache, which is a newly created folder. In order to prevent the files in / MNT / cdron from being messy in / opt. cp -r /mnt/cdron/* /opt/yumCache.

    • Switch to / etc / yum.com repos. D / directory, and create a CentOS base folder (custom folder name), and add / etc / yum repos. D / all files are moved to CentOS base folder for backup.

    • At / etc / yum.com repos. D / directory VI / etc / yum repos. d/local-yum. Repo (to create and edit a local-yum.repo file), fill in the following:

    [base-local]
    name=CentOS-local   # Warehouse name
    baseurl=file:///mnt/cdron # mount address
    enabled=1 
    gpgcheck=1 
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
    
    
    • Clean cache: yum clean all. If prompted, directly rm -rf /var/cache/yum

    • Then yum makecache

    • Test with yum install vim. The problem is finally solved

  • The complete code commands are sorted in order below:

mkdir /mnt/cdron  # create folder
mount -o loop /home/CentOS-7-x86_64-Everything-2003.iso /mnt/cdron  # Mount image
ls /mnt/cdron  # Check whether the mount is successful
mkdir /opt/yumCache  # Create yumCache folder
cp -r /mnt/cdron/* /opt/yumCache/
cd /etc/yum.repos.d/  # Switch directory
mkdir centos-Base  # New folder
mv ./*.repo centos-Base/
vi /etc/yum.repos.d/local-yum.repo  # See above for details
yum clean all
yum makecache
yum install vim

3. Thinking

My solution above is to create my own yum local warehouse instead of mounting CentOS everything image. Personally, I feel that I can not mount CentOS everything image, but directly find a yum source image and mount it. For details, please refer to the blog https://blog.csdn.net/xys2333/article/details/83349501 I didn't try the blog method myself, but it can be used as an alternative. I can do it when I have time

Keywords: Linux

Added by boushley on Thu, 20 Jan 2022 17:02:07 +0200