作 者:陳永昇 精誠資訊 恆逸教育訓練中心資深講師
技術分類:網路管理與通訊應用 |
| |
Allen負責管理WhoLan Corp的數十台Red Hat Enterprise Linux。有時候Allen必須為某些新購買的機器安裝Red Hat Enterprise Linux,有時候他又得更新每一台Red Hat Enterprise Linux。安裝時,每次 Allen 就得拿出一堆Red Hat Enterprise Linux安裝光碟,隨著安裝程序手忙腳亂的換來換去,速度慢又沒有效率。每次當這些Red Hat Enterprise Linux更新時,還會造成許多對外的連線,耗用大量的頻寬,讓Allen頭痛不已。
為此,Allen詢問我是否有更棒的解決方案,可以讓一台Red Hat Enterprise Linux作為安裝伺服器與更新伺服器,節省安裝的時間,並下載更新套件後自動分享給其他Red Hat Enterprise Linux使用??
有。解決 Allen 問題的答案,就是 mrepo。 |
| |
| mrepo的介紹 |
| mrepo係提供給YUM/APT套件管理系統使用的輔助工具,其官方網站為 http://dag.wieers.com/home-made/mrepo/。只要是使用YUM或APT套件管理系統的Linux產品,皆可使用mrepo來建置安裝伺服器或更新伺服器。由於Red Hat Enterprise Linux 5 現今已經換用YUM來作為套件管理工具,因此Allen可以使用 mrepo建置安裝伺服器與更新伺服器。 |
| |
| 建構mrepo伺服器 |
| 首先,您必須先建置一個給mrepo使用的伺服器。mrepo伺服器上必須提供一個Apache HTTP Server的網站伺服器,並且需安裝mrepo套件。 |
| |
| 安裝mrepo套件 |
由於Red Hat Enterprise Linux系統並未內建mrepo套件,因此,您必須手動安裝之。您可以從mrepo的官方網站,下載最新版的mrepo(截至截稿為止,最新版本為 0.8.6) 並安裝之。
安裝mrepo時,您必須先確定是否已經安裝createrepo套件,如果尚未安裝,請先手動安裝起來。
如果您需要mrepo的RPM套件,筆者製作了一份,放在筆者的網站中。您可以從 http://www.cdchen.idv.tw/sites/www.cdchen.idv.tw/files/mrepo-0.8.6-1.noarch.rpm 取得: |
[root@linux ~]# rpm -ivh http://www.cdchen.idv.tw/sites/www.cdchen.idv.tw/files/mrepo-0.8.6-1.noarch.rpm
取回中 http://www.cdchen.idv.tw/sites/www.cdchen.idv.tw/files/mrepo-0.8.6-1.noarch.rpm
正在準備… ########################################### [100%]
1:mrepo ########################################### [100%]
[root@linux ~]# |
設定mrepo伺服器
安裝完成後,接著您必須產生mrepo的設定檔。mrepo的設定檔分為「主要設定檔」與「發行版本設定檔」兩種。 |
| |
| 主要設定檔 |
| 用來組態mrepo主要的參數,以及各發行版本設定檔的預設值。mrepo主要設定檔預設為 /etc/mrepo.conf。以下是我的 /etc/mrepo.conf: |
### Configuration file for mrepo
### The [main] section allows to override mrepo's default settings
### The mrepo-example.conf gives an overview of all the possible settings
[main]
srcdir = /var/mrepo
wwwdir = /var/www/mrepo
confdir = /etc/mrepo.conf.d
arch = i386
mailto = root@localhost
smtp-server = localhost
#rhnlogin = username:password
### Any other section is considered a definition for a distribution
### You can put distribution sections in /etc/mrepo.conf.d/
### Examples can be found in the documentation at:
### /usr/share/doc/mrepo-0.8.6/dists/. |
| |
| 發行版本設定檔 |
mrepo 的發行版本設定檔用來設定各發行版本 (Distribution) 套件之組態資料。所有發行版本設定檔必須儲存於/etc/mrepo.conf.d/目錄中,並且以.conf作為副檔名。
您可以從/usr/share/doc/mrepo-VERSION/dists/目錄中,取得發行版本設定檔的範本,編輯修改後,再存入/etc/mrepo.conf.d/目錄中。
以下是我的/etc/mrepo.conf.d/rhel5s.conf設定檔,提供給您參考: |
### Name: Red Hat Enterprise Server v5
### URL: http://www.redhat.com/
[rhel5s]
name = Red Hat Enterprise Server $release ($arch)
release = 5.3
arch = x86_64
metadata = repomd repoview
### ISO images
iso = rhel-server-$release-$arch-dvd.iso
### Additional repositories
updates = rhns:///rhel-$arch-server-5 |
| |
| 產生mrepo倉儲 |
完成設定檔後,接著您必須產生mrepo的倉儲 (Repositry)。mrepo倉儲其實也就是YUM的套件倉儲 (Package Repositry)。
以上述的rhel5s.conf為例,您必須先將iso參數指定的ISO檔案,儲存於/var/mrepo/iso/目錄中,然後執行 mrepo -ugvv: |
[root@linux ~]# mrepo -ugvv
Verbosity set to level 2
Using configfile /etc/mrepo.conf
Setting option confdir in section [main] to: /etc/mrepo.conf.d
Setting option srcdir in section [main] to: /var/mrepo
Setting option wwwdir in section [main] to: /var/www/mrepo
Setting option mailto in section [main] to: root@localhost
Setting option smtp-server in section [main] to: localhost
Setting option arch in section [main] to: i386
Setting option arch in section [rhel5s] to: x86_64
rhel5s-x86_64: Mount ISO rhel-server-5.3-x86_64-dvd.iso to /var/www/mrepo/rhel5s-x86_64/disc1
rhel5s-x86_64: Updating Red Hat Enterprise Server 5.3 (x86_64)
rhel5s-x86_64: Generating Red Hat Enterprise Server 5.3 (x86_64) meta-data
rhel5s-x86_64: Create repomd repository for os
1673/3093 - jakarta-commons-collections-testframework-javadoc-3.2-2jpp.3.x86_64.
3093/3093 - libvolume_id-devel-095-14.19.el5.x86_64.rpm
Saving Primary metadata
Saving file lists metadata
Saving other metadata
[root@linux ~]# |
此時mrepo便會開始下載更新的套件,並且重新建立mrepo倉儲資料檔。爾後若需要重新下載更新套件,與更新mrepo倉儲資料,只需執行一次mrepo -ugvv即可。
另外,偷偷告訴您,mrepo套件會提供一個 /etc/cron.d/mrepo,您只需取消其中的註解,Red Hat Enterprise Linux每一天就會重新執行mrepo -ugvv。
最後提醒您,如果您需要讓mrepo透過RHN下載更新的套件,您還必須將Red Hat Enterprise Linux 5 RHN的systemid(/etc/sysconfig/rhn/systemid) 複製到/var/mrepo/rhel5s-ARCH/目錄中。若需要其他版本,或更詳細的組態方法,請參閱:http://svn.rpmforge.net/svn/trunk/tools/mrepo/docs/redhat-network.txt。 |
| |
| 組態用戶端 |
| 建置完成 mrepo 伺服器後,您可以使用透過mrepo的倉儲,來進行安裝或更新系統。 |
| |
| 安裝用戶端 |
如果需安裝新的Red Hat Enterprise Linux,您只需在安裝Red Hat Enterprise Linux過程中,以 http://MREPOSERVER/mrepo/rhel5s-ARCH/disc1/作為安裝來源 (Installation Source),這個URL提供著Red Hat Enterprise Linux 安裝光碟的內容。
如果您需要取得Red Hat Enterprise Linux的ISO檔,其路徑則為http://MREPOSERVER/mrepo/rhel5s-ARCH/iso/。 |
| |
| 更新用戶端 |
| 如果打算讓Red Hat Enterprise Linux可以透過mrepo伺服器進行更新或安裝軟體,只需在這些Red Hat Enterprise Linux的/etc/yum.repos.d/目錄中,產生一個YUM的設定檔即可: |
[base]
name=WhoLan Corp Base $releasever - $basearch
failovermethod=priority
baseurl=http://MREPOSERVER/mrepo/rhel5s-x86_64/disc1/Server
arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[updates]
name=WhoLan Corp Base $releasever - $basearch
failovermethod=priority
baseurl=http://MREPOSERVER/mrepo/rhel5s-x86_64/RPMS.updates
arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release |
| 如此一來,作為mrepo用戶端的Red Hat Enterprise Linux便可利用yum指令,進行安裝或更新軟體的工作了。 |
| |
您可在課程中了解更多的Linux…
|
| 相關學習資源︰ |
|
 |