【转】RHEL7更换yum源

redhat系统安装好尽管默认带有yum,但是redhat的更新包只对注册用户有效(收费)。所以需要更换yum源。

说明:我下载的是网易的rpm包,因为这些包在不断更新,所以可能失效。但是有方法可以解决,详见下文。
 参考:https://blog.csdn.net/hongbin_xu/article/details/79316614
以下rpm包在2018.5.26可用

基本的流程就是:

1.删除redhat7.0系统自带的yum软件包;
2.自行下载所需要的软件包;
3.根据依赖项安装;
4.新建repo配置文件。
一般来说,之后就可以正常使用了。可能还会遇到一些依赖项的问题,后面会提到。

流程
1、查看自带的yum软件包

[root@xhb yum.repos.d]# rpm -qa | grep yum

yum-utils-1.1.31-24.el7.noarch
yum-langpacks-0.4.2-3.el7.noarch
yum-metadata-parser-1.1.4-10.el7.x86_64
yum-rhn-plugin-2.0.1-4.el7.noarch
PackageKit-yum-0.8.9-11.el7.x86_64
yum-3.4.3-118.el7.noarch


这下面列出来的软件包,要记住一下,后面要根据其来搜索rpm包来安装新版本。比如”yum-utils”、”yum-langpacks”等等。

2、卸载这些安装包

rpm -qa | grep yum | xargs rpm -e --nodeps

3、保证上网正常

ping www.baidu.com

4、进入以下网站下载对应的rpm包

  • 阿里云网络源地址:https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/
  • 网易163网络源地址:http://mirrors.163.com/
  • CentOS网络源地址:http://centos.ustc.edu.cn/centos/

使用CTRL+F输入关键字查找对应的安装包即可。


5、找到安装包后下载下来
由于输出结果较多,故省略,下面是指令:

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-3.4.3-163.el7.centos.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-langpacks-0.4.2-7.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-rhn-plugin-2.0.1-10.el7.noarch.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-52.el7.noarch.rpm


6、安装

输入指令rpm -ivh yum-*,遇到报错,依赖项问题。

[root@linuxprobe home]# rpm -ivh yum-*

warning: yum-3.4.3-158.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
    python-urlgrabber >= 3.10-8 is needed by yum-3.4.3-158.el7.centos.noarch
    rpm >= 0:4.11.3-22 is needed by yum-3.4.3-158.el7.centos.noarch

另外再回去找安装包下载下来:

wget http://mirrors.163.com/centos/7/os/x86_64/Packages/rpm-4.11.3-32.el7.x86_64.rpm
wget http://mirrors.163.com/centos/7/os/x86_64/Packages/python-urlgrabber-3.10-8.el7.noarch.rpm

输入指令更新rpm:

rpm -Uvh rpm-4.11.3-32.el7.x86_64.rpm --nodeps
rpm -Uvh python-urlgrabber-3.10-8.el7.noarch.rpm --nodeps


再次运行rpm -ivh yum-*。

[root@linuxprobe home]# rpm -ivh yum-*

warning: yum-3.4.3-158.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-4################################# [ 50%]
   3:yum-3.4.3-158.el7.centos         ################################# [ 75%]
   4:yum-utils-1.1.31-45.el7          ################################# [100%]

我自己的这里报错了:

warning: yum-3.4.3-163.el7.centos.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
    yum-plugin-fastestmirror is needed by yum-3.4.3-163.el7.centos.noarch

解决:https://jingyan.baidu.com/article/f3e34a12c3cbe9f5eb6535da.html

rpm后添加两个文件执行:

[root@localhost rpm]# rpm -ivh yum-3.4.3-163.el7.centos.noarch.rpm yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm


7、新建repo配置文件

vim /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 - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=os
baseurl=http://mirrors.163.com/centos/7/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$7 - Updates - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=updates
baseurl=http://mirrors.163.com/centos/7/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$7 - Extras - 163.com
#mirrorlist=http://mirrorlist.centos.org/?release=$7&arch=$basearch&repo=extras
baseurl=http://mirrors.163.com/centos/7/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-$7 - Plus - 163.com
baseurl=http://mirrors.163.com/centos/7/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.163.com/centos/RPM-GPG-KEY-CentOS-7


8、测试yum是否配置成功

随便下一个软件看看:

[root@linuxprobe home]# yum -y install tree

