亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫
最近訪問板塊 發(fā)新帖
樓主: duanjigang
打印 上一主題 下一主題

Linux平臺(tái)軟件管理系統(tǒng)設(shè)計(jì)與規(guī)劃-中級(jí)篇(3)-深入理解和使用yum來管理RPM包 [復(fù)制鏈接]

論壇徽章:
0
11 [報(bào)告]
發(fā)表于 2013-01-03 12:25 |只看該作者
本帖最后由 duanjigang 于 2013-01-03 13:04 編輯

yum 本地 cache

之所以要把yum 的本地 cache 拿出來單獨(dú)說下,是因?yàn)檫@個(gè)要素不管在 yum 的執(zhí)行流程中,還是在 yum 的日常問題中都很重要。

首先看下本機(jī)的 repo 配置:

  1. # ls /etc/yum.repos.d/*
  2. /etc/yum.repos.d/newtest.repo  /etc/yum.repos.d/test.repo
  3. [root@yum yum]# cat /etc/yum.repos.d/*.repo
  4. [newtest]
  5. name=just a test reposity
  6. baseurl=http://yum.test.com:81/yum
  7. enabled=1
  8. gpgcheck=0
  9. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

  10. [test]
  11. name=just a test reposity
  12. baseurl=http://yum.test.com:81/yum
  13. enabled=1
  14. gpgcheck=0
  15. gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
復(fù)制代碼
我們能夠看到配置了兩個(gè) repo,其中一個(gè)名字為test, 另外一個(gè)為 newtest.

然后再看文件
/etc/yum.conf
中的配置

  1. cachedir=/var/cache/yum
復(fù)制代碼
設(shè)備本地的cache 目錄為
/var/cache/yum 目錄,首先我們清空下該目錄:

  1. # rm -fr /var/cache/yum/*
復(fù)制代碼
然后執(zhí)行命令

  1. #yum list
