Linux(centOS)安装yum

  1. 查看是否有安装yum

rpm -qa | grep yum

红框内代表已安装的,如果为空代表未安装yum

  1. 删除yum下的所有组件

rpm -qa | grep yum | xargs rpm -e --nodeps
  1. 查看原有的yum配置,并且删除(删除红框内的文件)

whereis yum
  1. 获取yum安装包

安装包下载地址

  1. 安装yum

rpm -ivh --force --nodeps yum-cron-3.4.3-168.el7.centos.noarch.rpm
rpm -ivh --force --nodeps yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
rpm -ivh --force --nodeps yum-3.4.3-168.el7.centos.noarch.rpm
rpm -ivh --force --nodeps  yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm
  1. 查看yum是否安装成功使用 rpm -qa | grep yum,的如果有内容就代表安装成功

  1. 配置yum.repos.d

 cd /etc/yum.repos.d
mv CentOS-Base.repo CentOS-Base.repo_OLD
wget -nc http://mirrors.aliyun.com/repo/Centos-7.repo
mv Centos-7.repo CentOS-Base.rep

8、缓存yum包到本地

yum clean all
yum list
yum makecache

9、遇到的问题

  • 问题1:执行yum相关命令报错
Configuration file /etc/yum/pluginconf.d/update-motd.conf not found
Unable to find configuration file for plugin update-motd
Loaded plugins: fastestmirror
Repository '-repo': Error parsing config: Error parsing "baseurl = '-repo'": URL must be http, ftp, file or https not ""
Repository 'amzn2-core': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/$product/$target/x86_64/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2-core-source': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/$product/$target/SRPMS/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2-core-debuginfo': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/$product/$target/debuginfo/x86_64/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2extra-docker-source': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/extras/docker/latest/SRPMS/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2extra-docker-debuginfo': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/extras/docker/latest/debuginfo/x86_64/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2extra-docker': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/extras/docker/latest/x86_64/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2extra-kernel-5.10-source': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/extras/kernel-5.10/latest/SRPMS/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2extra-kernel-5.10-debuginfo': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/extras/kernel-5.10/latest/debuginfo/x86_64/mirror.list'": URL must be http, ftp, file or https not ""
Repository 'amzn2extra-kernel-5.10': Error parsing config: Error parsing "mirrorlist = '$awsproto://$amazonlinux.$awsregion.$awsdomain/7.5/extras/kernel-5.10/latest/x86_64/mirror.list'": URL must be http, ftp, file or https not ""
Cleaning repos: base docker-ce-stable docker.com_ epel extras updates
 

报错信息有两个问题要处理

1、根据第1行报错信息处理方案:在/etc/yum/pluginconf.d路径下新建update-motd.conf;

2、/etc/yum.repos.d 文件下删除跟报错相关的repos.d 文件

  • 问题2: 404 找不到相关镜像下载地址
 yum-config-manager --save --setopt=base.skip_if_unavailable=true
failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
http://mirrors.aliyun.com/centos/7.5/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
http://mirrors.aliyuncs.com/centos/7.5/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7.5/os/x86_64/repodata/repomd.xml: (28, "Failed to connect to mirrors.aliyuncs.com port 80 after 7206 ms: Couldn't connect to server")
http://mirrors.cloud.aliyuncs.com/centos/7.5/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com"
http://mirrors.aliyuncs.com/centos/7.5/os/x86_64/repodata/repomd.xml: [Errno 12] Timeout on http://mirrors.aliyuncs.com/centos/7.5/os/x86_64/repodata/repomd.xml: (28, "Failed to connect to mirrors.aliyuncs.com port 80 after 7164 ms: Couldn't connect to server")
Trying other mirror.
 One of the configured repositories failed (CentOS-7.5 - Base - mirrors.aliyun.com),
 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=base ...

     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 base
        or
            subscription-manager repos --disable=base

     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:

           

处理方法:在/etc/yum.repos.d 文件下的CentOS-Base.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-7 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/
        http://mirrors.aliyuncs.com/centos/7/os/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-7 - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/7/updates/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/7/extras/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/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-7 - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/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-7 - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/7/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/7/contrib/$basearch/
        http://mirrors.cloud.aliyuncs.com/centos/7/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值