CentOS Repository

Loading

同事跟我詢問究竟 Red Hat Enterprise Linux(RHEL)CentOS 的差別在哪裡!!我只知道他們很類似.

依據 CentOS 的官方說法.

What is CentOS?
CentOS is an Enterprise Linux distribution based on the freely available sources from Red Hat Enterprise Linux. Each CentOS version is supported for 7 years (by means of security updates). A new CentOS version is released every 2 years and each CentOS version is periodically updated (roughly every 6 months) to support newer hardware. This results in a secure, low-maintenance, reliable, predictable and reproducible Linux environment.

第一句話是重點 CentOS is an Enterprise Linux distribution based on the freely available sources from Red Hat Enterprise Linux.

CentOS 只包含了 RHEL 所有的開放原始碼的軟體,其他則不包括.所以基本上他們的核心版本一致,Open Source 的軟體也一致.

Repository

甚至於可以安裝 RHEL 但使用 CentOS 的 Repository,一般安裝好的 RHEL 需要到 Red Hat Subscription Management (以前稱為 RHN – Red Hat Network) 註冊後才能使用 RHEL 的 Repository.

[root@localhost ~]# yum update
Loaded plugins: product-id, refresh-packagekit, search-disabled-repos, security,
              : subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Update Process
No Packages marked for Update

Repository 最簡單的格式如下:

  • Repository ID
  • Name
  • Baseurl or mirrorlist
  • gpgkey
  • Enabled
  • gpgcheck

基本上定義以下這幾種 CentOS Repository 就足夠.
[base] – Base
[updates] – Released updates
[extras] – Additional packages that may be useful
[plus] – Packages used/produced in the build but not released

CentOS6 Repository

先停用 RHEL Repository 須將設定檔的 enabled 修改成為 0

[root@localhost ~]# vi /etc/yum.repos.d/rhel-source.repo
enabled=0

或是

[root@localhost ~]# vi /etc/yum/pluginconf.d/fastestmirror.conf
enabled=0

新增 任何名稱.repo (須以此結尾).

[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=os
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
enabled=1
gpgcheck=1

[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=updates
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
enabled=1
gpgcheck=1

[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=extras
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=1
enabled=1

[plus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=6&arch=$basearch&repo=centosplus
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
gpgcheck=1
enabled=1

因為 CentOS 官方停止維護( CentOS to CentOS Stream – https://benjr.tw/104230 ),需改 CentOS6 的 Yum 來源.

[base]
name=CentOS-6.10 - Base - vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/os/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6
 
#released updates 
[updates]
name=CentOS-6.10 - Updates - vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/updates/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6
 
#additional packages that may be useful
[extras]
name=CentOS-6.10 - Extras - vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/extras/$basearch/
gpgcheck=1
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-6.10 - Plus - vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-6.10 - Contrib - vault.centos.org
failovermethod=priority
baseurl=http://vault.centos.org/6.10/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://vault.centos.org/RPM-GPG-KEY-CentOS-6

還需要安裝 CentOS 的 GPG – GPG private signature 主要用意是檢查使用者下載的 RPM 檔是否遭到修改或已經毀壞.之後就可以使用 yum 了.

[root@localhost ~]# rpm --import http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6
[root@localhost ~]# yum update
Loaded plugins: fastestmirror, product-id, refresh-packagekit, search-disabled-repos, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Setting up Update Process
Loading mirror speeds from cached hostfile
 * base: ftp.tc.edu.tw
 * plus: ftp.tc.edu.tw
 * updates: ftp.tc.edu.tw
base                                                                                           | 3.7 kB     00:00     
base/primary_db                                                                                | 4.7 MB     00:12     
centos                                                                                         | 3.7 kB     00:00     
plus                                                                                           | 3.4 kB     00:00     
plus/primary_db                                                                                | 4.0 MB     00:09     
updates                                                                                        | 3.4 kB     00:00     
updates/primary_db                                                                             | 8.1 MB     00:30     
Resolving Dependencies
--> Running transaction check
...

CentOS7 Repository

新增 任何名稱.repo (須以此結尾).

[root@localhost ~]# vi /etc/yum.repos.d/centos.repo
[centos]
name=CentOS-7
baseurl=http://ftp.ksu.edu.tw/pub/CentOS/7.7.1908/isos/x86_64/
enabled=1
gpgcheck=1
gpgkey=http://ftp.ksu.edu.tw/pub/CentOS/7.7.1908/isos/x86_64/RPM-GPG-KEY-CentOS-7

就可以利用 CentOS 的 Repository 來安裝所需工具,不建議使用 #yum update ,有可能在更新核心後造成無法開機的情況.

[root@localhost ~]# yum repolist
[root@localhost ~]# yum install net-tools

常見問題:

mirrorlist 與 baseurl 有可能失效,建議可以先到 http://isoredirect.centos.org/centos/7/isos/x86_64/ 檢視,哪一的更新網站離你比較近.

沒有解決問題,試試搜尋本站其他內容

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

這個網站採用 Akismet 服務減少垃圾留言。進一步了解 Akismet 如何處理網站訪客的留言資料