搭建YUM庫

1、yum基本概念

yum是Yellow dogUpdater Modified的簡稱,起初是由yellow dog這一發行版的開發者Terra Soft研發,用python寫成,那時還叫做yup(yellow dog updater),後經杜克大學的Linux@Duke開發團隊進行改進,遂有此名。yum的宗旨是自動化地升級,安裝/移除rpm包,收集rpm包的相關信息,檢查依賴性並自動提示用戶解決。yum的關鍵之處是要有可靠的repository,顧名思義,這是軟件的倉庫,它可以是http或ftp站點,也可以是本地軟件池,但必須包含rpm的header, header包括了rpm包的各種信息,包括描述,功能,提供的文件,依賴性等.正是收集了這些 header並加以分析,才能自動化地完成餘下的任務。

repository 是用 yum-arch 或者 createrepo命令創建的,也可以用別人已有的 repository 作爲鏡像。

Yum 有以下特點:

1)        *可以同時配置多個資源庫(Repository)

2)        *簡潔的配置文件(/etc/yum.conf)

3)        *自動解決增加或刪除rpm包時遇到的倚賴性問題

4)        *使用方便

5)        *保持與RPM數據庫的一致性

YUM的基本工作流程如下:

         服務器端:在服務器上面存放了所有的RPM軟件包,然後以相關的功能去分析每個RPM文件的依賴性關係,將這些數據記錄成文件存放在服務器的某特定目錄內。

         客戶端:如果需要安裝某個軟件時,先下載服務器上面記錄的依賴性關係文件(可通過WWW或FTP方式),通過對服務器端下載的紀錄數據進行分析,然後取得所有相關的軟件,一次全部下載下來進行安裝。

2、yum 軟件包安裝

2.1 Yum包確認

[oracle@xml-ora1 ~]$ rpm -q rpm

rpm-4.4.2.3-18.el5

         用rpm –q 查詢軟件包是否已經安裝,如果沒有安裝則需要先下載或者使用光盤裏的rmp包進行安裝

2.2 Yum包下載安裝

可以用wget 直接從http://yum.baseurl.org/download/網上下載,或者光盤自帶的rpm包來進行安裝。

3、yum操作配置說明

3.1 yum基本操作指令

yum 的基本操作包括軟件的安裝(本地,網絡),升級(本地,網絡),卸載,另外還有一定的查詢功能。設定好了本地的yum之後,就可以很方便的進行安裝。

[oracle@xml-ora1 ~]$ yum --help

usage: yum [options] COMMAND

List of Commands:

check-update   Check for available package updates(列出所有可更新的軟件清單)

clean          Remove cached data(清除yum緩存)

deplist        List a package's dependencies(列出指定軟件包所有依賴的軟件清單)

downgrade      downgrade a package

erase          Remove a package or packages fromyour system(刪除指定已安裝的軟件包)

groupinfo      Display details about a package group(列出組件包含的軟件清單)

groupinstall   Install the packages in a group on yoursystem(安裝組件)

grouplist      List available package groups(列出所有可安裝的組件清單)

groupremove    Remove the packages in a group from yoursystem(清除組件)

help           Display a helpful usage message(列出yum所有指令說明)

info           Display details about a package orgroup of packages(獲取所有或者指定包的詳細信息)

info-security  Returns security data for the packageslisted, that affects your system

install        Install a package or packages on yoursystem(僅安裝所有或者指定的軟件)

list           List a package or groups of packages(列出所有或者指定的軟件清單)

list-security   Returnssecurity data for the packages listed, that affects your system

localinstall    Installa local RPM(本地安裝rpm軟件包)

makecache     Generate the metadata cache(生成數據緩存)

provides       Find what package provides the givenvalue(列出軟件包提供哪些文件)

reinstall       reinstalla package(重新安裝指定軟件包)

repolist       Display the configured softwarerepositories(顯示軟件倉庫的配置)

resolvedep     Determine which package provides the givendependency(哪個包提供依賴)

search         Search package details for the givenstring(根據關鍵字模糊查找軟件包)

shell          Run an interactive yum shell(運行交互式的yum shell

update         Update a package or packages on yoursystem(安裝所有或所有可更新軟件)

update-minimal    Works like update, but goes to the 'newest'package match which fixes a problem that affects your system

upgrade        Update packages taking obsoletes intoaccount(大規模的版本升級,yum update不同的是,連舊的淘汰的包也升級)

remove                 Remove a package or packages on your system (刪除指定已安裝的軟件)

 

options:

  -h,--help          show this help messageand exit

  -t,--tolerant        be tolerant of errors (遇到錯誤繼續運行yum

 -C                run entirelyfrom cache, don't update cache(完全從緩衝區的程序包運行yum,緩衝區默認爲/var/yum/cache

 -c  [config file]     config file location(使用不同默認/etc/yum.conf之外的配置文件)

 -R  [minutes]       maximum command wait time(設置以分鐘計算的等待時間)

 -d  [debug level]    debugging output level(代替/etc/yum.conf中的調試級別)

 --showduplicates     showduplicates, in repos, in list/search commands

 -e  [error level]     error output level(設置錯誤消息的級別。配置腳本級別設置爲0)

  -q,--quiet           quiet operation(靜默安裝,不提示信息)

  -v,--verbose         verbose operation(查看rpm版本)

 -y                  answer yes forall questions(設置自動回答選項爲y)

 --version            show Yumversion and exit(顯示 YUM版本信息並退出)

 --installroot=[path]    set install root(設置爲root安裝)

--enablerepo=[repo]  enableone or more repositories (wildcards allowed)(啓用軟件倉庫)

 --disablerepo=[repo]  disable oneor more repositories (wildcards allowed)(禁用軟件倉庫)

  -x[package], --exclude=[package]   excludepackage(s) by name or glob

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

 --obsoletes           enableobsoletes processing during updates

 --noplugins           disable Yumplugins(禁掉yum插件)

 --nogpgcheck          disable gpgsignature checking(禁掉GPG驗證檢查)

 --disableplugin=[plugin]  disableplugins by name 用名稱禁掉插件)

 --enableplugin=[plugin]   enableplugins by name 用名稱啓用插件)

 --skip-broken         skippackages with depsolving problems 忽略包的依賴問題)

 --color=COLOR         controlwhether color is used(設置是否啓用顏色)

 --security            Includesecurity relevant packages

 --cve=CVE             Includepackages needed to fix the given CVE

 --bz=BZ               Includepackages needed to fix the given BZ

 --advisory=ADVISORY   Includepackages needed to fix the given advisory

 Plugin Options:

 

yum list的特殊用法:

列出所有可更新的軟件清單

命令:yum list updates

列出所有已安裝的軟件包

命令:yum list installed

列出已安裝但不在資源庫的軟件包

命令:yum list extras

 

yum info 特殊用法:

列出所有軟件包的信息

命令:yum info

列出所有可更新的軟件包信息

命令:yum info updates

列出所有已安裝的軟件包信息

命令:yum info installed

列出所有已安裝但不在YumRepository內的軟件包信息

命令:yum info extras

 

清除YUM緩存特殊用法:

yum 會把下載的軟件包和header存儲在cache中,而不會自動刪除。如果我們覺得它們佔用了磁盤空間,可以使用yum clean指令進行清除,更精確的用法是yum clean headers清除header,yum clean packages清除下載的rpm包。

清除緩存目錄(/var/cache/yum)下的軟件包

命令:yum clean packages

清除緩存目錄(/var/cache/yum)下的headers

命令:yum clean headers

清除緩存目錄(/var/cache/yum)下舊的headers

命令:yum clean oldheaders

清除緩存目錄(/var/cache/yum)下的軟件包及舊的headers

命令:yum clean, yum cleanall (= yum clean packages; yum clean oldheaders)

3.2 /etc/yum.conf配置文件詳解

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

yum的配置文件:

