解決RHEL 7 無法使用 RHEL repos

Richard Tsai
5 min readJan 7, 2019

--

自從RedHat 採取要收費的政策後, 要使用yum 去更新系統也無法使用了.

這個時候除了去註冊外, 另外的選擇就是使用CentOS 的repos 來更新系統.

步驟如下:

1. 移除原先的更新程式

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

2. 安裝CentOS 更新程式

wget http://mirror01.idc.hinet.net/CentOS/7/os/x86_64/Packages/yum-3.4.3-168.el7.centos.noarch.rpmwget http://mirror01.idc.hinet.net/CentOS/7/os/x86_64/Packages/python-iniparse-0.4-9.el7.noarch.rpmwget http://mirror01.idc.hinet.net/CentOS/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpmwget http://mirror01.idc.hinet.net/CentOS/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

3. 安裝相關RPM

rpm -ivh  yum-3.4.3-168.el7.centos.noarch.rpm python-iniparse-0.4-9.el7.noarch.rpm yum-metadata-parser-1.1.4-10.el7.x86_64.rpm yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch.rpm

4. 建立新的 repo file

這裡要注意, 檔名可以任意, 但一定要有 .repo 結尾

vim /etc/yum.repos.d/redhat.repo

內容如下, 這裡我使用 Hinet IDC 的 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
baseurl=http://mirror01.idc.hinet.net/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://mirror01.idc.hinet.net/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://mirror01.idc.hinet.net/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://mirror01.idc.hinet.net/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://mirror01.idc.hinet.net/CentOS/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

5. 完成後更新資料

yum clean all
yum update -y

2020/01/02 更新: 更新失效的rpm 位置及加入rpm 安裝方法

2021/08/09 更新: 更新失效的rpm 位置及加入rpm 安裝方法, 失效的原因為 版本更新, 也可以自行到以下連結早到正確版的RPM https://mirror01.idc.hinet.net/CentOS/7/os/x86_64/Packages/

--

--

Richard Tsai

人的大腦是用來思考, 解決問題, 不是拿來當記事本