基于cobbler搭建本地的yum仓库源

概述:

前面的文章已经大致描述并配置了通过cobbler服务结合PXE+Kickstart+DHCP+TFTP+HTTP无人值守安装多系统的自动化运维安装系统服务;利用这一特性,cobbler还有一个妙用,用来搭建(同步)本好的yum源仓库;用来统一安装更新本地的(IDC)系统软件与第三方软件仓库;
需要用到的无非还是cobbler rsync httpd,本文是线上部署时的整理笔记,旨在备忘与分享,如有错误和遗漏欢迎指正~

安装配置:
由于基于cobbler所以请参考前前方自动化运维之cobbler安装多版本系统
因此只介绍如何基于httpd服务同步更新源,需要安装的cobbler及配置,httpd安装启动好即可配置成本地的更新源;
添加同步及管理本地yum源主要用到cobbler repo 相关命令
cobbler repo命令说明:

# cobbler repo
cobbler repo add    #添加yum源
cobbler repo copy
cobbler repo edit
cobbler repo find
cobbler repo list       #列出已添加的yum源
cobbler repo remove  #删除已添加的本地yum源
cobbler repo rename  #重命名本地已添加的源
cobbler repo report     #列出全部源的详细信息

添加本地仓库:

cobbler repo add --name=Centos6-UPDATES --mirror=http://mirrors.aliyun.com/centos/6/updates/x86_64/
cobbler repo add --name=Centos6-salt201611 --mirror=https://repo.saltstack.com/yum/redhat/6/x86_64/2016.11/
cobbler repo add --name=Centos7-extras  --mirror=https://mirrors.aliyun.com/centos/7/extras/x86_64/
cobbler repo add --name=epel6-x86_64-testing --mirror=http://mirrors.aliyun.com/epel/testing/6/x86_64/
cobbler repo add --name=Centos7-salt201707  --mirror=https://repo.saltstack.com/yum/redhat/7Server/x86_64/2017.7/
cobbler repo add --name=Centos6-Base --mirror=http://mirrors.aliyun.com/centos/6/os/x86_64/
cobbler repo add --name=epel6-x86_64 --mirror=http://mirrors.aliyun.com/epel/6/x86_64/
cobbler repo add --name=Centos7-epel --mirror=https://mirrors.aliyun.com/epel/7Server/x86_64/
cobbler repo add --name=Centos6-webtatic --mirror=http://sp.repo.webtatic.com/yum/el6/x86_64/
cobbler repo add --name=Centos7-webtatic --mirror=https://sp.repo.webtatic.com/yum/el7/x86_64/
cobbler repo add --name=Centos6-percona  --mirror=http://repo.percona.com/release/6Server/os/x86_64/
cobbler repo add --name=Centos7-salt201611 --mirror=https://repo.saltstack.com/yum/redhat/7/x86_64/2016.11/
cobbler repo add --name=Centos7-zabbix3 --mirror=http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/
cobbler repo add --name=Centos6-extras  --mirror=http://mirrors.aliyun.com/centos/6/extras/x86_64/
cobbler repo add --name=Centos6-zabbix3 --mirror=http://repo.zabbix.com/zabbix/3.4/rhel/6/x86_64/
cobbler repo add --name=Centos7-percona --mirror=http://repo.percona.com/release/7Server/os/x86_64/

查看已经添加的仓库

[root@localhost repo_mirror]# cobbler repo list
   Centos6-Base
   Centos6-UPDATES
   Centos6-extras
   Centos6-percona
   Centos6-salt201611
   Centos6-webtatic
   Centos6-zabbix3
   Centos7-Base
   Centos7-epel
   Centos7-extras
   Centos7-percona
   Centos7-salt201611
   Centos7-salt201707
   Centos7-webtatic
   Centos7-zabbix3
   epel6-x86_64
   epel6-x86_64-testing

添加好以上各种镜像源后可以通过
#cobbler reposync 命令开始同步所有的镜像源到本地
也可以指定仓库名同步,(cobbler reposync --only=“仓库名”)由于 同步所有需要时间比较长,故这里只指定更新同步一个源做演示,其他的原理一样,以同步Centos7-zabbix3为例

# cobbler reposync --only=Centos7-zabbix3
task started: 2018-06-18_102322_reposync
task started (id=Reposync, time=Mon Jun 18 10:23:22 2018)
hello, reposync
run, reposync, run!
creating: /var/www/cobbler/repo_mirror/Centos7-zabbix3/config.repo
creating: /var/www/cobbler/repo_mirror/Centos7-zabbix3/.origin/Centos7-zabbix3.repo
running: /usr/bin/reposync -l -n -d --config=/var/www/cobbler/repo_mirror/Centos7-zabbix3/.origin/Centos7-zabbix3.repo --repoid=Centos7-zabbix3 --download_path=/var/www/cobbler/repo_mirror -a x86_64
2.9 kB     00:00     
3.6 kB     00:00     
......以下省略....

由于这个仓库不大同步到本地很快,默认同步到/var/www/cobbler/repo_mirror/下
如图:
基于cobbler搭建本地的yum仓库源

此时就可以在浏览器上访问:
http://172.16.0.4/cobbler/repo_mirror/Centos7-zabbix3/ 如图:
基于cobbler搭建本地的yum仓库源

制作本地的repo 在其他本地机器上制作

#cat local.repo
[root@localhost yum.repos.d]# cat local.repo 
[local]
name=local CentOS7 zabbix34
baseurl=http://172.16.0.4/cobbler/repo_mirror/Centos7-zabbix3/
enable=1
gpgcheck=0

查看:
# yum clean all
# yum makecache
# yum repolist

如图:
基于cobbler搭建本地的yum仓库源

接下来就可以愉快的把这个local.repo分发到所有内部(能访问这个cobbler服务器)机器上,当作zabbix本地源使用了,这里只添加了zabbix,还可以同步以上添加的镜像库,全部同步到本地后制作针对centos6 centos7的本地理更新源!
添加计划任务每天凌晨1点同步所有源到本地(由于基于rsync,同步时自动保持一致)

# crontab -l
1 1 * * *  /bin/cobbler reposync >/dev/null

至此一个本地的yum源仓库完成;如果觉得不错点个赞啊!

扫描二维码关注公众号,回复: 1621458 查看本文章

猜你喜欢

转载自blog.51cto.com/dyc2005/2130240