[root@xml-oms 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的日誌文件所在的位置

distroverpkg=redhat-release  #yum會根據軟件包判斷你的發行版本,默認是redhat-release,也可以是安裝的任何針對自己發行版的rpm包。

tolerant=1                                    #表示yum是否容忍命令行發生與軟件包有關的錯誤,比如要安裝1,2,3三個包,其中3此前已經安裝了,如果你設爲1,yum不會出現錯誤信息。

exactarch=1                                 #是否只升級和你安裝軟件包cpu體系一致的包,如果設爲1,則如你安裝了一個i386的內核,則yum不會用i686的包來升級。

obsoletes=1                                 #update的參數,相當於upgrade,是否允許更新陳舊的RPM

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

plugins=1                                      #是否允許使用插件,默認是1允許

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

retries=1                                       #網絡連接發生錯誤後的重試次數,如果設爲0,則會無限重試

pkgpolicy=newest                  #包的策略。一共有兩個選項,newestlast,這個作用是如果你設置了多個repository,而同一軟件在不同的repository中同時存在,yum應該安裝哪一個,如果是newest,則yum會安裝最新的那個版本。如果是last,則yum會將服務器id以字母表排序,並選擇最後的那個服務器上的軟件安裝。一般都是選newest

 

# Note: yum-RHN-plugin doesn't honor this.

metadata_expire=1h                #用於指定信息庫數據庫的有效期,單位爲秒。

 

# Default.

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

 

# PUT YOUR REPOS HERE OR IN separate filesnamed file.repo

# in /etc/yum.repos.d

 

3.3 /etc/yum.repos.d/中的文件

該目錄的默認版本中只有1個文件。這個repo文件是Linux中yum源(軟件倉庫)的配置文件,通常一個repo文件定義了一個或者多個軟件倉庫的細節內容,例如我們將從哪裏下載需要安裝或者升級的軟件包,repo文件中的設置內容將被yum讀取和應用。

[root@dataserver01 ~]# ll /etc/yum.repos.d/*

-rw-r--r-- 1 root root 561 Mar 10  2010 /etc/yum.repos.d/rhel-debuginfo.repo

 

[oracle@dataserver01 ~]$ cat/etc/yum.repos.d/rhel-debuginfo.repo

[rhel-debuginfo]

name=Red Hat Enterprise Linux $releasever -$basearch - Debug

baseurl=ftp://ftp.redhat.com/pub/redhat/linux/enterprise/$releasever/en/os/$basearch/Debuginfo/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[rhel-debuginfo-beta]

name=Red Hat Enterprise Linux $releaseverBeta - $basearch - Debug

baseurl=ftp://ftp.redhat.com/pub/redhat/linux/beta/$releasever/en/os/$basearch/Debuginfo/

enabled=0

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta,file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

所有服務器設置都應該遵循如下格式:

[serverid]

name=name $releasever – $basearch  

baseurl=url://

url://

enabled=

gpgcheck=

gpgkey=

 

參數說明:

serverid: 用於指定一個倉庫,用於區別各個不同的repository,必須是一個唯一的名稱。

mirrorlist:鏡像站點列表,尋找可用的repository,mirrorlist和baseurl兩者僅用一個即可。

baseurl:    當mirrorlist註釋掉後,這個選項就是服務設置中最重要的部分,必須設置正確。其中的url: 支持的協議有 http://ftp:// file://三種。baseurl後可以跟多個url,你可以自己改爲速度比較快的鏡像站,但baseurl只能有一個,其中url指向的目錄必須是這個repository header目錄的上一級,也支持$releasever $basearch這樣的變量。

name:   是對repository的描述,定義了軟件倉庫的名稱,一般沒什麼作用。支持像$releasever$basearch這樣的變量。

$releasever:變量定義了發行版本,通常是8,9,10等數字

$basearch:變量定義了系統的架構,可以是i386、x86_64、ppc等值。cpu的基本體系組,如i686和athlon同屬i386。

failovermethode: 有兩個選項roundrobin和priority,意思分別是有多個url可供選擇時,yum選擇的次序,roundrobin是隨機選擇,如果連接失 敗則使用下一個,依次循環,priority則根據url的次序從第一個開始。如果不指明,默認是roundrobin。

enable:   用於指定是否使用本倉庫,默認值爲1,即可用

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

gpgkey:    定義用於校驗的gpg密鑰,可用手動導入密鑰。

3.4 導入密鑰

導入每個reposity的GPG key,yum可以使用gpg對包進行校驗,確保下載包的完整性,所以我們先要到各個repository站點找到gpg key,一般都會放在首頁的醒目位置,一些名字諸如 RPM-GPG-KEY.txt之類的純文本文件,把它們下載,然後用rpm --importxxx.txt命令將它們導入,最好把發行版自帶GPG-KEY也導入,rpm --import /usr/share/doc/redhat-release-*/RPM-GPG-KEY官方軟件升級用的上。

查看官方密鑰:

[oracle@dataserver01 ~]$ find / -type f -name"RPM-GPG-KEY*"

[oracle@dataserver01 ~]$ ll/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-*

-rw-r--r-- 1 root root 1175 Mar 10  2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-auxiliary

-rw-r--r-- 1 root root 1706 Mar 10  2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-beta

-rw-r--r-- 1 root root 1990 Mar 10  2010/etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-former

-rw-r--r-- 1 root root 1164 Mar 10  2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

-rw-r--r-- 1 root root  885 Mar 10 2010 /etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-rhx

 

導入密鑰:

[oracle@dataserver01 ~]$

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY*

或者

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5

rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-beta

4、掛載光盤搭建本地YUM服務器

4.1 服務器端掛載光盤

[root@xml-ora1 mnt]# mount /dev/cdrom/mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

[root@xml-ora1 mnt]# ll /mnt/cdrom/

total 3770

dr-xr-xr-x 3 root root   8192 Mar 22 2010 Cluster

dr-xr-xr-x 3 root root   8192 Mar 22 2010 ClusterStorage

-r--r--r-- 8 root root   8445 Sep 3  2008 EULA

-r--r--r-- 3 root root   8445 Mar 10 2010 eula.en_US

-r--r--r-- 8 root root  18416 Dec 1  2006 GPL

dr-xr-xr-x 4 root root   2048 Mar 22 2010 images

dr-xr-xr-x 2 root root   2048 Mar 22  2010 isolinux

4.2 客戶端修改yum源

yum的一切配置信息都儲存在一個叫yum.conf的配置文件中,通常位於/etc目錄下,是整個yum系統的核心。先copy原yum源文件備份,然後用vim編輯yum文件並保存:

[root@xml-ora1 cdrom]# cp/etc/yum.repos.d/rhel-debuginfo.repo /etc/yum.repos.d/rhel-debuginfo.repo.bak

[root@xml-ora1 cdrom]# vi/etc/yum.repos.d/rhel-debuginfo.repo

[root@xml-ora1 cdrom]# more/etc/yum.repos.d/rhel-debuginfo.repo

[Cluster]

name=Red Hat Enterprise Linux $releasever -$basearch - Cluster

baseurl=file:///mnt/cdrom/Cluster

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[ClusterStorage]

name=Red Hat Enterprise Linux $releasever -$basearch - ClusterStorage

baseurl=file:///mnt/cdrom/ClusterStorage

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[Server]

name=Red Hat Enterprise Linux $releasever -$basearch - Server

baseurl=file:///mnt/cdrom/Server

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

[VT]

name=Red Hat Enterprise Linux $releasever -$basearch - VT

baseurl=file:///mnt/cdrom/VT

enabled=1

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

 

配置文件社會自說明:

1)        [ ]內的是倉庫的名稱

2)        name是倉庫的描述或者說資源名稱

3)        baseurl 倉庫的位置,Yum源的目錄獲取路徑

4)        enabled 是否啓用這個倉庫,1爲起用,0爲禁用,本地設爲1

5)        gpgcheck 是否檢查GPG簽名(用來驗證要安裝的包是不是REDHAT官方的)

4.3 客戶端測試光盤Yum源使用

出現如下信息,說明配置成功:

[root@xml-ora1 etc]# yum grouplist

Setting up Group Process

Installed Groups:

  Administration Tools

  Legacy Software Development

  Legacy Software Support

  Mail Server

  Network Servers

  Server Configuration Tools

  System Tools

  Text-based Internet

   XWindow System

Available Groups:

  Authoring and Publishing

  Cluster Storage

  Clustering

  DNS Name Server

  Development Libraries

  Development Tools

  Editors

  Engineering and Scientific

  FTP Server

  GNOME Desktop Environment

  GNOME Software Development

  Games and Entertainment

  Graphical Internet

  Graphics

  Java Development

  KDE (K Desktop Environment)

  KDE Software Development

  KVM

  Legacy Network Server

  MySQL Database

  News Server

  Office/Productivity

  OpenFabrics Enterprise Distribution

  PostgreSQL Database

  Printing Support

  Sound and Video

  Web Server

  Windows File Server

   XSoftware Development

  Xen

Done

5、Copy光盤搭建本地YUM服務器

5.1 建立yum服務器目錄

創建一個存放放RPM所有安裝包的目錄,位置自定義:

[root@xml-oms /]# mkdir -p /u01/yum

5.2 copy光盤內容到yum服務器

掛載光盤:

[root@xml-oms cdrom]# mkdir -p /mnt/cdrom/

