學以至用,纔是認證的目的。仍是那句話,咱們要去證實證書的含金量,而不是用證書來證實本身。html
要解決的痛點:centos
1.裝機費時費力,完成公司環境統一配置重複枯燥。
緩存
PXE自動化安裝,並使用kickstart的%post腳本完成統一配置。bash
2.公司出口帶寬限制,下載速度慢,重複下載浪費帶寬。
ide
3.本身開發的應用管理分散,易出錯。
工具
出路:
post
建立本地源,裝機時經過%post腳本或者其它工具共享給須要的機器。
ui
a.使用安裝光盤創建基本base源。
this
優勢:不須要下載。缺點:rpm較舊。
url
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
命令自己格式很簡單,跟上一步建立的頂級目錄便可。
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