yum源配置


我這里使用的centos7操作系統。 下載地址是:https://www.centos.org/download/

yum倉庫的創建可以參考: http://www.cnblogs.com/zhaojiedi1992/p/zhaojiedi_linux_037_yumrepo.html

yum源配置大致流程如下:

1 添加光盤

將安裝光盤(我用的是CentOS-7-x86_64-Everything-1511.iso), 添加到vmware的光盤項中去。如下圖

注意 :選擇了安裝包后,確保上面的那個設備狀態的2個復選框是勾選中的。

2 掛載光盤

執行下面命令

[root@localhost ~]# mkdir /mnt/cdrom               #創建一個目錄
[root@localhost ~]# mount -r /dev/cdrom /mnt/cdrom    #掛載光盤到指定的目錄
[root@localhost ~]# tail -n 1 /etc/mtab >>/etc/fstab   #掛載信息寫入到配置文件中去,開機自動掛載

3 添加repo文件

[root@localhost /] cd /etc/yum.repos.d/  #進入yum配置目錄
[root@localhost yum.repos.d]# ls      #查看目錄下已有的配置項
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo
CentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo
[root@localhost yum.repos.d]# mkdir backup  #創建一個備份目錄
[root@localhost yum.repos.d]# mv *.* backup  #當前目錄的文件移動到備份目錄中去
[root@localhost yum.repos.d]# ls        #查看當前目錄
backup
[root@localhost yum.repos.d]# cp backup/CentOS-Base.repo localcdrom.repo  #賦值一個repo文件到yum的配置目錄中
[root@localhost yum.repos.d]# ls
backup  localcdrom.repo
[root@localhost yum.repos.d]# vi localcdrom.repo   #編輯這個repo文件
[root@localhost yum.repos.d]# cat localcdrom.repo   #檢查repo的配置
[localcdrom]
name=localcdrom
baseurl=file:///mnt/cdrom/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

這里說一下repo文件的選項意義:

  • [localcdrom] : 這個是repo的識別號。必須是唯一的。不能有重復的
  • name:repo的名字: 中間可以有空格
  • baseurl: 這個是yum源的地址, ftp:// 是ftp協議, http://是http協議的, ftp://是ftp協議的, 這里配置的file:///mnt/cdrom/就是/mnt/cdrom這個目錄就是本地yum的配置地址。確保這個目錄有repodata目錄。
  • gpgcheck=1 :進行包檢測
  • gpgkey: 包檢測秘鑰路徑。支持http,ftp,file三種協議的
  • cost: 代價(默認是2000) 越小優先級越高。

4 清空yum和重新生成緩存

[root@localhost yum.repos.d]# yum clean all  #清空yum 緩存
Loaded plugins: fastestmirror, langpacks
Cleaning repos: localcdrom
Cleaning up everything
Cleaning up list of fastest mirrors
[root@localhost yum.repos.d]# yum makecache  #生成yum緩存
Loaded plugins: fastestmirror, langpacks
localcdrom                                                                                            | 3.6 kB  00:00:00     
(1/4): localcdrom/group_gz                                                                            | 155 kB  00:00:00     
(2/4): localcdrom/filelists_db                                                                        | 6.2 MB  00:00:00     
(3/4): localcdrom/primary_db                                                                          | 5.3 MB  00:00:00     
(4/4): localcdrom/other_db                                                                            | 2.3 MB  00:00:00     
Determining fastest mirrors
Metadata Cache Created

5 配置好了。 那就測試一下吧。

[root@localhost yum.repos.d]# yum install lftp    #這里測試一個ftp工具
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package lftp.x86_64 0:4.4.8-7.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
 Package                  Arch                       Version                            Repository                      Size
=============================================================================================================================
Installing:
 lftp                     x86_64                     4.4.8-7.el7                        localcdrom                     750 k

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

Total download size: 750 k
Installed size: 2.4 M
Is this ok [y/d/N]: y            #輸入y確認
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : lftp-4.4.8-7.el7.x86_64                                                                                   1/1 
  Verifying  : lftp-4.4.8-7.el7.x86_64                                                                                   1/1 

Installed:
  lftp.x86_64 0:4.4.8-7.el7                                                                                                  

Complete!

6 提供一些國內一些比較出名的一些yum源地址吧

阿里:http://mirrors.aliyun.com/

網易:http://mirrors.163.com/

搜狐:http://mirrors.sohu.com/

注意: aliyun上面是直接提供了repo文件下載的。我們可以直接下載ali官方提供的repo文件。 不用我們自己編寫的,這里我截了兩張aliyun的圖。

 

7 提供我本地的一個配置吧

/etc/yum.repos.d/cdrom.repo

[cdrom]
name=cdrom
baseurl=file:///mnt/cdrom
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

8 重要環境變量

  • $releasever : 紅帽的發布版本,如果是centos6的系統,這個變量就是6。
  • $basearch:系統架構,等價於uname -m,這個值x86_64,i686等這些數值。
  • $uuid:機器的唯一數值,這個參數一般不用的。
  • $YUM0 - $YUM9:這個是自定義的環境變量。

注意: 從3.2.28開始,/etc/yum/vars目錄下的的任何文件都將變成一個以文件名命名的變量,變量值為文件的內容,如果設置了,會覆蓋上面的設置的。如/etc/yum/vars/system的內容為abc,那么system變量的值就是abc。

9 官方的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 - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#released updates 
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
 
#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
        http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

這個repo樣例,主要有base,updates,extras,centosplus,contrib幾個片段, 每個片段都很基本,baseurl寫了2個,使用了$releasever,$basearch這些內置變量。

 10 epel源安裝

EPEL的全稱叫Extra Packages for Enterprise Linux 。EPEL是由 Fedora 社區打造,為 RHEL 及衍生發行版如 CentOS、Scientific Linux 等提供高質量軟件包的項目。裝上了 EPEL之后,就相當於添加了一個第三方源。

參考: http://mirrors.aliyun.com/help/epel

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM