yum(Yellow dog Updater, Modified) 是一個與apt類似的軟件包管理器,在Fedora,Redhat,SUSE,CentOS等Linux發行版中采用。
軟件包管理器可以解決rpm的依賴管理問題,使得軟件的安裝、升級更加容易。
yum使用中心倉庫(repository)最為軟件源,管理軟件包,而各Linux系統通過yum的配置連接到這個源來獲取軟件包。
1 理由
盡管有很多的免費鏡像提供yum源服務,但是還是有必要建立自己的yum服務器,主要出於以下幾點考慮:
- 網絡速度:訪問互聯網可能比較慢
- 節省帶寬:如果有大量的服務器,架設自己的yum源可以有效節省互聯網帶寬
- 聯網限制:對於有些內網服務器,不能連接到互聯網
- 對於RHEL(Redhat Enterprise Linux),需要購買服務
- 便於發布自己開發的rpm包
2 規划
本公司服務器操作系統主要是RHEL和CentOS,所以希望同時提供這些操作系統的yum源。
由於沒有購買RHEL服務,所以RHEL源使用DVD中的文件構建一個“靜態”的源。
而CentOS則可以與一個發布的源進行同步,以保持更新。官方認可的鏡像服務可以在 http://www.centos.org/modules/tinycontent/index.php?id=32 查找速度較快並且支持rsync的鏡像,但是我找到了一個國內的鏡像不在該列表中: mirrors.ustc.edu.cn/centos/. 這個鏡像支持rsync 服務,可以進行同步更新。
yum源的規划如下: http://dev.mycompony.com/mirrors/ centos/ centos源,其目錄結構與其他鏡像站點相同
rhel/ RHEL源 6Server/ 5erver/ os/ x8664/ # 將RHEL dvd的iso光盤文件掛載到此目錄 updates/ x8664/ # 使用mirrordir從ftp://ftp.redhat.com/redhat/linux/updates/rhn/5Server/x86_64/ 同步 custom/ x8664/ # 自己開發的內部使用的軟件包 Packages/ # 打包的rpm文件 repodata/ # 用createrepo生成的索引文件 RPM-GPG-KEY-redhat-5Server RPM-GPG-KEY-redhat-6Server CentOS-mycompany.repo RHEL-mycompany.repo
3 架設
yum源可以使用http或ftp提供服務,這里使用nginx作為webserver,提供http方式的訪問。
1.在/path/to/your/mirrors 創建好上面規划的目錄結構。
- 對於centos,使用命令:
rsync -avrt rsync://mirrors.ustc.edu.cn/centos/ –exclude=debug/ –exclude=i386/ –exclude=isos/ /path/to/your/mirrors/centos
可以實現同步。也可以將此命令加入crontab,我設置的周期是每天同步。 - 對於RHEL,分成幾個部分:
1)用dvd鏡像文件提供基本的軟件包,只需要將RHEL dvd的iso光盤文件掛載到對應的目錄即可,同時為了方便,可以將其中的RPM-GPG-KEY文件復制到/path/to/your/mirrors/RHEL目錄下面,並按照版本命名。
2)對於rhn提供的updates,也可以建立一個鏡像。由於redhat.com不提供rsync服務,需要用mirrordir實現同步:
mirrordir ftp://ftp.redhat.com/redhat/linux/updates/rhn/5Server/x86_64/ /var/files/mirrors/RHEL/5Server/updates/x86_64
如果沒有安裝mirrordir,可以從 http://genotec.linux.tucows.com/files/mirrordir-0.10.49.tar.gz 下載。 該命令也可以加入到crontab的計划任務中以實現定期同步。
3)如果有一下內部開發的軟件包,可以創建一個custom文件夾,將發布的rpm放到其中的Packages目錄,再通過命令:
cd path/to/your/mirrors/RHEL/5server/custom/x8664 createrepo -o . Packages
創建索引文件
4 使用
為了便於使用,可以提供寫好的repo文件,用戶只需放到/etc/yum.repos.d/目錄下,再執行yum update 即可。這里創建了CentOS-mycompany.repo 和 RHEL-mycompany.repo 放到/path/to/your/mirrors目錄下,分別用於CentOS和RHEL。
在repo文件中可以盡量使用變量,以提高通用性。常用的變量包括:
$releasever,發行版的版本
$arch,cpu體系(划分過於細致,在repo文件中一般不使用,而是使用下面的$basearch)
$basearch,cpu的基本體系組
我的兩個repo文件參考如下:
RHEL-mycompany.repo:
[base] name=RHEL-mycompany - Base baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/os/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever [updates] name=RHEL-mycompany - Update baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/updates/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever [extras] name=RHEL-mycompany - Extra baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/extras/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever [custom] name=RHEL-mycompany - Custom baseurl=http://dev.mycompany.com/mirrors/RHEL/$releasever/custom/$basearch/ enabled=1 gpgcheck=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-redhat-$releasever
CentOS-mycompany.repo:
[base] name=CentOS-mycompany - Base baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/os/$basearch/ gpgchecksever=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever #released updates [update] name=CentOS-mycompany - Updates baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever #additional packages that may be useful [extras] name=CentOS-mycompany - Extras baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/extras/$basearch/ gpgcheck=1 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever #additional packages that extend functionality of existing packages [centosplus] name=CentOS-mycompany - Plus baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever #contrib - packages by Centos Users [contrib] name=CentOS-mycompany - Contrib baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/contrib/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever #packages of mycompany [custom] name=CentOS-mycompany - custom baseurl=http://dev.mycompany.com/mirrors/centos/$releasever/custom/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://dev.mycompany.com/mirrors/centos/RPM-GPG-KEY-CentOS-$releasever
Date: 2012-08-17 15:17:22 CST
HTML generated by org-mode 6.33x in emacs 23