Loaded plugins: fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Determining fastest mirrors
base                                                                 | 3.6 kB  00:00:00     
extras                                                               | 3.4 kB  00:00:00     
updates                                                              | 3.4 kB  00:00:00     
base/x86_64/group_gz           FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/29b154c359eaf12b9e35d0d5c649ebd62ce43333f39f02f33ed7b08c3b927e20-c7-x86_64-comps.xml.gz: [Errno 14] curl#6 - "Could not resolve host: mirrors.163.com; Unknown error"
Trying other mirror.
updates/x86_64/primary_db      FAILED                                          
http://mirrors.163.com/centos/7/updates/x86_64/repodata/d94a7500ce5b2da5a87ec4a88472b7d4668293b0aea3704dbbe23ef9819dbef0-primary.sqlite.bz2: [Errno 14] curl#6 - "Could not resolve host: mirrors.163.com; Unknown error"
Trying other mirror.
extras/x86_64/primary_db       FAILED                                          
http://mirrors.163.com/centos/7/extras/x86_64/repodata/e4b5b58cea2f141b821193fbe5b791fd8dec29014091f45b3101d08ae8eb1e1b-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:80; Connection refused"
Trying other mirror.
(1/4): extras/x86_64/primary_db                                      | 146 kB  00:00:00     
base/x86_64/primary_db         FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:80; Operation now in progress"
Trying other mirror.
base/x86_64/primary_db         FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.163.com:80; Operation now in progress"
Trying other mirror.
base/x86_64/primary_db         FAILED                                          
http://mirrors.163.com/centos/7/os/x86_64/repodata/03d0a660eb33174331aee3e077e11d4c017412d761b7f2eaa8555e7898e701e0-primary.sqlite.bz2: [Errno 14] curl#56 - "Recv failure: Connection reset by peer"
Trying other mirror.
(1/2): updates/x86_64/primary_db                                     | 2.0 MB  00:00:07     
(2/2): base/x86_64/primary_db                                        | 5.9 MB  00:00:14     
Resolving Dependencies
--> Running transaction check
---> Package tree.x86_64 0:1.6.0-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

============================================================================================
 Package           Arch                Version                      Repository         Size
============================================================================================
Installing:
 tree              x86_64              1.6.0-10.el7                 base               46 k

Transaction Summary
============================================================================================
Install  1 Package

Total download size: 46 k
Installed size: 87 k
Downloading packages:
warning: /var/cache/yum/x86_64/$releasever/base/packages/tree-1.6.0-10.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for tree-1.6.0-10.el7.x86_64.rpm is not installed
tree-1.6.0-10.el7.x86_64.rpm                                         |  46 kB  00:00:05     
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
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:
PackageKit-0.8.9-11.el7.x86_64 has missing requires of PackageKit-backend
rhn-check-2.0.2-5.el7.noarch has missing requires of yum-rhn-plugin >= ('0', '1.6.4', '1')
rpm-libs-4.11.1-16.el7.x86_64 has missing requires of rpm = ('0', '4.11.1', '16.el7')
rpm-python-4.11.1-16.el7.x86_64 has missing requires of rpm = ('0', '4.11.1', '16.el7')
  Installing : tree-1.6.0-10.el7.x86_64                                                 1/1 
  Verifying  : tree-1.6.0-10.el7.x86_64                                                 1/1 

Installed:
  tree.x86_64 0:1.6.0-10.el7                                                                

Complete!


第二种方法:

挂载安装文件ISO里面的yum源
参考:

  • https://www.jianshu.com/p/25a63cbf1e9d
  • https://www.cnblogs.com/kerrycode/p/4723637.html
  • https://blog.csdn.net/qq_37460356/article/details/79568387
     
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为了在RHEL6.8上搭建本地yum源服务器,你需要进行以下步骤: 1. 首先,安装"Development Tools"软件包,可以使用以下命令进行安装:yum groupinstall "Development Tools" 2. 接下来,我们需要更换yum源。首先,删除RHEL原有的yum源,可以使用命令:rpm -qa|grep yum|xargs rpm -e --nodeps 3. 然后,下载CentOS的yum安装包并进行安装,可以使用以下命令:yum install -y http://mirror.centos.org/centos/6/os/x86_64/Packages/yum-3.2.29-81.el6.centos.noarch.rpm 4. 创建本地yum源的配置文件。在/etc/yum.repos.d/目录下创建一个新的文件,比如rhel6server.repo,并在其中加入以下内容: [Server] name=rhel6server baseurl=file:///rhel6/Server enabled=1 gpgcheck=0 5. 最后,创建本地yum源的目录。在根目录下创建一个名为rhel6的文件夹,并在其中创建一个名为Server的子文件夹。 现在你已经成功搭建了RHEL6.8的本地yum源服务器。你可以使用yum命令来安装和更新软件包,它会从你的本地源中获取软件包。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [开发环境——基于RHEL 6.8开发环境的搭建](https://blog.csdn.net/weixin_33810006/article/details/92651442)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [RHEL6/redhat6通过安装光盘制作本地yum源](https://blog.csdn.net/sj349781478/article/details/126881729)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值