[root@xml-oms cdrom]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

 

獲取RPM包源,將ISO中的Server目錄複製到本機需要安裝YUM倉庫的目錄下:

[root@xml-oms ~]# cp -r /mnt/cdrom/Server/  /u01/yum.

5.3 createrepo工具安裝

yum 使用存儲在每一個rpm包裏的header信息摘要去完成它的工作,而這個摘要信息由'createrepo'程序創建,沒有安裝這個軟件進行信息收集,系統是無法查詢找到的。

安裝createrepo工具,然後用這個工具生成YUM通用數據庫。

[root@xml-oms Server]# rpm -q create*

package createrepo-0.4.11-3.el5.noarch.rpmis not installed

[root@xml-oms ~]# rpm -ivh/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm

warning:/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature:NOKEY, key ID 37017186

Preparing...               ########################################### [100%]

  1:createrepo            ########################################### [100%]

5.4 createrepo創建yum倉庫

進入創建的YUM倉庫目錄/u01/yum,重建倉庫信息配置文件(/u01/yum/目錄下)

[root@xml-oms ~]# cd /u01/yum/

[root@xml-oms ~]# createrepo /u01/yum/

1534/3116 -Server/tomcat5-servlet-2.4-api-javadoc-5.5.23-0jpp.7.el5_3.2.x86_64.2385/3116 -Server/jakarta-commons-collections-testframework-3.2-2jpp.3.x86_64.r2679/3116 -Server/jakarta-commons-collections-testframework-javadoc-3.2-2jpp.3.3116/3116 -Server/libFS-1.0.0-3.1.i386.rpm                                    

Saving Primary metadata

Saving file lists metadata

Saving other metadata

5.5 客戶端配置yum源

基於之前已經建立的YUM倉庫,這裏配置YUM客戶端,進入/etc/yum.repos.d,創建yum.repo文件(滿足*.repo即可),這裏採用備份原配置文件,直接修改:

[root@xml-oms yum]# cd /etc/yum.repos.d

[root@xml-oms yum.repos.d]# ll

total 12

-rw-r--r-- 1 root root 561 Mar 10  2010 rhel-debuginfo.repo

[root@xml-oms yum.repos.d]# cp rhel-debuginfo.repo  rhel-debuginfo.repo.bak

[root@xml-oms yum.repos.d]# ll

total 12

-rw-r--r-- 1 root root 561 Mar 10  2010 rhel-debuginfo.repo

-rw-r--r-- 1 root root 561 Nov 19 17:39rhel-debuginfo.repo.bak

 

yum.repo文件配置信息修改爲如下:

[root@xml-oms yum.repos.d]# vi rhel-debuginfo.repo

[Server]

name=Server

baseurl=file:///u01/yum/Server

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

5.6 測試YUM倉庫配置是否成功

測試之前,最好把YUM的所有緩存清除一下

[root@xml-oms yum.repos.d]# yum clean all

Loaded plugins: rhnplugin, security

Cleaning up Everything

[root@xml-oms yum.repos.d]# yum grouplist

Loaded plugins: rhnplugin, security

This system is not registered with RHN.

RHN support will be disabled.

[root@xml-oms yum.repos.d]# yum install vsftpd

[root@xml-oms yum.repos.d]# yum remove vsftpd

6、FTP方式搭建遠程YUM服務器(推薦)

6.1 建立yum服務器目錄

創建一個存放放RPM所有安裝包的目錄,位置自定義:

[root@xml-oms /]# mkdir -p /u01/yum

6.2 copy光盤內容到yum服務器

掛載光盤:

[root@xml-oms cdrom]# mkdir -p /mnt/cdrom/

[root@xml-oms cdrom]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

 

獲取RPM包源,將ISO中的Server目錄複製到本機需要安裝YUM倉庫的目錄下:

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/Server//u01/yum

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/ClusterStorage//u01/yum/

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/VT/ /u01/yum/

[root@xml-oms yum]# pwd

/u01/yum

6.3 安裝FTP服務器

 [[email protected]]# rpm -ivh/u01/yum/Server/vsftpd-2.0.5-16.el5_4.1.x86_64.rpm

warning:/u01/yum/Server/vsftpd-2.0.5-16.el5_4.1.x86_64.rpm: Header V3 DSA signature:NOKEY, key ID 37017186

Preparing...                ###########################################[100%]

  1:vsftpd                ########################################### [100%]

[root@xml-oms yum.repos.d]# chkconfig --list vsftpd

vsftpd          0:off   1:off  2:off   3:off   4:off  5:off   6:off

[root@xml-oms yum.repos.d]# chkconfig vsftpd on

[root@xml-oms yum.repos.d]# chkconfig --list vsftpd

vsftpd          0:off   1:off  2:on    3:on    4:on   5:on    6:off

[root@xml-oms yum.repos.d]# service vsftpd status

vsftpd is stopped

[root@xml-oms yum.repos.d]# service vsftpd start

Starting vsftpd for vsftpd: [  OK  ]

[root@xml-oms yum.repos.d]# service vsftpd status

vsftpd (pid 15673) is running...

6.4 將FTP目錄指向yum服務器目錄

這裏使用將ftp目錄指向yum服務器目錄,在/etc/vsftpd/vstpd.conf末尾添加以下參數即可。或者可以移動系統盤中的RPM文件到FTP中,或者建立鏈接目錄到yum服務器目錄。

[root@xml-oms ~]# vi /etc/vsftpd/vsftpd.conf

……

vsftpd_log_file=/var/log/vsftpd.log

use_localtime=YES

anon_root=/u01/yum

 

[root@xml-oms yum.repos.d]# service vsftpd restart

Shutting down vsftpd: [  OK  ]

Starting vsftpd for vsftpd: [  OK  ]

 

在windows下測試ftp連通和有效性:

C:\Users\Administrator>ftp 172.16.10.173

連接到 172.16.10.173。

220 (vsFTPd 2.0.5)

用戶(172.16.10.173:(none)): anonymous

331 Please specify the password.

密碼:

230 Login successful.

ftp> ls

200 PORT command successful. Consider usingPASV.

150 Here comes the directory listing.

Server

Repodata

6.5 createrepo工具安裝

yum 使用存儲在每一個rpm包裏的header信息摘要去完成它的工作,而這個摘要信息由'createrepo'程序創建,沒有安裝這個軟件進行信息收集,系統是無法查詢找到的。

安裝createrepo工具,然後用這個工具生成YUM通用數據庫。

[root@xml-oms Server]# rpm -q create*

package createrepo-0.4.11-3.el5.noarch.rpmis not installed

[root@xml-oms ~]# rpm -ivh/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm

warning:/u01/yum/Server/createrepo-0.4.11-3.el5.noarch.rpm: Header V3 DSA signature:NOKEY, key ID 37017186

Preparing...               ########################################### [100%]

  1:createrepo            ########################################### [100%]

6.6 createrepo重建倉庫

         在RHEL 5中每個目錄下的repodata目錄下都有一個repomd.xml,該文件中就記錄了rpm包的依賴關係,還有一個comps-rhel5-*.xml文件,這個文件主要記錄分組情況,建立yum倉庫時,需要先重建該文件。

 

重建Server

[root@xml-oms repodata]# cd /u01/yum/Server/repodata/

[root@xml-oms repodata]# pwd

/u01/yum/Server/repodata

[root@xml-oms repodata]# ls

comps-rhel5-server-core.xml  other.xml.gz    repomd.xml

filelists.xml.gz             primary.xml.gz  TRANS.TBL

[root@xml-oms repodata]#

createrepo -g /u01/yum/Server/repodata/comps-rhel5-server-core.xml/u01/yum/Server

2679/3116 -jakarta-commons-collections-testframework-javadoc-3.2-2jpp.3.x86_64.3116/3116 -libFS-1.0.0-3.1.i386.rpm                                           

Saving Primary metadata

Saving file lists metadata

Saving other metadata

 

重建VT

[root@xml-oms yum]# cd /u01/yum/VT/repodata/

[root@xml-oms repodata]# pwd

/u01/yum/VT/repodata

[root@xml-oms repodata]#createrepo -g/u01/yum/VT/repodata/comps-rhel5-vt.xml /u01/yum/VT/

2/71 - celt051-0.5.1.3-0.el5.i386.rpm                                           

Error opening package -Virtualization-ta-IN-5.2-11.noarch.rpm

21/71 -Virtualization-kn-IN-5.2-11.noarch.rpm                                 

Error opening package -Virtualization-pa-IN-5.2-11.noarch.rpm

71/71 - Virtualization-pt-BR-5.2-11.noarch.rpm                                 

Saving Primary metadata