復(fù)制代碼
看下在 cache 目錄下能生成什么咚咚?

  1. # tree /var/cache/yum/
  2. /var/cache/yum/
  3. |-- newtest
  4. |   |-- cachecookie
  5. |   |-- headers
  6. |   |-- packages
  7. |   |-- primary.xml.gz
  8. |   |-- primary.xml.gz.sqlite
  9. |   `-- repomd.xml
  10. `-- test
  11.     |-- cachecookie
  12.     |-- headers
  13.     |-- packages
  14.     |-- primary.xml.gz
  15.     |-- primary.xml.gz.sqlite
  16.     `-- repomd.xml
復(fù)制代碼
能夠看到,客戶端的兩個(gè)repo 都對(duì)應(yīng)生成了 cache 目錄,每個(gè)cache 的目錄中都有文件 repomd.xml 和 primary.xml 文件或者其 Sqlite 文件。
為了驗(yàn)證下客戶端是否把服務(wù)器上的索引文件下載下來了,我們進(jìn)行對(duì)比:
在客戶端執(zhí)行:

  1. # md5sum repomd.xml
  2. 916b78131cab447e60b17bf01a41240a  repomd.xml
復(fù)制代碼
在服務(wù)器上執(zhí)行:
# md5sum /usr/local/cme/web/yum/repodata/repomd.xml
916b78131cab447e60b17bf01a41240a  /usr/local/cme/web/yum/repodata/repomd.xml
[/code]
可以看到兩者是一致的。驗(yàn)證了 yum 客戶端 cache 服務(wù)器索引到本地的實(shí)事。
另外還有兩個(gè)目錄 headers 和 packages, 可以參考源碼進(jìn)行功能分析。
在此處貌似要補(bǔ)充上 yum 是怎么利用本地 cache 進(jìn)行工作的,這貌似又成了 yum 的源碼分析了,目前這塊偶還未有閱讀到,后面有空再補(bǔ)充吧。

在上一節(jié)中我們只是就 primary.xml 文件進(jìn)行了內(nèi)容分析,這里,在客戶端 cache 中,我們花點(diǎn)時(shí)間看下 sqlite 文件,因?yàn)?yum 中對(duì) rpm 包的信息存儲(chǔ)數(shù)據(jù)庫時(shí)采用的
是文件數(shù)據(jù)庫 sqlite 存儲(chǔ)的。因此我們單獨(dú)拎出來說下.

yum 索引中的 sqlite 文件

以客戶端的 primary.xml.gz.sqlite 為例,用 sqlite3 直接打開 sqlite 文件進(jìn)行查看:

  1. # sqlite3 primary.xml.gz.sqlite
  2. sqlite> .table  
  3. conflicts  db_info    files      obsoletes  packages   provides   requires
  4. sqlite> .schema packages
  5. CREATE TABLE packages (  pkgKey INTEGER PRIMARY KEY,  pkgId TEXT,  name TEXT,  arch TEXT,  version TEXT,  epoch TEXT,  release TEXT,  summary TEXT,  description TEXT,  url TEXT,  time_file TEXT,  time_build TEXT,  rpm_license TEXT,  rpm_vendor TEXT,  rpm_group TEXT,  rpm_buildhost TEXT,  rpm_sourcerpm TEXT,  rpm_header_start TEXT,  rpm_header_end TEXT,  rpm_packager TEXT,  size_package TEXT,  size_installed TEXT,  size_archive TEXT,  location_href TEXT,  location_base TEXT,  checksum_type TEXT,  checksum_value TEXT);
  6. CREATE INDEX packageId ON packages (pkgId);
  7. CREATE INDEX packagename ON packages (name);
  8. CREATE TRIGGER removals AFTER DELETE ON packages  BEGIN    DELETE FROM files WHERE pkgKey = old.pkgKey;    DELETE FROM requires WHERE pkgKey = old.pkgKey;    DELETE FROM provides WHERE pkgKey = old.pkgKey;    DELETE FROM conflicts WHERE pkgKey = old.pkgKey;    DELETE FROM obsoletes WHERE pkgKey = old.pkgKey;  END;
復(fù)制代碼
通過 sqlite 的命令能看到 sqlite 中的所有表,每個(gè)文件是一個(gè)庫,這個(gè)庫中的所有 table 包含的信息,與 我們前面看到的 primary.xml 中的信息是一致的。
只不過采用了不同的存儲(chǔ)方式。
看下 package 表 中的數(shù)據(jù):

sqlite> select * from packages;
1|6a6fbc7e58160ffa71b1f91912dc6eaf1cd6e0ae|wget|i386|1.14|0|1|GNU wget|The GNU wget program downloads files from the Internet using the command-line.||1357187570|1357185960|GPL||Development/Tools|yum.test.com|wget-1.14-1.src.rpm|280|9282||809949|2032999|2039664|wget-1.14-1.i386.rpm||sha|6a6fbc7e58160ffa71b1f91912dc6eaf1cd6e0ae
2|a9f4ad3086dcfcced210361bc72e4d418144cfcc|test-daddy|i386|1.1|0|1|GNU test-daddy|The GNU wget program downloads files from the Internet using the command-line.||1357187570|1357185424|GPL||Development/Tools|yum.test.com|test-daddy-1.1-1.src.rpm|280|2127||4235|9354|4936|test-daddy-1.1-1.i386.rpm||sha|a9f4ad3086dcfcced210361bc72e4d418144cfcc
3|82828b38c988399f597cceb14d896de6d36cd1c8|test-girl|i386|1.1|0|1|GNU test-girl|The GNU wget program downloads files from the Internet using the command-line.||1357187570|1357185262|GPL||Development/Tools|yum.test.com|test-girl-1.1-1.src.rpm|280|2119||4227|9354|4936|test-girl-1.1-1.i386.rpm||sha|82828b38c988399f597cceb14d896de6d36cd1c8
4|6ce87802e577736bb8b481c157cb9fb8822f8b88|wget-debuginfo|i386|1.14|0|1|Debug information for package wget|This package provides debug information for package wget.
Debug information is useful when developing applications that use this
package or when debugging this package.||1357187570|1357185960|GPL||Development/Debug|yum.test.com|wget-1.14-1.src.rpm|280|2043||19714|45564|45836|wget-debuginfo-1.14-1.i386.rpm||sha|6ce87802e577736bb8b481c157cb9fb8822f8b88
5|f377c921e23ba10507de267b345d03d1f32f02a4|test-baby|i386|1.1|0|1|GNU test-baby|The GNU wget program downloads files from the Internet using the command-line.||1356570667|1356570667|GPL||Development/Tools|localhost.localdomain|test-baby-1.1-1.src.rpm|280|2290||4463|9395|5108|test-baby-1.1-1.i386.rpm||sha|f377c921e23ba10507de267b345d03d1f32f02a4
sqlite>


呵呵,看到的數(shù)據(jù)和 xml 文件中的展示的數(shù)據(jù)是一樣的。


論壇徽章:
0
12 [報(bào)告]
發(fā)表于 2013-01-03 13:05 |只看該作者
本帖最后由 duanjigang 于 2013-01-03 13:19 編輯

yum clean 分析
提到 yum 的客戶端 cache,又不得不對(duì)yum 中一個(gè)常用的針對(duì)cache 進(jìn)行操作的命令進(jìn)行分析,那就是: yum clean

看下 man 手冊(cè):

  1. clean  Is  used  to  clean  up  various things which accumulate in the yum cache directory over time.
  2.               More complete details can be found in the Clean Options section below.
復(fù)制代碼
看下命令行提示:

  1. # yum clean
  2. Error: clean requires an option: headers, packages, metadata, dbcache, plugins, all
復(fù)制代碼
看到它支持 clean 的對(duì)象有 headers,packages,metadata,dbcache 和 plugins 這幾項(xiàng)。
之前為了解決 yum 插件的clean 問題,簡(jiǎn)單分析了下 yum clean 的源碼,附上分析日志如下。

yum clean的源碼,在/usr/share/yum-cli/cli.py 中 882行

  1. def cleanCli(self, userlist):
復(fù)制代碼
函數(shù)中.
支持的參數(shù)有:

  1. yum clean:
  2. header
  3. packages
  4. metadata
  5. dbcache
  6. expire-cache
  7. plugins
復(fù)制代碼
針對(duì)不同的輸入,會(huì)調(diào)用

  1. self.cleanPackages()
  2. self.cleanHeaders()
  3. self.cleanMetadata()
  4. self.cleanSqlite()
復(fù)制代碼
這幾個(gè)函數(shù),刪除不同的項(xiàng)

然后我們?cè)谖募?div id="a9ur7n9vt" class="blockcode">

  1. /usr/lib/python2.4/site-packages/yum/__init__.py
復(fù)制代碼中能夠看到上面幾個(gè)函數(shù)的實(shí)現(xiàn):

  1. def cleanHeaders(self):
  2.         exts = ['hdr']
  3.         return self._cleanFiles(exts, 'hdrdir', 'header')

  4.     def cleanPackages(self):
  5.         exts = ['rpm']
  6.         return self._cleanFiles(exts, 'pkgdir', 'package')
復(fù)制代碼
等等。
這幾個(gè)clean函數(shù)都是通過封裝 __cleanFiles來實(shí)現(xiàn)的,看看這個(gè)函數(shù):

  1. def _cleanFiles(self, exts, pathattr, filetype):
  2.         filelist = []
  3.         removed = 0
  4.         for ext in exts:
  5.             for repo in self.repos.listEnabled():
  6.                 repo.dirSetup()
  7.                 path = getattr(repo, pathattr)
  8.                 if os.path.exists(path) and os.path.isdir(path):
  9.                     filelist = misc.getFileList(path, ext, filelist)

  10.         for item in filelist:
  11.             try:
  12.                 os.unlink(item)
  13.             except OSError, e:
  14.                 self.logger.critical(_('Cannot remove %s file %s'), filetype, item)
  15.                 continue
  16.             else:
  17.                 self.verbose_logger.log(logginglevels.DEBUG_4,
  18.                     _('%s file %s removed'), filetype, item)
  19.                 removed+=1
  20.         msg = _('%d %s files removed') % (removed, filetype)
  21.         return 0, [msg]
復(fù)制代碼
其實(shí)就是去對(duì)應(yīng)的目錄下刪除文件而已。

可以如下測(cè)試:
修改代碼段:

  1. for item in filelist:
  2.             try:
  3.                 print "====:", item
  4.                 os.unlink(item)
復(fù)制代碼
添加打印,保存
然后先 yum list 生成cache
可以 yum list 看下生成的文件

  1. tree
  2. .
  3. |-- ops.5.i386
  4. |   |-- cachecookie
  5. |   |-- packages
  6. |   |-- primary.sqlite
  7. |   `-- repomd.xml
  8. |-- ops.5.noarch
  9. |   |-- cachecookie
  10. |   |-- packages
  11. |   |-- primary.sqlite
  12. |   `-- repomd.xml
  13. `-- rhel.5.i386
  14.     |-- cachecookie
  15.     |-- packages
  16.     |-- primary.sqlite
  17.     `-- repomd.xml
  18. 然后 sudo yum clean all
  19. 輸出如下:
  20. ====: //var/cache/yum/ops.5.noarch/repomd.xml
  21. ====: //var/cache/yum/ops.5.i386/repomd.xml
  22. ====: //var/cache/yum/rhel.5.i386/repomd.xml
  23. ====: //var/cache/yum/ops.5.noarch/cachecookie
  24. ====: //var/cache/yum/ops.5.i386/cachecookie
  25. ====: //var/cache/yum/rhel.5.i386/cachecookie
  26. ====: //var/cache/yum/ops.5.noarch/primary.sqlite
  27. ====: //var/cache/yum/ops.5.i386/primary.sqlite
  28. ====: //var/cache/yum/rhel.5.i386/primary.sqlite
復(fù)制代碼
再去/var/cache/yum下tree下,看不到y(tǒng)um list 后的文件了

yum clean 是這樣實(shí)現(xiàn)的,我想,對(duì)于 install, update 和 list 等操作,如果你要分析源碼的話,可以借鑒 clean 的分析過程。

論壇徽章:
0
13 [報(bào)告]
發(fā)表于 2013-01-04 06:25 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 07:31 編輯

杭州好大雪~~繼續(xù)總結(jié)
yum 的 配置文件

yum 的 配置分為三類:

1 全局配置     /etc/yum.conf   -- 配置整個(gè) yum 服務(wù)的一些參數(shù)和options
2 repo 配置   /etc/yum.repos.d/*.repo 配置 yum 訪問時(shí)的repo源和路徑
3 插件配置   /etc/yum/pluginconf.d/*.conf 配置 yum 擴(kuò)展插件


下來依次解釋其內(nèi)容的含義:

/etc/yum.conf
先看下內(nèi)容"

  1. $ cat /etc/yum.conf
  2. [main]
  3. cachedir=/var/cache/yum
  4. keepcache=0
  5. debuglevel=2
  6. logfile=/var/log/yum.log
  7. distroverpkg=redhat-release
  8. tolerant=1
  9. exactarch=1
  10. obsoletes=1
  11. gpgcheck=1
  12. plugins=1
  13. metadata_expire=0

  14. # Default.
  15. # installonly_limit = 3

  16. # PUT YOUR REPOS HERE OR IN separate files named file.repo
  17. # in /etc/yum.repos.d
復(fù)制代碼
cachedir: 前面說過,本地存放cache 的目錄。
keepcache: 在成功安裝rpm后是否保留rpm和header文件,在前面介紹 cachdir 的例子中,我們看到cachedir 中的 header 和 packages 目錄是空的,現(xiàn)在打開keepcache

  1. keepcache=1
復(fù)制代碼
然后重新安裝 test-girl 和 test-daddy 包,之后再看下 cachedir 的內(nèi)容:

  1. # tree /var/cache/yum/
  2. /var/cache/yum/
  3. |-- newtest
  4. |   |-- cachecookie
  5. |   |-- headers
  6. |   |-- packages
  7. |   |-- primary.xml.gz
  8. |   |-- primary.xml.gz.sqlite
  9. |   `-- repomd.xml
  10. `-- test
  11.     |-- cachecookie
  12.     |-- headers
  13.     |   |-- test-daddy-1.1-1.i386.hdr
  14.     |   `-- test-girl-1.1-1.i386.hdr
  15.     |-- packages
  16.     |   |-- test-daddy-1.1-1.i386.rpm
  17.     |   `-- test-girl-1.1-1.i386.rpm
  18.     |-- primary.xml.gz
  19.     |-- primary.xml.gz.sqlite
  20.     `-- repomd.xml
復(fù)制代碼
看到了本地cache 的 hdr 和 rpm 文件了吧。

debuglevel: debug 信息輸出等級(jí),范圍為0-10,默認(rèn)是2
persistdir:  yum 持久化存儲(chǔ)數(shù)據(jù)的存儲(chǔ)目錄,默認(rèn)為 /var/lib/yum
reposdir: 我們都知道,yum的默認(rèn)repo 配置目錄是 /etc/yum.repos.d, 這個(gè)目錄可以通過配置文件中的行

  1. reposdir=dir1,dir2
復(fù)制代碼
來修改,這樣,yum 會(huì)加載這多個(gè)目錄下的*.repo 文件,在加載完這些之后,還要和 /etc/yum.conf 中的 repo 配置項(xiàng)合并,我們能夠看到 /etc/yum.conf 中最后一行有提示:
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d

也就是在告訴使用者:你直接把 *.repo 中的內(nèi)容寫在這里也好。這樣,yum.conf 中的repo 最終會(huì)和 reposdir 中配置的 repo 合并。
從個(gè)人喜好角度講:我更喜歡把*.repo分開,不同的應(yīng)用不同的repo,也方便各自修改,更新,如果都合并到一個(gè)文件 yum.conf 中,更新修改都是這個(gè)文件,涉及到多個(gè)程序修改repo時(shí),還得進(jìn)行互斥操作,比較麻煩。另外,看起來格式也比較亂。

errorlevel:和 Debuglevel 一樣,只不過是錯(cuò)誤信息輸出的配置等級(jí)。
logfile: yum 安裝的日志,
pkgpolicy:包安裝的策略,有兩個(gè)選項(xiàng),newest和last,如果你設(shè)置了多個(gè)repo,并且出現(xiàn)同一個(gè)軟件在不同的repos中同時(shí)存在的情況,yum 應(yīng)該安裝哪一個(gè),如果配置是 newest,則yum會(huì)安裝最新的那個(gè)版本。如果配置是 last,yum 則會(huì)將服務(wù)器 id 以字母表排序,并選擇最后的那個(gè)服務(wù)器上的軟件安裝。一般都是選 newest。
distroverpkg:指定一個(gè)軟件包,yum會(huì)根據(jù)這個(gè)包判斷你的發(fā)行版本,默認(rèn)是redhat-release,也可以是安裝的任何針對(duì)自己發(fā)行版的rpm包。我們?cè)?*.repo中經(jīng)常會(huì)這樣配置:

  1. baseurl=http://xxxx/redhat/$releasever/$basearch/
復(fù)制代碼
其中 $basearch 的值會(huì)為 i386 或者 x86_64,而 $releasever 的取值就是以 distroverpkg 的取值為名稱的rpm的版本號(hào),基本上取值都是 redhat-release
如果你看到你的系統(tǒng)上 redhat-release 的包為:

  1. $ rpm -qa redhat-release
  2. redhat-release-5Server-5.7.0.3
復(fù)制代碼
那么就能斷定 *.repo 中的  $releasever 為5.7了。很多人容易把這個(gè)值理解為獲取的是 /etc/redhat-release 這個(gè)文件中的內(nèi)容,其實(shí)不是,我之前的腳本也是獲取這個(gè)值的。這個(gè)設(shè)計(jì),貌似是個(gè)比較讓人詬病的點(diǎn),碰巧在水木社區(qū)看到一篇帖子,就是惡心這個(gè)設(shè)計(jì)的,轉(zhuǎn)過來跟大家分享下:

http://www.newsmth.net/nForum/#!article/LinuxApp/738396
發(fā)信人: JulyClyde (torred), 信區(qū): LinuxApp
標(biāo)  題: yum的$releasever真是太反動(dòng)了
發(fā)信站: 水木社區(qū) (Fri Oct  9 16:54:21 2009), 站內(nèi)
  
原創(chuàng);網(wǎng)址 http://www.julyclyde.org/?p=275
yum的$releasever真是太反動(dòng)了
  
來看這篇文章的人,大都應(yīng)該同意《Unix編程藝術(shù)》中提到的那些觀點(diǎn)吧。今天就給大家看一個(gè)反例:yum 的 $releasever 變量
  
在 /etc/yum.repos.d/ 目錄下的軟件庫定義文件中,常常會(huì)在 baseurl 的路徑中提到 $releasever 這個(gè)變量,表示當(dāng)前發(fā)行版的大版本號(hào),但大家知道這個(gè)變量是在哪設(shè)置的嗎?我 grep 了整個(gè) etc 目錄都沒找到,還是看了 yum.conf 才知道的,是在 yum.conf 文件里 distroverpkg 選項(xiàng)定義的。但這個(gè)選項(xiàng)就很有問題:
  
    1. distroverpkg 和 releasever 名字不同,且看不出什么聯(lián)系
    2. distroverpkg 的值,并不是明文,而是“redhat-release”。不知道大家看到這個(gè)會(huì)有什么想法,反正我是首先想到了 /etc/redhat-release 文件,但我錯(cuò)了。實(shí)際上指的是 redhat-release 這個(gè)RPM包。所謂“distroverpkg=redhat-release”的意思,其實(shí)是將 $releasever 設(shè)置為 redhat-release 這個(gè)RPM包的版本號(hào)
  
夠變態(tài)吧?別人都是直接賦值,或者 include 一個(gè)各種變量定義的文件進(jìn)來,而yum竟然用某個(gè)包的屬性作為值,違反了“everything is file”的原則。爛!
  
有人為心愛的 RedHat 分辯說是為了升級(jí) redhat-release 包之后可以自動(dòng)升級(jí)整個(gè)系統(tǒng),但事實(shí)證明 RedHat 的選擇一向都是很傻的。為什么不在軟件庫定義文件中 include 一個(gè)表示版本號(hào)的頭文件,每次大升級(jí)的時(shí)候更改這個(gè)文件呢?
  
再舉個(gè)例子:
  
Debian系里面,內(nèi)核包的版本維護(hù)是利用一個(gè)虛擬的 linux-image 包,依賴于某個(gè)風(fēng)格的比如 linux-image-generic 包,而該包又依賴于 linux-image-2.6.28-15-generic,后者就是真正的內(nèi)核包,其版本號(hào)直接寫在包名里。系統(tǒng)升級(jí)的時(shí)候,由于 linux-image 和 linux-image-generic 的依賴關(guān)系變動(dòng),會(huì)依賴于新的 linux-image-2.6.xx-yy-generic 包,自然會(huì)裝上。
  
反觀 RedHat 的做法:各個(gè)內(nèi)核包,只有若干個(gè) kernel-<flavor> 的包名,版本號(hào)作為 RPM 的屬性來實(shí)現(xiàn),但是內(nèi)核這么重大的包又不能輕易用新的代替舊的,于是再給 yum 新增一個(gè) instalonly 插件(注意不是install,而是少一個(gè)l字母)來抑制新 kernel 代替舊 kernel 的動(dòng)作。



exactarch:有兩個(gè)選項(xiàng)1和0,代表是否只升級(jí)和你安裝軟件包c(diǎn)pu體系一致的包,如果設(shè)為1,則如你安裝了一個(gè)i386的rpm,則yum不會(huì)用1686的包來升級(jí)。
retries: 網(wǎng)絡(luò)連接發(fā)生錯(cuò)誤后的重試次數(shù),如果設(shè)為0,則會(huì)無限重試。
tolerent: 也有1和0兩個(gè)選項(xiàng),表示yum是否容忍命令行發(fā)生與軟件包有關(guān)的錯(cuò)誤,比如你要安裝1,2,3三個(gè)包,而其中3此前已經(jīng)安裝了,如果你設(shè)為1,則yum不會(huì)出現(xiàn)錯(cuò)誤信息。默認(rèn)是0。
exclude: 排除某些軟件在升級(jí)名單之外,可以用通配符,列表中各個(gè)項(xiàng)目要用空格隔開。
gpgchkeck: 有1和0兩個(gè)選擇,分別代表是否是否進(jìn)行g(shù)pg校驗(yàn).
alwaysprompt: 安裝時(shí)是否提示,設(shè)置為1就會(huì)提示,需要你在 yum install 時(shí)輸入?yún)?shù) -y,比如

  1. yum install xxoo -y
復(fù)制代碼
如果設(shè)置為0,就不需要附件 -y 輸入了。
obsoletes: 默認(rèn)為1,是否用新的包替換舊的包,比如你在 制作 xxoo 包時(shí),spec 中已經(jīng)標(biāo)明會(huì) obsoletes  掉 ooxx包,別人如果直接
yum update/install ooxx
就會(huì)提示安裝 xxoo包,這個(gè)對(duì)于改名的軟件包非常有用。
timeout : 在http連接時(shí),等待超時(shí)的秒數(shù),如果你的網(wǎng)絡(luò)狀況不好,可以設(shè)置大點(diǎn),默認(rèn)為30,標(biāo)識(shí)超時(shí)為30秒。
另外還有一些比較實(shí)用的配置,比如限制安裝時(shí)帶寬使用的選項(xiàng): throttle  和 bandwith,這個(gè)問題思考好幾次了,終于找到這個(gè)配置了。
想要了解更多配置,可以去yum.conf 的文檔頁查閱:
http://linux.die.net/man/5/yum.conf
我們這里只列舉可一些常見的配置。

論壇徽章:
0
14 [報(bào)告]
發(fā)表于 2013-01-04 14:35 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 15:20 編輯

