Monday, March 10, 2008

利用 LFTP 建立 YUM Server

看過很多人用不同的方法來架 YUM Server 各有利弊
在經過一番的選擇後 後來我是選擇使用 LFTP 來架 YUM Server
原因是他的彈性語法簡單易懂 可以搭配 exclude 或 include 來指定要下載的 rpms
例如 openoffice 很少用就可以用 exclude 來排除,
或是 centosplus 你只需要更新 kernel-xxx-centos.plus ,可以 include 只下載需要的部份。

以下是 CentOS 5.X 的範例,為了避免字數過長,將 rpm 放到 /centos 目錄
另外 httpd 的設定,相信大家都會,就不再贅述。

mkdir /centos
cd /centos
wget http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5
mkdir -p /centos/5/os/i386

ps. key 要放在 /centos 主目錄,此行亦可以放在 lftp config 裡面

vi centos5-lftp.config
ps. 可以用 -x openoffice 表示不下載 openoffice
以下範例視個人需要,把註解拿掉。若只需要抓一次,建議抓完後註解掉,節省 LFTP 檢查的時間。
寫好後執行

lftp -f centos5-lftp.config

若沒有問題,可以放到 crontab 每星期更新一次就好了 每天更新也沒用
因為 CentOS 更新頻率約一星期一次,而且通常是假日

以下為 centos5-lftp.config 內容
#以下有三個 FTP 站台供選擇
open http://ftp.cs.pu.edu.tw
#open ftp.tcc.edu.tw
#open http://ftp.twaren.net
# only need to get repodata, headers, rpms
#
# For OS, 第一次才需要,抓完後可以註解掉
mirror -e --delete /Linux/CentOS/5/os/i386/repodata /centos/5/os/i386/repodata
mirror -e --delete /Linux/CentOS/5/os/i386/CentOS /centos/5/os/i386/CentOS
#For boot server ,抓完後可以註解掉
mirror -e --delete /Linux/CentOS/5/os/i386/images /centos/5/os/i386/images
mirror -e --delete /Linux/CentOS/5/os/i386/isolinux /centos/5/os/i386/isolinux
#以上四行亦可換成下面一行
#mirror -e --delete /Linux/CentOS/5/os/i386 /centos/5/os/i386
#For update
mirror -e --delete /Linux/CentOS/5/updates/i386/repodata /centos/5/updates/i386/repodata
mirror -e --delete -x openoffice /Linux/CentOS/5/updates/i386/RPMS /centos/5/updates/i386/RPMS
#For extra
#mirror -e --delete /Linux/CentOS/5/extras/i386/repodata /centos/5/extras/i386/repodata
#mirror -e --delete /Linux/CentOS/5/extras/i386/RPMS /centos/5/extrass/i386/RPMS
#For centosplus
mirror -e --delete /Linux/CentOS/5/centosplus/i386/repodata /centos/5/centosplus/i386/repodata
mirror -e --delete /Linux/CentOS/5/centosplus/i386/RPMS /centos/5/centosplus/i386/RPMS


然後就可以將 /etc/yum.repos.d/CentOS-Base.repo
每一行 baseurl 改成你目前的主機 並將 mirrorlist 註解掉
baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
改成 baseurl=http://you.server.com/centos/$releasever/updates/$basearch/

如下。只列出 base, update, exteas, centosplus

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=http://10.254.1.1/pub/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://10.254.1.1/pub/centos/RPM-GPG-KEY-CentOS-5

#released updates
[update]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://10.254.1.1/pub/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://10.254.1.1/pub/centos/RPM-GPG-KEY-CentOS-5

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://10.254.1.1/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://10.254.1.1/pub/centos/RPM-GPG-KEY-CentOS-5
enabled=0

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
baseurl=http://10.254.1.1/pub/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://10.254.1.1/pub/centos/RPM-GPG-KEY-CentOS-5


如果是 CentOS 4.X ,則要多 mirror 一個 headers 的目錄,簡單的範例如下
cat centos4-ftp.config
#以下有三個 FTP 站台供選擇
open http://ftp.cs.pu.edu.tw
#open ftp.tcc.edu.tw
#open http://ftp.twaren.net
# only need to get repodata, headers, rpms
#
# For OS, 第一次才需要,抓完後可以註解掉
mirror -e --delete /Linux/CentOS/4/os/i386 /centos/4/os/i386
# For Update
mirror -e --delete /Linux/CentOS/4/updates/i386/repodata /centos/4/updates/i386/repodata
mirror -e --delete /Linux/CentOS/4/updates/i386/headers /centos/4/updates/i386/headers
mirror -e --delete -x office /Linux/CentOS/4/updates/i386/RPMS /centos/4/updates/i386/RPMS

No comments:

Post a Comment