在CentOS制作本地yum源公司电脑多,而且80%是Linux,所以制作本地yum源可以节省大量时间到网上更新。
我是使用apache作为yum传输工具
这是我的apache配置
# ServerAdmin webmaster@dummy-host.example.com DocumentRoot /opt/Centos ServerName 192.168.5.30 # ErrorLog logs/dummy-host.example.com-error_log # CustomLog logs/dummy-host.example.com-access_log common
Options Indexes MultiViews AllowOverride None Order allow,deny Allow from all
|
yum 源的目录结构是
[root@host30 Centos]# tree -d /opt/Centos/
/opt/Centos/
`-- Centos
|-- i386
| |-- addons
| | |-- RPMS
| | `-- repodata
| |-- centosplus
| | |-- RPMS
| | `-- repodata
| |-- contrib
| | |-- RPMS
| | `-- repodata
| |-- extras
| | |-- RPMS
| | `-- repodata
| |-- fasttrack
| | |-- RPMS
| | `-- repodata
| |-- os
| | |-- CentOS
| | |-- NOTES
| | |-- images
| | | |-- pxeboot
| | | `-- xen
| | |-- isolinux
| | `-- repodata
| `-- updates
| |-- RPMS
| `-- repodata
`-- x86_64
|-- addons
| |-- RPMS
| `-- repodata
|-- centosplus
| |-- RPMS
| `-- repodata
|-- contrib
| |-- RPMS
| `-- repodata
|-- extras
| |-- RPMS
| `-- repodata
|-- fasttrack
| |-- RPMS
| `-- repodata
|-- os
| |-- CentOS
| |-- NOTES
| |-- images
| | |-- pxeboot
| | `-- xen
| |-- isolinux
| `-- repodata
`-- updates
|-- RPMS
`-- repodata
为了节省自己到网上更新的时间,可以将本地的iso镜像复制到os目录中
[root@host30 Centos]# mount
/opt/OS/CentOS-5.3-x86_64-bin-DVD.iso on /mnt/os type iso9660 (rw,loop=/dev/loop0)
/opt/OS/CentOS-5.4-i386-bin-DVD.iso on /mnt/os2 type iso9660 (rw,loop=/dev/loop1)
[root@host30 Centos]# cp -a /mnt/os/* /opt/Centos/Centos/i386/os/
[root@host30 Centos]# cp -a /mnt/os2/* /opt/Centos/Centos/x86_64/os/
到网上同步最新镜像
在rsync.muug.mb.ca/centos/5.4中有CentOS最新的源
[root@host30 rsync]# cat sync_yum_source.sh
/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/updates/i386/ /opt/Centos/Centos/i386/updates/
#/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/os/i386/ /opt/Centos/Centos/i386/os/
/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/addons/i386/ /opt/Centos/Centos/i386/addons/
/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/centosplus/i386/ /opt/Centos/Centos/i386/centosplus/
/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/extras/i386/ /opt/Centos/Centos/i386/extras/
/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/fasttrack/i386/ /opt/Centos/Centos/i386/fasttrack/
/usr/bin/rsync -avrt --delete rsync://rsync.muug.mb.ca/centos/5.4/contrib/i386/ /opt/Centos/Centos/i386/contrib/
#/usr/bin/rsync -avrtzH --delete --exclude=SRPMS/ --exclude=x86_64/ --exclude=isos/ rsync://rsync.muug.mb.ca/centos/5.4/ /var/ftp/Centos/
/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/updates/x86_64/ /opt/Centos/Centos/x86_64/updates/
#/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/os/x86_64/ /opt/Centos/Centos/x86_64/os/
/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/addons/x86_64/ /opt/Centos/Centos/x86_64/addons/
/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/centosplus/x86_64/ /opt/Centos/Centos/x86_64/centosplus/
/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/extras/x86_64/ /opt/Centos/Centos/x86_64/extras/
/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/fasttrack/x86_64/ /opt/Centos/Centos/x86_64/fasttrack/
/usr/bin/rsync -avrtzH --delete rsync://rsync.muug.mb.ca/centos/5.4/contrib/x86_64/ /opt/Centos/Centos/x86_64/contrib/
作一个计划任务,保持和网上时时同步
[root@host30 rsync]# crontab -l
50 17 */1 * * /export/rsync/sync_yum_source.sh &
[root@host30 rsync]#
这些做好了,现在要实现连上本地源了repo文件是CentOS中yum源的配置文件
这个是i386的repo文件
[root@host30 yum.repos.d]# cat Centos-host30.repo
[updates]
name=CentOS-$releasever - updates
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[base]
name=CentOS-$releasever - base
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[fasttrack]
name=CentOS-$releasever - fasttrack
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - extras
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - contrib
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - centosplus
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - addons
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
这个是x86_64的repo文件
[root@host30 ftp]# cat Centos-x86_64.repo
[updates]
name=CentOS-$releasever - updates
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[base]
name=CentOS-$releasever - base
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[fasttrack]
name=CentOS-$releasever - fasttrack
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[extras]
name=CentOS-$releasever - extras
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[contrib]
name=CentOS-$releasever - contrib
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[centosplus]
name=CentOS-$releasever - centosplus
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
[addons]
name=CentOS-$releasever - addons
baseurl=
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
现在只要将本地的repo文件拷贝到需要更新的机器的/etc/yum.repos.d目录下
就可以实现在本地更新了