repo配置文件 /etc/yum.repos.d/*.repo

這個(gè)目錄地下的文件是使用 yum 最長(zhǎng)用到的配置文件。
我們看一個(gè)例子文件的內(nèi)容:

  1. #cat RHEL.repo
  2. [redhat.$releasever.base.$basearch]
  3. name=redhat
  4. baseurl=http://yum.test.com/redhat/$releasever/iso/$basearch/
  5. gpgcheck=0

  6. [redhat.$releasever.updates.$basearch]
  7. name=redhat updates
  8. baseurl=http://yum.test.com/redhat/$releasever/updates/$basearch/
  9. gpgcheck=0
復(fù)制代碼
可以看到,一個(gè)文件是由一個(gè)或者若干個(gè) reposity 組成的,每個(gè) reposity 保持了傳統(tǒng)的 ini 文件的定義格式。
每個(gè)reposity 至少包含以下信息:

  1. [repositoryid]
  2. name=Some name for this repository
  3. baseurl=url://path/to/repository/
復(fù)制代碼
reposityid 必須是一個(gè)唯一的單詞,也就是說是一個(gè)單詞,不能有空格隔開。
name:對(duì)這個(gè)repo的描述
baseurl 是訪問時(shí)的http地址模版,之所以叫模版,因?yàn)榻M成這個(gè) url 可以是一個(gè)實(shí)際的地址,也可以是變量組成的一個(gè)URL。
這里要注意一點(diǎn),baseurl 的域名都容易理解,是 yum 服務(wù)器的域名,然后后面的目錄路徑寫到什么地步呢?看下文檔原文:
baseurl Must be a URL to the directory where the yum repository's 'repodata' directory lives. Can be an http://, ftp:// or file:// URL
對(duì)了,baseurl 就是要寫到包含索引目錄(repodata)那一層目錄為止,這樣yum 才能根據(jù)既定的協(xié)議去這個(gè)路徑下找 repodata 目錄,找對(duì)應(yīng)的 repomd.xml 文件,否則會(huì)報(bào)錯(cuò)。
可以采用 http/ftp/file 協(xié)議進(jìn)行訪問。

也可以在一個(gè)baseurl 表達(dá)式中指定多個(gè)url,比如:

  1. [repositoryid]
  2. name=Some name for this repository
  3. baseurl=url://server1/path/to/repository/
  4. url://server2/path/to/repository/
  5. url://server3/path/to/repository/
復(fù)制代碼
如果有http認(rèn)證的話,可以寫上用戶名和密碼:

  1. baseurl=http://user:passwd@example.com/
復(fù)制代碼
mirrorlist  指向一個(gè)文件的 url 地址,這個(gè)文件中可以寫多個(gè) baseurl 來給yum 用,組成了一個(gè)mirror list.
enabled  1 或者 0,表示是否啟用。
gpgcheck 1 或者 0,表示對(duì)于從這個(gè)源下載的包是否啟用 gpg signature 校驗(yàn)。
gpgkey  gpgkey 的 URL 地址。

其它的選項(xiàng),可以參考文檔原文,我在此大概貼下:

gpgcakey A URL pointing to the ASCII-armored CA key file for the repository. This is a normal gpg public key - but this key will be used to validate detached signatures of all other keys. The idea is you are asked to confirm import for this key. After that any other gpg key needed for package or repository verification, if it has a detached signature which matches this key will be automatically imported without user confirmation.

exclude Same as the [main] exclude option but only for this repository. Substitution variables, described below, are honored here.

includepkgs Inverse of exclude. This is a list of packages you want to use from a repository. If this option lists only one package then that is all yum will ever see from the repository. Defaults to an empty list. Substitution variables, described below, are honored here.

enablegroups Either '0' or '1'. Determines whether yum will allow the use of package groups for this repository. Default is '1' (package groups are allowed).

failovermethod Either 'roundrobin' or 'priority'.

'roundrobin' randomly selects a URL out of the list of URLs to start with and proceeds through each of them as it encounters a failure contacting the host.

'priority' starts from the first baseurl listed and reads through them sequentially.

failovermethod defaults to 'roundrobin' if not specified.

keepalive Either '1' or '0'. This tells yum whether or not HTTP/1.1 keepalive should be used with this repository. See the global option in the [main] section above for more information.

timeout Overrides the timeout option from the [main] section for this repository.

http_caching Overrides the http_caching option from the [main] section for this repository.

retries Overrides the retries option from the [main] section for this repository.

throttle Overrides the throttle option from the [main] section for this repository.

bandwidth Overrides the bandwidth option from the [main] section for this repository.

sslcacert Overrides the sslcacert option from the [main] section for this repository.

sslverify Overrides the sslverify option from the [main] section for this repository.

sslclientcert Overrides the sslclientcert option from the [main] section for this repository.

sslclientkey Overrides the sslclientkey option from the [main] section for this repository.

metadata_expire Overrides the metadata_expire option from the [main] section for this repository.

mirrorlist_expire Overrides the mirrorlist_expire option from the [main] section for this repository.

proxy URL to the proxy server for this repository. Set to '_none_' to disable the global proxy setting for this repository. If this is unset it inherits it from the global setting

proxy_username username to use for proxy. If this is unset it inherits it from the global setting

proxy_password password for this proxy. If this is unset it inherits it from the global setting

username username to use for basic authentication to a repo or really any url. If this is unset it inherits it from the global setting

password password to use with the username for basic authentication. If this is unset it inherits it from the global setting

cost relative cost of accessing this repository. Useful for weighing one repo's packages as greater/less than any other. defaults to 1000

skip_if_unavailable If set to True yum will continue running if this repository cannot be contacted for any reason. This should be set carefully as all repos are consulted for any given command. Defaults to False


論壇徽章:
0
15 [報(bào)告]
發(fā)表于 2013-01-04 15:21 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 15:56 編輯

reposity 訪問的優(yōu)先級(jí)

有時(shí)候,我們會(huì)遇到同一個(gè)包在多個(gè) repo 中存在的情況。大多數(shù)情況都是,同一個(gè)包的不同版本分布在多個(gè)repo中,這時(shí)如果你采用

  1. yum install pkgname
復(fù)制代碼
的方式去安裝的話,因?yàn)?reposity 的默認(rèn)配置中 pkgpolicy 的機(jī)制為 newest, 因此,這樣會(huì)安裝最新版的包,大多數(shù)時(shí)候,問題就是這么產(chǎn)生的,好多人往往不明確自己需要軟件的版本,一個(gè) yum install 就給安裝到了最新版,最后才發(fā)現(xiàn)不是想要的版本,因此,建議安裝時(shí)最好能明確版本,這樣,即使同一個(gè)包在不同 repo 中,也會(huì)找對(duì)應(yīng)的版本去安裝,不至于出錯(cuò)。

另外一種情況是可能同版本的包也位于不同的repo中,按理說這種蛋疼的做法是不允許的,但是有時(shí)候我們還是希望關(guān)注下到底會(huì)安裝哪個(gè) repo 中的包,yum 為此提供了兩種機(jī)制:
cost 和 priorities 插件,其實(shí)這兩者的最終目的都是設(shè)置不同源的訪問優(yōu)先級(jí)。

我們?cè)诖酥徽f下 cost 的用法,priorities 插件留待后面介紹。

cost 的用法也很簡(jiǎn)單,就是配置一個(gè) cost = xxx, xxx 為權(quán)值,越小優(yōu)先級(jí)越高,默認(rèn)值是 1000,因此我們配置為1000以內(nèi)的都會(huì)比不配置的優(yōu)先級(jí)高。
看一個(gè)例子:
首先看下 yum 服務(wù)器上的配置,是一個(gè)典型的不規(guī)范yum源:

  1. ls *
  2. repo1:
  3. cmeguard-1.1.2-20.i386.rpm  repodata  test-cmeadmin-1.1.1-21.i386.rpm

  4. repo2:
  5. cmeguard-1.1.2-20.i386.rpm  repodata  test-cmeadmin-1.1.1-21.i386.rpm

  6. repo3:
  7. cmeguard-1.1.2-20.i386.rpm  repodata  test-cmeadmin-1.1.1-21.i386.rpm
復(fù)制代碼
有三個(gè)repo,其中都放置了相同的rpm包,而且同版本。

然后客戶端配置了三個(gè)repo文件:

  1. # ls /etc/yum.repos.d/
  2. yum0.repo  yum1.repo  yum2.repo
  3. cat /etc/yum.repos.d/yum0.repo
  4. [yum2]
  5. name=yum2
  6. baseurl=http://yum.test.com:81/yum/repo1
  7. enabled=1
  8. cost=100
  9. gpgcheck=0
  10. #cat /etc/yum.repos.d/yum1.repo
  11. [yum3]
  12. name=yum3
  13. baseurl=http://yum.test.com:81/yum/repo2
  14. enabled=1
  15. cost=103
  16. gpgcheck=0

  17. #cat /etc/yum.repos.d/yum2.repo
  18. [yum4]
  19. name=yum4
  20. baseurl=http://yum.test.com:81/yum/repo3
  21. enabled=1
  22. cost=105
  23. gpgcheck=0

復(fù)制代碼
三個(gè) repo 中 yum2 的 cost 最小,當(dāng)執(zhí)行

  1. yum install cmeguard
復(fù)制代碼
時(shí),提示如下:

  1. Dependencies Resolved

  2. =========================================================================================================================
  3. Package                      Arch                     Version                            Repository                Size
  4. =========================================================================================================================
  5. Installing:
  6. cmeguard                     i386                     1.1.2-20                        yum2                     9.6 M

  7. Transaction Summary
  8. =========================================================================================================================
  9. Install      1 Package(s)         
  10. Update       0 Package(s)         
  11. Remove       0 Package(s)
復(fù)制代碼
可以看到,是選擇了 yum2 中的包進(jìn)行安裝,驗(yàn)證了 cost 的作用。
以此為例,你可以修改多個(gè) repo的 cost 進(jìn)行優(yōu)先級(jí)的設(shè)置。 需要注意的一點(diǎn)是,repo 的優(yōu)先級(jí)跟 *.repo 的文件名稱無關(guān)。

論壇徽章:
0
16 [報(bào)告]
發(fā)表于 2013-01-04 16:23 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 16:44 編輯

repo 配置中的變量

有時(shí)候我們會(huì)看到這樣的 repo 配置:

  1. [redhat.$releasever.iso.$basearch]
  2. name=redhat
  3. baseurl=http://yum.test.com/redhat/$releasever/iso/$basearch/
  4. gpgcheck=0
復(fù)制代碼
這其中 reposityid,name,baseurl 中都可能用到了一系列變量,在實(shí)際執(zhí)行 yum 命令時(shí),這些變量會(huì)被賦值,然后按照實(shí)際的結(jié)果去執(zhí)行。
有時(shí),我們總想知道,這個(gè)變量到底是什么取值,在這段文字中,就針對(duì)這幾個(gè)變量進(jìn)行說明下.

  1.     $releasever This will be replaced with the value of the version of the package listed in distroverpkg. This defaults to the version of 'redhat-release' package.

  2.     $arch This will be replaced with your architecture as listed by os.uname()[4] in Python.

  3.     $basearch This will be replaced with your base architecture in yum. For example, if your $arch is i686 your $basearch will be i386.

  4.     $uuid This will be replaced with a unique but persistent uuid for this machine. The value that is first generated will be stored in /var/lib/yum/uuid and reused until this file is deleted.

  5.     $YUM0-$YUM9 These will be replaced with the value of the shell environment variable of the same name. If the shell environment variable does not exist then the configuration file variable will not be replaced.
復(fù)制代碼
簡(jiǎn)單翻譯下:

$releasever:就是yum.conf 中配置的distroverpkg的值對(duì)應(yīng)的rpm包的版本,這個(gè)奇葩配置,前面已經(jīng)說過了。
$arch,就是python代碼中

  1. os.uname()
復(fù)制代碼
的結(jié)果。
$basearch 對(duì)于64位架構(gòu)的機(jī)器就是x86_64, 32位架構(gòu)的就是i386.
$uuid 本機(jī)上產(chǎn)生的一個(gè)持久存儲(chǔ)的uuid值,唯一存在。
$YUM0-$YUM9 根據(jù)環(huán)境變量取值。
后面兩個(gè)變量基本上不會(huì)怎么用到。

最后,我們看幾個(gè)例子,在 我的一臺(tái)機(jī)器上, yum list 看到的輸出如下:

  1. xorg-x11-fonts-Type1.noarch                               7.1-2.1.el5                       redhat.5Server.iso.x86_64
復(fù)制代碼
這個(gè)就是前面的配置

  1. [redhat.$releasever.iso.$basearch]
復(fù)制代碼
展開后的值。

另外,需要注意的是,在4u機(jī)器上,reposityid 這一項(xiàng)中,變量貌似是不支持的。
比如,我在一臺(tái) 4u 的機(jī)器上看到如下輸出:

  1. xterm.i386                               192-8.el4_7.2          $releasever.$bas
復(fù)制代碼
在reposityid 這一項(xiàng),變量沒有被替換,但是在5u和6u的系統(tǒng)是沒問題的。

論壇徽章:
0
17 [報(bào)告]
發(fā)表于 2013-01-04 16:46 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 18:59 編輯

下面說下本篇的最后一個(gè)話題,也是比較有意思的一塊:
yum plugin (YUM 的插件)

使用 apach 和 nginx 的人都知道 apache 和 nginx 都具有在不同的調(diào)用點(diǎn)植入插件的功能,這些接口和 netfilter 的 五個(gè) hook 類似。

作為 redhat 系統(tǒng)的包管理命令- yum 也支持插件:一個(gè) python 腳本文件和一個(gè)配置文件,用來擴(kuò)展或者修改 yum 命令的行為,根據(jù)注冊(cè)函數(shù)的名稱來確定這些hook函數(shù)在何時(shí)調(diào)用。

增加 一個(gè) yum 插件需要完成兩件事情:一是開發(fā)對(duì)應(yīng)插件的 python 腳本,二是填寫對(duì)應(yīng)于該插件的配置文件。
插件的存儲(chǔ)默認(rèn)位置是:/usr/lib/yum-plugins/*.py
配置文件的存儲(chǔ)位置是:/etc/yum/pluginconf.d/*.conf

看下一個(gè) rhel 5.7 系統(tǒng)上的插件:

  1. $ ls /usr/lib/yum-plugins/*.py
  2. /usr/lib/yum-plugins/rhnplugin.py  /usr/lib/yum-plugins/subscription-manager.py
  3. /usr/lib/yum-plugins/product-id.py  /usr/lib/yum-plugins/security.py
  4. $ ls /etc/yum/pluginconf.d/
  5. product-id.conf  rhnplugin.conf  security.conf  subscription-manager.conf
復(fù)制代碼
我們都知道,一個(gè)數(shù)據(jù)包在主機(jī)上的網(wǎng)絡(luò)協(xié)議棧中被處理時(shí)會(huì)經(jīng)過很多點(diǎn),netfilter 提供了一種機(jī)制,可以在一些關(guān)鍵的點(diǎn),提供 hook 函數(shù)注冊(cè):用戶按照netfilter 模塊的的定義規(guī)范開發(fā)自己的代碼,編譯生成模塊文件 xx.ko,然后把這個(gè)模塊插入內(nèi)核,如果沒有什么異常的話,每一個(gè)經(jīng)過xxoo.ko注冊(cè)點(diǎn)的網(wǎng)絡(luò)報(bào)文都會(huì)被 xxoo.ko 的 hook 函數(shù)進(jìn)行處理;蛘逥ROP,或者ACCEPT, 或者STOLEN等等?傊,通過這些 hook 點(diǎn)能夠改變報(bào)文的最終目的地或者它在協(xié)議棧中的走向。

和 報(bào)文在協(xié)議棧中的處理一樣,當(dāng)你執(zhí)行一個(gè) yum 命令時(shí),比如安裝一個(gè)軟件包,這個(gè)事情也有很多關(guān)鍵點(diǎn),yum 的開發(fā)者在這些點(diǎn)也預(yù)留了一些外部可以注冊(cè)hook函數(shù)的接口,以方便使用者通過第三方插件的方式改變 yum 的行為和功能。yum 操作中 我們能夠想到的一些點(diǎn)有: yum 初始化,配置文件加載,repo加載,文件下載,安裝/卸載事務(wù)等等。
這對(duì)這些操作點(diǎn),yum 提供了以下幾個(gè) hook 點(diǎn)來方便用戶植入 hook 模塊,細(xì)說如下:

config
插件初始化以后的時(shí)刻,試圖去擴(kuò)展yum 的配置文件和命令行接口的 hook 可以放在這里


postconfig
yum的配置對(duì)象剛剛初始化以后的時(shí)刻,試圖修改或者擴(kuò)展 yum 中的變量的hook可以放在這里。yum-3.1.7 以后才支持該 hook點(diǎn)。

init
在yum 初始化的早起,可以進(jìn)行插件相關(guān)的初始化工作

predownload
包下載之前的時(shí)刻,想要獲取包信息的hook可以放在此處

postdownload
包下載之后的時(shí)刻,想要獲取下載包的錯(cuò)誤信息的hook可以放在此

prereposetup
在 yum 初始化 reposity 之前

postreposetup
在 yum 初始化 reposity 之后

exclude
在包的 inclusion 和 exclusion 處理完之后調(diào)用,想要改變 inclusion 和 exclusion 的 hook 放在此

preresolve
在包決定之前

postresolve
在包決定之后

pretrans
在 update trasanction 之前

posttrans
在 update transation 結(jié)束之后

close
在 yum 正常運(yùn)行結(jié)束之后

clean
在yum clean 之后調(diào)用 (4u的系統(tǒng)自帶yum不支持該hook)

論壇徽章:
0
18 [報(bào)告]
發(fā)表于 2013-01-04 19:02 |只看該作者
本帖最后由 duanjigang 于 2013-01-05 11:20 編輯

yum 的 hook 規(guī)范

隨便看一個(gè) 插件的代碼,能發(fā)現(xiàn)hook代碼的規(guī)范:

1): 如果要在 XX點(diǎn)注冊(cè)一個(gè)hook函數(shù),你的python 代碼中的函數(shù)名字應(yīng)該為

  1. XX_hook
復(fù)制代碼
2):每個(gè)hook 函數(shù)都會(huì)帶一個(gè)參數(shù) conduit
一個(gè) conduit 變量在不同的 hook/slot 點(diǎn)包含的數(shù)據(jù)是會(huì)變化的,類似于 netfilter 中的參數(shù) skbuff 一樣,在不同的hook點(diǎn),skbuff 中的指針,變量,或者有效,或者無效,這都要看它所處的位置(slot點(diǎn))。
不同的成員和方法在不同的 slot, 對(duì)于 conduit 也是會(huì)變得,這個(gè)可以參考 yum.plugins.SLOT_TO_CONDUIT這個(gè)字典,所有 condiut 子類的父類都是 PluginConduit


API依賴:

  在不同的yum版本中,支持的插件API和yum API都是會(huì)變化的。因此,為了防止出錯(cuò),并且使用到合適的API,需要在插件的代碼中指明版本號(hào)。當(dāng)前的API版本可以參考:yum.plugins.API_VERSION

插件類型:

目前支持兩種插件類型:

TYPE_CORE 和 TYPE_INTERACTIVE 兩種。

核心插件會(huì)修改yum的基礎(chǔ)功能,比如包排斥列表,依賴和 reposity 加載等。

交互式插件 可以修改yum的用戶界面,比如,交互式插件可以檢查一些錯(cuò)誤,然后退出yum,并且打印提示信息給用戶。

在yum2.6以及以前版本中,交互式插件定義為: TYPE_INTERFACE,不是很清晰,才進(jìn)行了更新。
看一下我寫的一個(gè)例子插件中注冊(cè)插件類型的代碼:

  1. requires_api_version = '2.4'
  2. if yum.plugins.API_VERSION < '2.3':
  3.     from yum.plugins import TYPE_INTERFACE
  4.     plugin_type = (TYPE_INTERFACE,)
  5. else:
  6.     from yum.plugins import TYPE_INTERACTIVE
  7.     plugin_type = (TYPE_INTERACTIVE,)
復(fù)制代碼
其它

可以在yum的任意調(diào)用點(diǎn),調(diào)用yum.plugins.PluginYumExit 來退出yum,并且打印你傳遞信息。

插件的配置文件都是INI格式存儲(chǔ)的,以下接口可以在插件的任何位置調(diào)用,來幫助你加載yum的配置信息(他們都是conduit中可以調(diào)用的):


  1. def confString(self, section, opt, default=None)

  2.     def confInt(self, section, opt, default=None)

  3.     def confFloat(self, section, opt, default=None)

  4.     def confBool(self, section, opt, default=None)
復(fù)制代碼
看名字,猜意思,很容易的。

yum-priorities 插件
yum-priorities 是一個(gè)標(biāo)準(zhǔn)的 yum 插件包,它的目的在于為不同的reposity 設(shè)置各自的優(yōu)先級(jí),優(yōu)先級(jí)在軟件升級(jí)或者安裝時(shí)決定訪問reposity 的順序。
優(yōu)先級(jí)低的repo 中的包不能升級(jí)優(yōu)先級(jí)高的 reposity 中的包所安裝的系統(tǒng)(針對(duì)于同一個(gè)包),同一個(gè)包,會(huì)先選擇優(yōu)先級(jí)較高的repo去選擇安裝。
安裝方法,直接

  1. yum install yum-priorities -y
復(fù)制代碼
即可。會(huì)安裝文件:

  1. /etc/yum/pluginconf.d/priorities.conf
  2. /usr/lib/yum-plugins/priorities.py
  3. /usr/lib/yum-plugins/priorities.pyc
  4. /usr/lib/yum-plugins/priorities.pyo
復(fù)制代碼
對(duì)于 priority 插件來說,每個(gè)repo 的默認(rèn)優(yōu)先級(jí)是99,可以配置的優(yōu)先級(jí)是1到99,你可以在repo的配置中添加一行來定義該repo的優(yōu)先級(jí),比如:

  1. [base]
  2. name=CentOS-$releasever - Base
  3. mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
  4. gpgcheck=1
  5. gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos4
  6. priority=1
復(fù)制代碼
優(yōu)先級(jí)取值越小,級(jí)別越高。
另外有一點(diǎn)要注意,因?yàn)閜ackage 之間可以存在 obsoletes(廢棄的意思)的關(guān)系,也就是說A包在spec 中指定了 obsoletes B 包,那么當(dāng)A和B都發(fā)布后,如果有人

  1. yum install/update B
復(fù)制代碼
包的時(shí)候,如果 /etc/yum.conf 中的 obsoletes 為 1,這時(shí)就會(huì)用A來替換B包,安裝A包。
即使 A 存在于優(yōu)先級(jí)較低的repo中而B存在于優(yōu)先級(jí)較高的repo中,這樣一來的話,priorities 的功能就和  obsoletes 沖突了。
obsoletes 允許更新,而 priorities 不允許更新,為了解決這個(gè)問題,給 priorities 插件引入了一個(gè)選項(xiàng) check_obsoletes
如果你如下配置的話:

  1. cat  /etc/yum/pluginconf.d/priorities.conf
  2. [main]
  3. enabled = 1
  4. check_obsoletes=1
復(fù)制代碼
obsoletes 就會(huì)被 priorities 插件禁掉。這樣互掐的功能,難免讓人覺得有些不爽。
因此,也會(huì)有如下的言論:
http://wiki.centos.org/PackageManagement/Yum/Priorities
Note: The upstream maintainer of yum, Seth Vidal, had the following to say about 'yum priorities' in September 2009:
Gosh, I hope people do not set up yum priorities. There are so many things about
priorities that make me cringe all over. It could just be that it reminds me of
apt 'pinning' and that makes me want to hurl.

論壇徽章:
0
19 [報(bào)告]
發(fā)表于 2013-01-04 19:13 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 19:18 編輯

yum 插件例子之一: 在所有 hook 點(diǎn)打印信息

如下是我寫的一個(gè) test 插件的例子,注意在5u7 或者更高版本 OS 上運(yùn)行。
配置如下:

  1. cat /etc/yum/pluginconf.d/test.conf
  2. [main]
  3. enabled=1
復(fù)制代碼
插件代碼如下,就是打印一行信息而已,只不過在所有slot/hook 點(diǎn)都進(jìn)行了注冊(cè):

  1. # cat /usr/lib/yum-plugins/test.py
  2. #!/usr/bin/python -tt
  3. from yum import config
  4. from yum.plugins import PluginYumExit
  5. import yum
  6. import yum.plugins
  7. import yum.config
  8. import rpmUtils.arch

  9. import locale
  10. locale.setlocale(locale.LC_ALL, '')


  11. requires_api_version = '2.4'
  12. if yum.plugins.API_VERSION < '2.3':
  13.     from yum.plugins import TYPE_INTERFACE
  14.     plugin_type = (TYPE_INTERFACE,)
  15. else:
  16.     from yum.plugins import TYPE_INTERACTIVE
  17.     plugin_type = (TYPE_INTERACTIVE,)

  18. def config_hook(conduit):
  19.         print "config_hook-----------------------------"
  20. def postconfig_hook(conduit):
  21.         print "postconfig_hook-----------------------------"

  22. def init_hook(conduit):
  23.         print "init_hook-----------------------------"
  24. def predownload_hook(conduit):
  25.         print "predownload_hook-----------------------------"
  26. def postdownload_hook(conduit):
  27.         print "postdownload_hook-----------------------------"
  28. def prereposetup_hook(conduit):
  29.         print "prereposetup_hook-----------------------------"
  30. def postreposetup_hook(conduit):
  31.         print "postreposetup_hook-----------------------------"
  32.     #raise PluginYumExit('Goodbye')

  33. def preresolve_hook(conduit):
  34.         print "preresolve_hook-----------------------------"
  35. def postresolve_hook(conduit):
  36.         print "postresolve_hook-----------------------------"

  37. def exclude_hook(conduit):
  38.         print "exclude_hook-----------------------------"
  39. def pretrans_hook(conduit):
  40.         print "pretrans_hook----------------------------"
  41. def posttrans_hook(conduit):
  42.         print "posttrans_hook----------------------------"
  43.        
  44. def close_hook(conduit):
  45.         print "close_hook-----------------------------"
  46. #It is  not supported on a rhel4 os
  47. def clean_hook(conduit):
  48.         print "clean_hook-----------------------------"
復(fù)制代碼
你可以通過:
yum list  search info update repolist clean remove install
等操作來檢查打印的信息,同時(shí)也幫助我們理解了 yum 的執(zhí)行流程,什么命令會(huì)進(jìn)行什么操作。

論壇徽章:
0
20 [報(bào)告]
發(fā)表于 2013-01-04 19:19 |只看該作者
本帖最后由 duanjigang 于 2013-01-04 19:31 編輯

yum 插件例子之二:downloadonly

該例子演示了 downloadonly 只下載rpm 而不安裝的功能,其中展示了 命令行參數(shù)擴(kuò)展功能,以及內(nèi)置函數(shù)調(diào)用的示例代碼,可以說是一個(gè)不錯(cuò)的例子:

  1. $ cat  /usr/lib/yum-plugins/test.py
  2. #!/usr/bin/python -tt
  3. from yum import config
  4. from yum.plugins import PluginYumExit
  5. import yum
  6. import yum.plugins
  7. import yum.config
  8. import rpmUtils.arch
  9. #print rpmUtils.arch.getBaseArch()
  10. #print rpmUtils.arch.getCanonArch()

  11. # Decent (UK.US English only) number formatting.
  12. import locale
  13. locale.setlocale(locale.LC_ALL, '')

  14. requires_api_version = '2.4'
  15. if yum.plugins.API_VERSION < '2.3':
  16.     from yum.plugins import TYPE_INTERFACE
  17.     plugin_type = (TYPE_INTERFACE,)
  18. else:
  19.     from yum.plugins import TYPE_INTERACTIVE
  20.     plugin_type = (TYPE_INTERACTIVE,)

  21. def config_hook(conduit):
  22.     parser = conduit.getOptParser()
  23.     parser.add_option('', '--downloadonly', dest='dlonly',
  24.       action='store_true', default=False,
  25.       help="don't update, just download,added by duanjigang")
  26.     # Add a boolean option to the [main] section
  27.     config.YumConf.enable_foo = config.BoolOption(False)

  28.     # Add a URL option to repository sections
  29.     config.RepoConf.foo_url = config.UrlOption()

  30.     # Add an option to to [main] and the repository sections. The
  31.     # repository options will inherit the properties of the [main] option
  32.     # and will use the value from [main] if the option is not specified in
  33.     # the repo section.
  34.     config.YumConf.max_foo = config.IntOption(10)
  35.     config.RepoConf.max_foo = config.Inherit(config.YumConf.max_foo)

  36. def init_hook(conduit):
  37.     conf = conduit.getConf()


  38.     # Display the options from the [main] section
  39.     conduit.info(2, "enable_foo = %r" % conf.enable_foo)
  40.     conduit.info(2, "max_foo = %r" % conf.max_foo)

  41.     # Display the options from the repository sections
  42.     for repo in conduit.getRepos().listEnabled():
  43.     #for repo in conduit.getRepos().listEnabled():
  44.         conduit.info(2, "%s.foo_url = %r" % (repo.id, repo.foo_url))
  45.         conduit.info(2, "%s.max_foo = %r" % (repo.id, repo.max_foo))

  46. def postdownload_hook(conduit):
  47.         opts, commands = conduit.getCmdLine()
  48.         if opts.dlonly:
  49.             raise PluginYumExit('exiting because --downloadonly specified--by duanjigang')
復(fù)制代碼
測(cè)試下其中的賦值和打印語句:

  1. $ yum info a | grep redhat
  2. redhat.5Server.iso.x86_64.foo_url = None
  3. redhat.5Server.iso.x86_64.max_foo = 10
  4. redhat.5Server.updates.x86_64.foo_url = None
  5. redhat.5Server.updates.x86_64.max_foo = 10
復(fù)制代碼
看一下命令行選項(xiàng):執(zhí)行
yum --help

后面有輸出一行:

  1. --downloadonly        don't update, just download,added by duanjigang
復(fù)制代碼
是我們?cè)黾拥拿钚袇?shù)。

最后我們測(cè)試下它的 downloadonly 功能:

  1. $ sudo yum install zsh --downloadonly -y
  2. =========================================================================================================================
  3. Package             Arch                   Version                     Repository                                  Size
  4. =========================================================================================================================
  5. Installing:
  6. zsh                 x86_64                 4.2.6-6.el5                 redhat.5Server.iso.x86_64                 1.8 M

  7. Transaction Summary
  8. =========================================================================================================================
  9. Install       1 Package(s)
  10. Upgrade       0 Package(s)

  11. Total size: 1.8 M
  12. Downloading Packages:


  13. exiting because --downloadonly specified--by duanjigang
復(fù)制代碼
驗(yàn)證下:

  1. $ rpm -qa zsh
  2. $ ls  -lat /var/cache/yum/redhat.5Server.iso.x86_64/packages/zsh-4.2.6-6.el5.x86_64.rpm
  3. -rw-r--r-- 1 root root 1835335 Apr  1  2012 /var/cache/yum/redhat.5Server.iso.x86_64/packages/zsh-4.2.6-6.el5.x86_64.rpm
復(fù)制代碼
我們能夠看到 包確實(shí)下載下來了,但是卻沒有安裝,正是我們期望的。

您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP