歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> yum配置與使用

yum配置與使用

日期:2017/3/3 16:30:16   编辑:關於Linux

yum的配置一般有兩種方式,一種是直接配置/etc目錄下的yum.conf文件,另外一種是在/etc/yum.repos.d目錄下增加.repo文件。

一、yum的配置文件

$ cat /etc/yum.conf

復制代碼

[main]

cachedir=/var/cache/yum #yum下載的RPM包的緩存目錄

keepcache=0 #緩存是否保存,1保存,0不保存。

debuglevel=2 #調試級別(0-10),默認為2(具體調試級別的應用,我也不了解)。

logfile=/var/log/yum.log #yum的日志文件所在的位置

exactarch=1 #在更新的時候,是否允許更新不同版本的RPM包,比如是否在i386上更新i686的RPM包。

obsoletes=1 #這是一個update的參數,具體請參閱yum(8),簡單的說就是相當於upgrade,允許更新陳舊的RPM包。

gpgcheck=1 #是否檢查GPG(GNU Private Guard),一種密鑰方式簽名。

plugins=1 #是否允許使用插件,默認是0不允許,但是我們一般會用yum-fastestmirror這個插件。

installonly_limit=3 #允許保留多少個內核包。

exclude=selinux* #屏蔽不想更新的RPM包,可用通配符,多個RPM包之間使用空格分離。

# This is the default, if you make this bigger yum won't see if the metadata

# is newer on the remote and so you'll "gain" the bandwidth of not having to

# download the new metadata and "pay" for it by yum not having correct

# information.

# It is esp. important, to have correct metadata, for distributions like

# Fedora which don't keep old packages around. If you don't like this checking

# interupting your command line usage, it's much better to have something

# manually check the metadata once an hour (yum-updatesd will do this).

# metadata_expire=90m

# PUT YOUR REPOS HERE or IN separate files named file.repo

# in /etc/yum.repos.d

復制代碼

二、*.repo文件詳解

什麼是repo文件?

repo文件是Fedora中yum源(軟件倉庫)的配置文件,通常一個repo文件定義了一個或者多個軟件倉庫的細節內容,例如我們將從哪裡下載需要安裝或者升級的軟件包,repo文件中的設置內容將被yum讀取和應用!

