红帽系统配置yum源
一、删除系统自带yum包
执行rpm -qa|grep yum --已经安装的yum包
执行rpm -qa|grep yum|xargs rpm -e --nodeps 不检查依赖直接删除所有yum包。
再次执行rpm -qa|grep yum查看已经安装的yum包,没有内容表明删除成功。
rpm -qa|grep yum rpm -qa|grep yum|xargs rpm -e --nodeps rpm -qa|grep yum
二、下载新的yum包进行安装
镜像地址:http://mirrors.163.com/centos/
根据自己系统版本找到对应目录,下载如下几个软件包,这些包的版本会更新,所以出现ERROR 404: Not Found.的时候需要在前面的目录下找到最新的版本
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-54.el7_8.noarch.rpm wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-10.el7.noarch.rpm
rpm -ivh python-urlgrabber-3.10-10.el7.noarch.rpm --force --nodeps rpm -ivh python-iniparse-0.4-9.el7.noarch.rpm rpm -ivh yum-*
yum的包一起安装,解决相互依赖的问题
同时rpm的版本会有要求,报错如下:
[root@localhost snow]# rpm -ivh yum-* warning: yum-3.4.3-168.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY error: Failed dependencies: rpm >= 0:4.11.3-22 is needed by yum-3.4.3-168.el7.centos.noarch [root@localhost snow]#
需先下载最新代码在安装,升级代码如下:
[root@localhost snow]# wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-45.el7.x86_64.rpm [root@localhost snow]# rpm -Uvh rpm-4.11.3-45.el7.x86_64.rpm --nodeps
升级完成后重新安装yum相关,然后检查是否安装成功。执行rpm -qa | grep yum出现新安装的即代表安装成功。
[root@localhost snow]# rpm -ivh yum-* warning: yum-3.4.3-168.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Preparing... ################################# [100%] Updating / installing... 1:yum-metadata-parser-1.1.4-10.el7 ################################# [ 25%] 2:yum-plugin-fastestmirror-1.1.31-5################################# [ 50%] 3:yum-3.4.3-168.el7.centos ################################# [ 75%] 4:yum-utils-1.1.31-54.el7_8 ################################# [100%] [root@localhost snow]# rpm -qa | grep yum yum-utils-1.1.31-54.el7_8.noarch yum-metadata-parser-1.1.4-10.el7.x86_64 yum-3.4.3-168.el7.centos.noarch yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch [root@localhost snow]#
三、替换系统自带的repo文件。
1、在/etc目录下重命名备份原来的repo:mv yum.repos.d yum.repos.d.backup
[root@localhost ~]# cd /etc [root@localhost etc]# ls -l |grep yum drwxr-xr-x. 6 root root 95 Nov 30 17:38 yum -rw-r--r--. 1 root root 970 Oct 1 2020 yum.conf drwxr-xr-x. 2 root root 24 Oct 1 2020 yum.repos.d [root@localhost etc]# mv yum.repos.d/ yum.repos.d.backup [root@localhost etc]# ls -l |grep yum drwxr-xr-x. 6 root root 95 Nov 30 17:38 yum -rw-r--r--. 1 root root 970 Oct 1 2020 yum.conf drwxr-xr-x. 2 root root 24 Oct 1 2020 yum.repos.d.backup [root@localhost etc]#
2、建一个新的yum.repos.d目录(确保在/etc目录下)
[root@localhost etc]# mkdir yum.repos.d [root@localhost etc]# ls -l |grep yum drwxr-xr-x. 6 root root 95 Nov 30 17:38 yum -rw-r--r--. 1 root root 970 Oct 1 2020 yum.conf drwxr-xr-x. 2 root root 6 Nov 30 17:46 yum.repos.d drwxr-xr-x. 2 root root 24 Oct 1 2020 yum.repos.d.backup [root@localhost etc]#
3、下载一个CentOS的repo(我们可以在网易镜像站的centos使用帮助中下载学习)
官方帮助链接:https://mirrors.163.com/.help/centos.html
[root@localhost etc]# cd yum.repos.d
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo --2022-11-30 17:55:19-- http://mirrors.163.com/.help/CentOS7-Base-163.repo Resolving mirrors.163.com (mirrors.163.com)... 117.147.202.12 Connecting to mirrors.163.com (mirrors.163.com)|117.147.202.12|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1572 (1.5K) [application/octet-stream] Saving to: ‘CentOS7-Base-163.repo’ 100%[============================================================>] 1,572 --.-K/s in 0s 2022-11-30 17:55:19 (125 MB/s) - ‘CentOS7-Base-163.repo’ saved [1572/1572]
[root@localhost yum.repos.d]# ls -l
total 4
-rw-r--r--. 1 root root 1572 Nov 30 2016 CentOS7-Base-163.repo
4、通过vim打开并编辑repo,打开文件默认如下:
[root@localhost yum.repos.d]# vi CentOS7-Base-163.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 - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates] name=CentOS-$releasever - Updates - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-$releasever - Extras - 163.com #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-$releasever - Plus - 163.com baseurl=http://mirrors.163.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 [root@localhost yum.repos.d]#
将所有的$releasever全部替换成版本号-->7.9.2009:
shift+: 编辑 输入下面的指令
%s/$releasever/7.9.2009/g
具体版本可参看官网。https://mirrors.163.com/centos/
5、根据使用说明文档,我们要清除缓存与重新生产缓存。
yum clean all ##清理缓存
yum makecache ##重新生成缓存
[root@localhost yum.repos.d]# yum clean all Configuration file /etc/yum/pluginconf.d/product-id.conf not found Unable to find configuration file for plugin product-id Configuration file /etc/yum/pluginconf.d/search-disabled-repos.conf not found Unable to find configuration file for plugin search-disabled-repos Configuration file /etc/yum/pluginconf.d/subscription-manager.conf not found Unable to find configuration file for plugin subscription-manager Loaded plugins: fastestmirror Cleaning repos: base extras updates Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# yum makecache Configuration file /etc/yum/pluginconf.d/product-id.conf not found Unable to find configuration file for plugin product-id Configuration file /etc/yum/pluginconf.d/search-disabled-repos.conf not found Unable to find configuration file for plugin search-disabled-repos Configuration file /etc/yum/pluginconf.d/subscription-manager.conf not found Unable to find configuration file for plugin subscription-manager Loaded plugins: fastestmirror Determining fastest mirrors base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/10): base/x86_64/group_gz | 153 kB 00:00:01 (2/10): base/x86_64/filelists_db | 7.2 MB 00:00:04 (3/10): base/x86_64/primary_db | 6.1 MB 00:00:03 (4/10): extras/x86_64/primary_db | 249 kB 00:00:00 (5/10): extras/x86_64/filelists_db | 276 kB 00:00:00 (6/10): extras/x86_64/other_db | 149 kB 00:00:00 (7/10): base/x86_64/other_db | 2.6 MB 00:00:01 (8/10): updates/x86_64/filelists_db | 10 MB 00:00:03 (9/10): updates/x86_64/other_db | 1.2 MB 00:00:00 (10/10): updates/x86_64/primary_db | 18 MB 00:00:06 Metadata Cache Created [root@localhost yum.repos.d]#
6、使用yum repolist all查看是否成功
[root@localhost yum.repos.d]# yum repolist all Configuration file /etc/yum/pluginconf.d/product-id.conf not found Unable to find configuration file for plugin product-id Configuration file /etc/yum/pluginconf.d/search-disabled-repos.conf not found Unable to find configuration file for plugin search-disabled-repos Configuration file /etc/yum/pluginconf.d/subscription-manager.conf not found Unable to find configuration file for plugin subscription-manager Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile repo id repo name status base/x86_64 CentOS-7.9.2009 - Base - 163.com enabled: 10,072 centosplus/x86_64 CentOS-7.9.2009 - Plus - 163.com disabled extras/x86_64 CentOS-7.9.2009 - Extras - 163.com enabled: 515 updates/x86_64 CentOS-7.9.2009 - Updates - 163.com enabled: 4,385 repolist: 14,972 [root@localhost yum.repos.d]#
7、安装一个mysql试试, yum install mysql
[root@localhost yum.repos.d]# yum install mysql Configuration file /etc/yum/pluginconf.d/product-id.conf not found Unable to find configuration file for plugin product-id Configuration file /etc/yum/pluginconf.d/search-disabled-repos.conf not found Unable to find configuration file for plugin search-disabled-repos Configuration file /etc/yum/pluginconf.d/subscription-manager.conf not found Unable to find configuration file for plugin subscription-manager Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package mariadb.x86_64 1:5.5.68-1.el7 will be installed --> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.68-1.el7 for package: 1:mariadb-5.5.68-1.el7.x86_64 --> Running transaction check ---> Package mariadb-libs.x86_64 1:5.5.44-2.el7 will be updated ---> Package mariadb-libs.x86_64 1:5.5.68-1.el7 will be an update --> Finished Dependency Resolution Dependencies Resolved ====================================================================================================== Package Arch Version Repository Size ====================================================================================================== Installing: mariadb x86_64 1:5.5.68-1.el7 base 8.8 M Updating for dependencies: mariadb-libs x86_64 1:5.5.68-1.el7 base 760 k Transaction Summary ====================================================================================================== Install 1 Package Upgrade ( 1 Dependent package) Total download size: 9.5 M Is this ok [y/d/N]: y Downloading packages: Delta RPMs disabled because /usr/bin/applydeltarpm not installed. warning: /var/cache/yum/x86_64/$releasever/base/packages/mariadb-libs-5.5.68-1.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY Public key for mariadb-libs-5.5.68-1.el7.x86_64.rpm is not installed (1/2): mariadb-libs-5.5.68-1.el7.x86_64.rpm | 760 kB 00:00:00 (2/2): mariadb-5.5.68-1.el7.x86_64.rpm | 8.8 MB 00:00:01 ------------------------------------------------------------------------------------------------------ Total 5.0 MB/s | 9.5 MB 00:00:01 Retrieving key from http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 Importing GPG key 0xF4A80EB5: Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>" Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5 From : http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7 Is this ok [y/N]: y Running transaction check Running transaction test Transaction test succeeded Running transaction Warning: RPMDB altered outside of yum. ** Found 4 pre-existing rpmdb problem(s), 'yum check' output follows: python-urlgrabber-3.10-10.el7.noarch is a duplicate with python-urlgrabber-3.10-7.el7.noarch rhn-check-2.0.2-6.el7.noarch has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1') rpm-libs-4.11.3-17.el7.x86_64 has missing requires of rpm = ('0', '4.11.3', '17.el7') rpm-python-4.11.3-17.el7.x86_64 has missing requires of rpm = ('0', '4.11.3', '17.el7') Updating : 1:mariadb-libs-5.5.68-1.el7.x86_64 1/3 Installing : 1:mariadb-5.5.68-1.el7.x86_64 2/3 Cleanup : 1:mariadb-libs-5.5.44-2.el7.x86_64 3/3 Verifying : 1:mariadb-libs-5.5.68-1.el7.x86_64 1/3 Verifying : 1:mariadb-5.5.68-1.el7.x86_64 2/3 Verifying : 1:mariadb-libs-5.5.44-2.el7.x86_64 3/3 Installed: mariadb.x86_64 1:5.5.68-1.el7 Dependency Updated: mariadb-libs.x86_64 1:5.5.68-1.el7 Complete! [root@localhost yum.repos.d]#