Saving file lists metadata

Saving other metadata

 

重建Cluster

[root@xml-oms repodata]# cd /u01/yum/Cluster

[root@xml-oms Cluster]# pwd

/u01/yum/Cluster

[root@xml-oms Cluster]# createrepo -g/u01/yum/Cluster/repodata/comps-rhel5-cluster.xml /u01/yum/Cluster

32/32 -Cluster_Administration-mr-IN-5.2-1.noarch.rpm                          

Saving Primary metadata

Saving file lists metadata

Saving other metadata

 

重建ClusterStorage

[root@xml-oms Cluster]# cd /u01/yum/ClusterStorage/

[root@xml-oms ClusterStorage]# pwd

/u01/yum/ClusterStorage

[root@xml-oms ClusterStorage]#createrepo -g/u01/yum/ClusterStorage/repodata/comps-rhel5-cluster-st.xml/u01/yum/ClusterStorage/

39/39 -kmod-cmirror-0.1.22-3.el5.x86_64.rpm                                   

Saving Primary metadata

Saving file lists metadata

Saving other metadata

6.7 準備客戶端yum配置文件

在每個客戶端使用YUM時,必須需要修改配置文件/etc/yum.repos.d/*.repo。 這個文件名稱可以隨便定義,但是擴展名必須是repo。新建一個YUM配置文件ftp.repo,如下:

[root@xml-oms yum]# cp /etc/yum.repos.d/rhel-debuginfo.repo/etc/yum.repos.d/ftp.repo

[root@xml-oms yum]# ll /etc/yum.repos.d/

ftp.repo                 rhel-debuginfo.repo      rhel-debuginfo.repo.bak

[root@xml-oms yum]# vi /etc/yum.repos.d/ftp_rhel5.5x64.repo

[ftp-rhel5.5-base]

name=Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/Server

gpgcheck=0

enabled=1

 

[ftp-rhel5.5-vt]

name=Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/VT

gpgcheck=0

enabled=1

 

[ftp-rhel5.5-cluster]

name= Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/Cluster

gpgcheck=0

enabled=1

 

[ftp-rhel5.5-ClusterStorage]

name= Redhat Enterprise 5.5x64

baseurl=ftp://172.16.10.173/ClusterStorage

 

複製一份到ftp目錄下,提供下載。

[root@xml-oms yum]# cp /etc/yum.repos.d/ftp_rhel5.5x64.repo /u01/yum/

6.8 客戶端更新配置yum源

         這裏客戶可以有2中方式下載服務器的yum源文件,FTP下載或者wget:

[root@xml-ora1 yum.repos.d]# cd /etc/yum.repos.d

[root@xml-ora1 yum.repos.d]# pwd

/etc/yum.repos.d

[root@xml-ora1 yum.repos.d]# wgetftp://172.16.10.173/ftp_rhel5.5x64.repo

--2012-11-20 11:04:37--  ftp://172.16.10.173/ftp_rhel5.5x64.repo

           => `ftp_rhel5.5x64.repo'

Connecting to 172.16.10.173:21...connected.

Logging in as anonymous ... Logged in!

==> SYST ... done.    ==> PWD ... done.

==> TYPE I ... done.  ==> CWD not needed.

==> SIZE ftp_rhel5.5x64.repo ... 463

==> PASV ... done.    ==> RETR ftp_rhel5.5x64.repo ... done.

Length: 463

100%[======================================>]463         --.-K/s  in 0s     

2012-11-20 11:04:37 (20.1 MB/s) -`ftp_rhel5.5x64.repo' saved [463]

 

或者ftp:

[root@xml-ora1 ~]# ftp 172.16.10.173

6.9客戶端yum測試

清除YUM緩存 ,測試:

[root@xml-ora1 yum.repos.d]# yum clean all

Cleaning up Everything

[root@xml-ora1 yum.repos.d]# yum check-update

ftp-rhel5.5-ClusterStorage                               | 1.1 kB     00:00    

ftp-rhel5.5-ClusterStorage/primary                       | 8.2 kB     00:00    

ftp-rhel5.5-ClusterStorage                                               39/39

ftp-rhel5.5-base                                         | 1.1kB     00:00    

ftp-rhel5.5-base/primary                                 | 1.1 MB     00:00    

ftp-rhel5.5-base                                                     3116/3116

ftp-rhel5.5-cluster                                      | 1.1kB     00:00    

ftp-rhel5.5-cluster/primary                              | 5.8 kB     00:00    

ftp-rhel5.5-cluster                                                      32/32

ftp-rhel5.5-vt                                           |1.1 kB     00:00    

ftp-rhel5.5-vt/primary                                   |  19 kB    00:00    

ftp-rhel5.5-vt:[#####################################################  ] 69/71[

注意,看到上面的ftp-rhel5.5-ClusterStorage信息說明是從我們的ftp源進行數據更新的。說明配置客戶端源成功。

7、HTTP方式搭建遠程YUM服務器

7.1 建立yum服務器目錄

創建一個存放放RPM所有安裝包的目錄,位置自定義:

[root@xml-oms /]# mkdir -p /u01/yum

7.2 copy光盤內容到yum服務器

掛載光盤:

[root@xml-oms cdrom]# mkdir -p /mnt/cdrom/

[root@xml-oms cdrom]# mount /dev/cdrom /mnt/cdrom/

mount: block device /dev/cdrom iswrite-protected, mounting read-only

 

獲取RPM包源,將ISO中的Server目錄複製到本機需要安裝YUM倉庫的目錄下:

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/Server//u01/yum

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/ClusterStorage//u01/yum/

[root@xml-oms cdrom]# cp -rf /mnt/cdrom/VT/ /u01/yum/

[root@xml-oms yum]# pwd

/u01/yum

7.3 安裝httpd

[root@xml-oms yum]# rpm -ivh /mnt/cdrom/Server/httpd-*

httpd-2.2.3-43.el5.x86_64.rpm         httpd-devel-2.2.3-43.el5.x86_64.rpm

httpd-devel-2.2.3-43.el5.i386.rpm     httpd-manual-2.2.3-43.el5.x86_64.rpm

7.4 修改http.conf

http.conf是apache的主配置文件,爲了避免啓動報錯。最好備份一下:

[root@localhost conf]# cp -p /etc/httpd/conf/httpd.conf/etc/httpd/conf/httpd.conf.bak

把 DocumentRoot 改成拷rpm包的目錄,大約在281行

[root@localhost conf]#vi httpd/conf +281

 ---->  281 DocumentRoot "/u01/yum/Server"

7.5重啓apahce服務

[root@localhost conf]# service httpd restart

Stopping httpd: [  OK  ]

Starting httpd: [  OK  ]

7.6 客戶端配置

         在配置文件目錄心中一個http.repo配置文件

[root@localhost yum.repos.d]# pwd

/etc/yum.repos.d

[root@localhost yum.repos.d]# cat http.repo

[http-rhel5.5-base]

name=Redhat Enterprise 5.5x64

baseurl=http://172.16.10.173

enabled=1

gpgcheck=0

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

7.7 軟件安裝測試

[root@localhost yum.repos.d]#yum clean all

[root@localhost yum.repos.d]#yum install sendmail –y

8、RHEL5使用Cent-OS5的YUM源

由於CentOS-5是RHEL-5的免費版,可以使用CentOS-5的yum源來達到在RHEL-5下更新軟件。

8.1 編輯YUM 配置文件

[root@dataserver01 ~]# cd /etc/yum.repos.d/

[root@dataserver01 yum.repos.d]# ls

rhel-debuginfo.repo

[root@dataserver01 yum.repos.d]# pwd

/etc/yum.repos.d

[root@Server yum.repos.d]# vi centos5.repo

[base]

name=Red Hat Enterprise Linux $releasever-Base

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever5&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#released updates

[update]

name=Red Hat Enterprise Linux $releasever-Updates

#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates

baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#packages used/produced in the build butnot released

[addons]

name=Red Hat Enterprise Linux $releasever-Addons

#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons

baseurl=http://ftp.sjtu.edu.cn/centos/5/addons/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#additional packages that may be useful

[extras]

name=Red Hat Enterprise Linux $releasever-Extras

#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras

baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

 

8.2 導入RPM-KEY

[root@dataserver01 yum.repos.d]#

rpm --importhttp://ftp.sjtu.edu.cn/centos/5/os/i386/RPM-GPG-KEY-CentOS-5

8.3 清理以下緩存測試

[root@dataserver01 yum.repos.d]# yum clean all

Loaded plugins: rhnplugin, security

Cleaning up Everything

[root@dataserver01 yum.repos.d]#yum list

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章