构建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
相关文章
相关标签/搜索