学以致用,才是认证的目的。还是那句话,我们要去证明证书的含金量,而不是用证书来证明自己。

    要解决的痛点:

    1.装机费时费力,完成公司环境统一配置重复枯燥。

    PXE自动化安装,并使用kickstart的%post脚本完成统一配置。

    2.公司出口带宽限制,下载速度慢,重复下载浪费带宽。

    3.自己开发的应用管理分散,易出错。

    出路:

    创建本地源,装机时通过%post脚本或者其它工具共享给需要的机器。

    a.使用安装光盘建立基本base源。

    优点:不需要下载。缺点:rpm较旧。

    b.保留yum缓存,使用createrepo创建个性化需求的仓库。

    优点:只创建需要的rpm,不会浪费空间存储根本不需要的rpm。

    缺点:需要在/etc/yum.conf启用keepcache,所有缓存的rpm需要汇总到一台主机上创建索引。

    c.rsync从公网同步。

    优点:配合cronjob很方便实现自动化,节省流量并且保持和上游同步。

    缺点:不少新项目有自己的仓库但是不支持rsync。

    d.reposync拉取特定repo。

    优点:只拉取需要的,节省宽带和硬盘。方便控制版本。

    缺点:暂时没想到。

    工具:

    createrepo, yum-utils, yum, rsync

    方法:

    a. rsync+crontab

    参考centos官方创建公网镜像文档。

    https://wiki.centos.org/zh/HowTos/CreatePublicMirrors

    cat /etc/cron.daily/syncYum.cron

     

#!/bin/bash

localpath="/var/www/html/CentOS"

mirror="rsync://mirrors.yun-idc.com/centos"

rsync="rsync -avzH --delete --progress"


verlist="7 7.0.1406 7.1.1503 7.2.1511"

baselist="centosplus extras fasttrack  updates cloud"

archlist="x86_64"


for ver in $verlist

do

    for base in $baselist

    do

        for arch in $archlist

        do

            remote=$mirror/$ver/$base/$arch/

            mkdir -pv $localpath/$ver/$base/$arch/

            $rsync $remote $localpath/$ver/$base/$arch/

        done

    done

done

    b. createrepo

    http://yum.baseurl.org/wiki/RepoCreate

    

    Collect the packages together in one directory. You can make as many     sub-    directories as you want, but there needs to be a top level directory     where they all live. That's where we're going to form our repository.

    所有的包放在一个目录里,目录里可以放置多个子目录。但我们需要一个统一的目录来创建包

    之间依赖的索引。

Once you have createrepo installed you need to run it. It only requires one argument which is the directory in which you would like to generate the repository data. So if the packages directory we made in step 1 is in /srv/my/repo then you would run:

    createrepo /srv/my/repo

命令本身格式很简单,跟上一步创建的顶级目录即可。

  1. To make this repository known to yum you need to add a .repo file to your yum configuration. On the systems where you want to use this repo you need to make a new file in/etc/yum.repos.d/. The file can be named anything but the extension on the file has to be .repo. Let's call this one 'myrepo.repo'.

In the file you just need to include the following:

   [myrepo]
   name = This is my repo
   baseurl = url://to/get/to/srv/my/repo/

That's all you need in that file. The 'baseurl' line is the path that machine uses to get to the repository. If the machine has direct access to it or mounts it as a filesystem you can use a baseurl line like:

     baseurl = file:///srv/my/repo/

NB: there are 3 slashes (/) following the file:, not 2. That is correct.


If you access the file via an http or https server you would use something like:

     baseurl = http://servername/my/repo

创建repo文件

Now, every time you modify, remove or add a new RPM package to /srv/my/repo you need to recreate the repository metadata. You do that by running createrepo the same way you did in step 2

每次文件有变更需要重新创建索引。

    c.reposync

    以openstack rdo为例

    安装源

    yum -y install https://www.rdoproject.org/repos/rdo-release.rpm

    查看仓库 

    yum repolist

    同步仓库

    reposync