2011年7月18日 星期一

[研究] 架設 CentOS 6.0 Yum Server


[研究] 架設 CentOS 6.0 Yum Server 

如果你的 CentOS 6.0 有很多台,可能想自己架設 Yum Server,而不是連上預設的 Yum Server,或連上國內某大學 Yum Server。

以下是以 CentOS 6.0 x86 架設 CentOS 6.0 Yum Server 方法:
(你也可以拿 Fedora 15 或其他 Linux 架設給 CentOS 6.0 Yum Server,方法不保證 100% 相同)

安裝所需套件和建立相關目錄:
代碼:
yum  -y  install  yum-arch  createrepo wget

mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/os/i386
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/updates/i386
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/extras/i386
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/centosplus/i386
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/contrib/i386

mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/os/x86_64
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/updates/x86_64
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/extras/x86_64
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/centosplus/x86_64
mkdir -p  /var/www/html/pub/Linux/CentOS/6.0/contrib/x86_64

ln -s /var/www/html/pub/Linux/CentOS/6.0  /var/www/html/pub/Linux/CentOS/6


建立 yum_cent60.sh 檔案,此處是去抓義守大學 (ISU) 的 Yum Server 內容:
(你可以改成其他大學,路徑要再確認一下)
代碼:

#---------------------------
# yum_cent60.sh
#---------------------------

cd  /var/www/html/pub/Linux/CentOS/6.0/os/i386
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/os/i386
createrepo /var/www/html/pub/Linux/CentOS/6.0/os/i386

cd  /var/www/html/pub/Linux/CentOS/6.0/updates/i386
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/updates/i386
createrepo /var/www/html/pub/Linux/CentOS/6.0/updates/i386

cd  /var/www/html/pub/Linux/CentOS/6.0/extras/i386
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/extras/i386
createrepo /var/www/html/pub/Linux/CentOS/6.0/extras/i386

cd  /var/www/html/pub/Linux/CentOS/6.0/centosplus/i386
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/centosplus/i386
createrepo /var/www/html/pub/Linux/CentOS/6.0/centosplus/i386

cd  /var/www/html/pub/Linux/CentOS/6.0/contrib/i386
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/contrib/i386
createrepo /var/www/html/pub/Linux/CentOS/6.0/contrib/i386

#---------------------

cd  /var/www/html/pub/Linux/CentOS/6.0/os/x86_64
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/os/x86_64
createrepo /var/www/html/pub/Linux/CentOS/6.0/os/x86_64

cd  /var/www/html/pub/Linux/CentOS/6.0/updates/x86_64
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/updates/x86_64
createrepo /var/www/html/pub/Linux/CentOS/6.0/updates/x86_64

cd  /var/www/html/pub/Linux/CentOS/6.0/extras/x86_64
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/extras/x86_64
createrepo /var/www/html/pub/Linux/CentOS/6.0/extras/x86_64

cd  /var/www/html/pub/Linux/CentOS/6.0/centosplus/x86_64
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/centosplus/x86_64
createrepo /var/www/html/pub/Linux/CentOS/6.0/centosplus/x86_64

cd  /var/www/html/pub/Linux/CentOS/6.0/contrib/x86_64
wget --passive-ftp -m -nH -nd ftp://ftp.isu.edu.tw/pub/Linux/CentOS/6.0/contrib/x86_64
createrepo /var/www/html/pub/Linux/CentOS/6.0/contrib/x86_64


設定為可執行:
代碼:
chmod  +x  /root/yum_cent60.sh


執行 vi /etc/crontab 設定排程,此處設定每天 PM 6:00 (18:00) 執行 /root/yum_cent60.sh
代碼:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
00 18 * * * /root/yum_cent60.sh

(完)

Client 的設定

當你有 CentOS 6.0 需要使用此台 CentOS 6.0 Yum Server 時,Client 請做下面修改
(假設該台 Yum Server IP 為 10.3.0.60)

/etc/yum.repos.d/CentOS-Base.repo 用下面的取代

代碼:
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://10.3.0.60/pub/Linux/CentOS/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates
[updates]
name=CentOS-$releasever - Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
baseurl=http://10.3.0.60/pub/Linux/CentOS/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
baseurl=http://10.3.0.60/pub/Linux/CentOS/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#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://mirror.centos.org/centos/$releasever/centosplus/$basearch/
baseurl=http://10.3.0.60/pub/Linux/CentOS/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
#baseurl=http://mirror.centos.org/centos/$releasever/contrib/$basearch/
baseurl=http://10.3.0.60/pub/Linux/CentOS/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6


相關文章

[研究] Fedora 15 x86 yum server 指定義守大學方法
viewtopic.php?f=16&t=20256

[研究] CentOS 6.0 yum server 指定義守大學方法
http://forum.icst.org.tw/phpbb/viewtopic.php?f=16&t=20206

[研究] Fedora 14 yum server 指定義守大學方法
http://forum.icst.org.tw/phpbb/viewtopic.php?f=16&t=19591

[研究] CentOS 5.5 yum server 指定義守大學方法
http://forum.icst.org.tw/phpbb/viewtopic.php?f=16&t=19592

(完)

沒有留言:

張貼留言