Cychin Net

a Chin's 生活雜記!

自建 YUM Server (CentOS 6.4)

by Alex on 2013 年 03 月 20 日

由於內部Linux主機愈來愈多了,每次在更新的時候,都會耗掉對外的頻寬,所以才想說要建立內部的YUM Server,除了可節省對外的頻寬外,安裝及更新的時間也都可以加快許多又方便

內部的Linux都是使用CentOS 6,所以就另外安裝一台Linux,作為YUM Server,做法如下:

1. 安裝所需套件:httpd, yum-arch, createrepo

先安裝EPEL

#rpm -Uvh http://http://mirror01.idc.hinet.net/EPEL/6/x86_64/epel-release-6-8.noarch.rpm

安裝httpd, yum-arch, createrepo

#yum groupinstall “Web Server”

#yum install yum-arch createrepo

啟動httpd 服務

#service httpd start

#chkconfig –level 235 httpd on  –> 開機時自動啓動

2. 建立YUM Server 設定

建立要放置Source 目錄

#mkdir -p /var/www/html/yum/centos/6.4/os/x86_64

#mkdir -p /var/www/html/yum/centos/6.4/updates/x86_64

#mkdir -p /var/www/html/yum/centos/6.4/extras/x86_64

針對目錄mirror YUM Server 更新套件 (這裡使用rsync,而不是使用mirrordir的方式,因為當我使用mirrordir都會因為buffer over flow,而中斷無法更新)

#rsync -aqzH –delete ftp.cs.pu.edu.tw::CentOS/6.4/os/x86_64 /var/www/html/yum/centos/6.4/os/x86_64

#rsync -aqzH –delete ftp.cs.pu.edu.tw::CentOS/6.4/updates/x86_64 /var/www/html/yum/centos/6.4/updates/x86_64

#rsync -aqzH –delete ftp.cs.pu.edu.tw::CentOS/6.4/extras/x86_64 /var/www/html/yum/centos/6.4/extras/x86_64

RPM分析,並在目錄下產生headers資料夾

#yum-arch /var/www/html/yum/centos/6.4/os/x86_64

#yum-arch /var/www/html/yum/centos/6.4/updates/x86_64

#yum-arch /var/www/html/yum/centos/6.4/extras/x86_64

使用createrepo產生XML metadata,並在目錄下產生repodata資料夾

#createrepo /var/www/html/yum/centos/6.4/os/x86_64

#createrepo /var/www/html/yum/centos/6.4/updates/x86_64

#createrepo /var/www/html/yum/centos/6.4/extras/x86_64

設定每週自動更新套件

#vim /usr/local/sbin/yum-update.sh

加入上述rsync三個指令後,存檔,並修改權限

#rsync -aqzH –delete ftp.cs.pu.edu.tw::CentOS/6.4/os/x86_64 /var/www/html/yum/centos/6.4/os/x86_64

#rsync -aqzH –delete ftp.cs.pu.edu.tw::CentOS/6.4/updates/x86_64 /var/www/html/yum/centos/6.4/updates/x86_64

#rsync -aqzH –delete ftp.cs.pu.edu.tw::CentOS/6.4/extras/x86_64 /var/www/html/yum/centos/6.4/extras/x86_64

#chmod 777 /usr/local/sbin/yum-update.sh

加到排程工作執行

#crontab -e

0 2 * * 7 /usr/local/sbin/yum-update.sh  –> 設定為每週日凌晨2點執行

3. YUM Client 設定

設定YUM

#cp /etc/yum.repo/CentOS-Base.repo /etc/yum.repo/CentOS-Base.repo.bak

#vi /etc/yum.repo/CentOS-Base.repo

將[base] [updates] [extras] 的更新路徑變更為內部的YUM Server

—————————————————————————————————————————-

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

[updates]
name=CentOS-$releasever – Updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=http://YUM Server IP/yum/centos/$releasever/updates/$basearch/
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
gpgkey=http://YUM Server IP/yum/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-6

[extras]
name=CentOS-$releasever – Extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=http://YUM Server IP/yum/centos/$releasever/extras/$basearch/
gpgcheck=1
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
gpgkey=http://YUM Server IP/yum/centos/$releasever/os/$basearch/RPM-GPG-KEY-CentOS-6

—————————————————————————————————————————-

#yum clean all

#yum update

以上YUM Server/Client即完成設定

One thought on “自建 YUM Server (CentOS 6.4)

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *

* Copy This Password *

* Type Or Paste Password Here *