構建ubuntu12.十、centos6本地更新源

    在公司內部使用國內的16三、sohu等源的時候,發如今安裝軟件較多的時候,仍是有點慢,目前公司內部的openstack平臺上面跑了60多臺vm實例,按照趨勢還有增多的可能,確實須要搭建一套本地源。

    不少搭建本地源的案例都是把發行DVD中的rpm、deb包拷貝到本地,而後經過http協議進行訪問,DVD中的包都是沒有更新過的,而openstack項目更新仍是比較快的,尤爲是ubuntu常常更新東西仍是不少的,因此決定把國內的某個源拉一套到本地,而後天天定時同步更新。

1 搭建ubuntu 12.10源 web

  在debian/ubuntu下有個神器叫apt-mirror,該工具可讓你鏡像一部分或者所有發行版的apt sources到本地,apt-mirror具備如下特性:
        * It uses a config similar to apts sources.list
        * It's fully pool comply
        * It supports multithreaded downloading
        * It supports multiple architectures at the same time
        * It can automatically remove unneeded files
        * It works well on overloaded channel to internet
        * It never produces an inconsistent mirror including while mirroring
        * It works on all POSIX compliant systems with perl and wget

  如今讓咱們把sohu的ubuntu 12.10的源mirror到本地,先安裝apt-mirror工具: shell

apt-get install apt-mirror
   /etc/cron.d/apt-mirror  設置天天何時同步更新內容

   /etc/apt/mirror.list  mirror相關信息的配置 數據庫

   因爲源的內容比較多,並且比較重要,全部同步下來的源內容咱們不放在本地磁盤,而是在共享存儲上劃出一塊空間,掛載在宿主機上,這樣在宿主機宕機或者硬盤故障的時候,可使共享存儲的內容在其餘宿主機上繼續發揮做用,本編中掛載在/opt/apt-source目錄下。 apache

mirror.list配置以下:
set base_path    /opt/apt-source
set mirror_path  $base_path/mirror
set skel_path    $base_path/skel
set var_path     $base_path/var
set cleanscript $var_path/clean.sh
set defaultarch  <running host architecture>
set postmirror_script $var_path/postmirror.sh
set run_postmirror 0
set nthreads     40
set _tilde 0

deb-amd64 http://mirrors.sohu.com/ubuntu/  quantal  main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/  quantal-backports  main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/  quantal-proposed  main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/  quantal-security  main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/  quantal-updates  main restricted universe multiverse

deb-i386 http://mirrors.sohu.com/ubuntu/  quantal  main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/  quantal-backports  main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/  quantal-proposed  main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/  quantal-security  main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/  quantal-updates  main restricted universe multiverse

  開始在後臺同步sohu的源: ubuntu

nohup apt-mirror -c /etc/apt/mirror.list &
  同步完畢後,搭建web服務
apt-get install apache2
cd /var/www
ln -s /opt/apt-source/mirror/mirrors.sohu.com/ubuntu ubuntu
  把/etc/apt/sources.list文件的內容替換成以下(10.1.6.6):
deb http://10.1.6.6/ubuntu quantal main  multiverse restricted  universe
deb http://10.1.6.6/ubuntu quantal-backports main  multiverse restricted  universe
deb http://10.1.6.6/ubuntu quantal-proposed main  multiverse restricted  universe
deb http://10.1.6.6/ubuntu quantal-updates main  multiverse restricted  universe
deb http://10.1.6.6/ubuntu quantal-security main  multiverse restricted  universe

    若是在設置mirror.list時,源設置的是'deb http://',則默認是同步64位的包,可是有些包安裝時須要32位的支持,因此還須要同步32位的源,就如上面配置文件設置。 centos

  更新apt數據庫信息 緩存

apt-get update

2 搭建centos6源 工具

    在搞定完ubuntu以後,想按照上面的思路把centos也搞定,google一番後,沒發現centos下有類似的工具,只能另換方法,決定直接從官方把整個源同步下來,到mirrors.kernel.org上一看,提供了三種方式mirror sources:HTTP、FTP、RSYNC,那就用rsync把它所有同步下來吧。 post

經過下面腳本進行同步 google

#!/bin/sh
#rsync -avzL --delete -stats rsync://mirrors.kernel.org/centos/6/ /opt/apt-source/centos6/
rsync="/usr/bin/rsync -avzL --delete"
mirror=rsync://mirrors.kernel.org/centos

ver=6
arch="x86_64 i386"
base="os updates centosplus isos fasttrack extras cr contrib"
local=/opt/apt-source/centos6

for arch in $arch
do
  for base in $base
  do
    remote=$mirror/$ver/$base/$arch/
    if [ ! -e $local/$base/$arch ]; then
      mkdir -p "$local/$base/$arch"
    fi
    $rsync $remote $local/$base/$arch/
  done
done
    腳本放入後臺執行便可,同步完畢後,用以下內容替換centos6的/etc/yum.repos.d/CentOS-Base.repo內容便可。
[base]
name=CentOS - Base
baseurl=http://10.1.6.6/centos/6/os/$basearch/
gpgcheck=1
gpgkey=http://10.1.6.6/centos/6/os/$basearch/RPM-GPG-KEY-CentOS-6

#released updates
[update]
name=CentOS - Updates
baseurl=http://10.1.6.6/centos/6/updates/$basearch/
gpgcheck=1
gpgkey=http://10.1.6.6/centos/6/os/$basearch/RPM-GPG-KEY-CentOS-6

#released extras
[extras]
name=CentOS - Extras
baseurl=http://10.1.6.6/centos/6/extras/$basearch/
gpgcheck=1
gpgkey=http://10.1.6.6/centos/6/os/$basearch/RPM-GPG-KEY-CentOS-6

#released CentOSPlus
[centosplus]
name=CentOS - CentOSPlus
baseurl=http://10.1.6.6/centos/6/centosplus/$basearch/
gpgcheck=1
gpgkey=http://10.1.6.6/centos/6/os/$basearch/RPM-GPG-KEY-CentOS-6

#contrib - packages by Centos Users
[contrib]
name=CentOS - Contrib
baseurl=http://10.1.6.6/centos/6/contrib/$basearch/
gpgcheck=1
gpgkey=http://10.1.6.6/centos/6/os/$basearch/RPM-GPG-KEY-CentOS-6
更新yum源緩存信息
yum clean all
yum makecache
相關文章
相關標籤/搜索