我們以一份系統自帶的repo文件做為實例來探討(#號後面是我加的注釋):

[fedora] #方括號裡面的是軟件源的名稱,將被yum取得並識別

name=Fedora $releasever - $basearch #這裡也定義了軟件 倉庫的名稱,通常是為了方便閱讀配置文件,一般沒什麼作用,$releasever變量定義了發行版本,通常是8,9,10等數字,$basearch變 量定義了系統的架構,可以是i386、x86_64、ppc等值,這兩個變量根據當前系統的版本架構不同而有不同的取值,這可以方便yum升級的時候選擇 適合當前系統的軟件包,以下同……

failovermethod=priority #failovermethod 有兩個值可以選擇,priority是默認值,表示從列出的baseurl中順序選擇鏡像服務器地址,roundrobin表示在列出的服務器中隨機選擇

exclude=compiz* *compiz* fusion-icon* #exclude這個選項是後來我自己加上去的,用來禁止這個軟件倉庫中的某些軟件包的安裝和更新,可以使用通配符,並以空格分隔,可以視情況需要自行添加

#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/

#上面的一行baseurl第一個字符是'#'表示該行已經被注釋,將不會被讀取,這一行的意思是指定一個baseurl(源的鏡像服務器地址)

#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch

#上面的這一行是指定一個鏡像服務器的地址列表,通常是開啟的,本例中加了注釋符號禁用了,我們可以試試,將$releasever和$basearch替換成自己對應的版本和架構,例如10和i386,在浏覽器中打開,我們就能看到一長串鏡可用的鏡像服務器地址列表。

選擇自己訪問速度較快的鏡像服務器地址復制並粘貼到repo文件中,我們就能獲得較快的更新速度了,格式如下baseurl所示:

baseurl=

ftp://ftp.sfc.wide.ad.jp/pub/Linux/Fedora/releases/10/Everything/i386/os

http://ftp.chg.ru/pub/Linux/fedora/linux/releases/10/Everything/i386/os

http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/10/Everything/i386/os

http://mirror.nus.edu.sg/fedora/releases/10/Everything/i386/os

http://mirror.yandex.ru/fedora/linux/releases/10/Everything/i386/os

http://ftp.twaren.net/Linux/Fedora/linux/releases/10/Everything/i386/os

http://ftp.itu.edu.tr/Mirror/Fedora/linux/releases/10/Everything/i386/os

enabled=1 #這個選項表示這個repo中定義的源是啟用的,0為禁用

gpgcheck=1 #這個選項表示這個repo中下載的rpm將進行gpg的校驗,已確定rpm包的來源是有效和安全的

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch #定義用於校驗的gpg密鑰

##以下的軟件倉庫基本上用不到,選項含義同上

[fedora-debuginfo]

name=Fedora $releasever - $basearch - Debug

failovermethod=priority

#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/$basearch/debug/

mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-debug-$releasever&arch=$basearch

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

[fedora-source]

name=Fedora $releasever - Source

failovermethod=priority

#baseurl=http://download.fedoraproject.org/pub/fedora/linux/releases/$releasever/Everything/source/SRPMS/

mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-source-$releasever&arch=$basearch

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$basearch

另外,關於yum的選項可以man一下:

List of Commands:

復制代碼

check-update 檢查可提供的包升級

clean 刪除緩存數據

deplist 列出包依賴相關

erase 移除一個或多個包從你的系統

groupinfo 顯示關於包組的細節

groupinstall 從組裡安裝軟件包到你的系統

grouplist 列出當前的組

groupremove 在一個組中移除包從您的系統

help 顯示幫助用法信息

info 顯示關於包或一組包的細節信息

install 安裝一個或多個軟件包在你的系統

list 列出一個包或某組的包

localinstall 安裝本地 RPM

makecache 生成原數據緩存

provides Find what package provides the given value

reinstall 重新安裝一個包

repolist 顯示軟件倉庫的配置

resolvedep 決定哪個包提供了給定的依賴

search 查找包細節居給定的字符串

shell 運行交互式的yum shell

update 更新一個或多個包在你的系統

upgrade Update packages taking obsoletes into account

Options:

-h, --help show this help message and exit

-t, --tolerant be tolerant of errors

-C 從緩沖中運行,而不是升級緩存

-c [config file] config file location

-R [minutes] 最大化的命令等待時間

-d [debug level] 調試輸出級別

--showduplicates 顯示復制, 在repo,list/search命令下

-e [error level] 錯誤輸出級別

-q, --quiet 安靜的操作

-v, --verbose verbose operation

-y 回答所有的問題為是

--version 顯示 YUM版本信息並退出

--installroot=[path] 設置為root安裝

--enablerepo=[repo] 激活一個或多個倉庫(支持通配符)

--disablerepo=[repo] 禁掉一個或多個倉庫(支持通配符)

-x [package], --exclude=[package] 在名稱或glob不包含包。

--disableexcludes=[repo] disable exclude from main, for a repo or for everything

--obsoletes enable obsoletes processing during updates

--noplugins 禁掉yum插件

--nogpgcheck 禁掉GPG驗證檢查

--disableplugin=[plugin] 用名稱禁掉插件

--enableplugin=[plugin] enable plugins by name

--skip-broken 忽略包的依賴問題

--color=COLOR control whether color is used

wget http://mirrors.163.com/.help/CentOS-Base-163.repo

yum makecache

本文出自 “TNT、運維之路” 博客,請務必保留此出處http://tntdba.blog.51cto.com/1199791/985982

Copyright © Linux教程網 All Rights Reserved