当前位置: 首页 > Linux

2018年第12周-yum私库搭建

时间:2023-04-06 03:19:44 Linux

本实验过程只在centos上实践过。让我们先推角色。假设我有A、B、C三台服务器,A服务器是centos6.5版本,target:我想把它当作yum私有库服务器B是centos7.2版本,target:yum安装包的时候,确实不是从网上获取安装包信息,而是从服务器A获取安装包信息安装服务器C是centos6.5版本,目标:安装yum包时,不从网上获取安装包信息,而是获取安装包从服务器A获取安装信息安装步骤1.备份服务器A上的mv/etc/yum.repos.d/CentOS-Base.repo/etc/yum.repos.d/CentOS-Base.repo.backup2。在服务器A上下载新的CentOS-Base.repo到/etc/yum.repos.d/#CentOS5wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-5.repo#CentOS6wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo#CentOS7wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun。com/repo/Centos-7.repo在这里,我们只有6和7版本的centos,所以我们下载centos6和centos7的Centos-Base.repo,然后我们需要进去修改centos7的名字#CentOS6wget-O/etc/yum.repos.d/CentOS-Base.repohttp://mirrors.aliyun.com/repo/Centos-6.repo#CentOS7wget-O/etc/yum.repos.d/CentOS-Base-7.repohttp://mirrors.aliyun.com/repo/Centos-7.repo在服务器A修改CentOS-Base-7.repo,设置$releasever改为7vim/etc/yum.repos.d/CentOS-Base-7.repo[base-7]name=CentOS-7-Base-mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/7/os/$basearch/http://mirrors.aliyuncs.com/centos/7/os/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=osgpgcheck=1gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#releasedupdates[updates-7]name=CentOS-7-更新-mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/7/updates/$basearch/http://mirrors.aliyuncs.com/centos/7/updates/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updatesgpgcheck=1gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#可能有用的附加包[extras-7]name=CentOS-7-附加-mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/7/extras/$basearch/http://mirrors.aliyuncs.com/centos/7/extras/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extrasgpgcheck=1gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additionalpackagesthatextendthefunctionalityofexistingpackages[centosplus-7]name=CentOS-7-Plus-mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/7/centosplus/$basearch/http://mirrors.aliyuncs.com/centos/7/centosplus/$basearch/#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplusgpgcheck=1enabled=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#contrib-Centos用户的软件包[contrib]name=CentOS-$releasever-贡献-mirrors.aliyun.comfailovermethod=prioritybaseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/#镜像列表=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contribgpgcheck=1enabled=0gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-73。在服务器A上安装Apachehttp服务器,请参考文章https://segmentfault.com/a/11...4.在服务器A上下载所有程序安装包,进入http服务器目录。这个过程会花很长时间reposync-rbase-7-p如果/var/www/html/reposync命令不存在需要安装:yum-utilscreaterepoyum-plugin-priorities-yreposync命令是一个python脚本。包含在yum-utils包中。此过程可能需要安装reposync5。在服务器A上创建base-7索引createrepo-pdo/var/www/html/base-7//var/www/html/base-7/6,此时可以访问http://serverA/base-7查看目录信息7.然后配置serverB,删除(备份)serverB/etc/yum.repos.d/下的其他repo文件,新建base.repo文件,内容如下:[base]name=basebaseurl=http://server/base-7enabled=1gpgcheck=08.然后yumcleanall9清除服务器B上的yum缓存信息。在服务器B上缓存新的yum库信息,此时可以看到到新的基库信息yummakecache更新步骤1.更新服务器A上的base-7库信息,在服务器A上执行以下命令:reposync-d-rbase-7-p/var/www/html/#同步镜像源2.更新服务器A上base-7库的索引信息,在服务器A上执行命令:createrepo--update/var/www/html/epel  #每增加一个新的rpm,都要更新epel索引信息3.在服务器A上,以上步骤可以生成一个文件yum-update.sh,每周定时执行#!/bin/bashdatetime=`date+"%Y-%m-%d"`#exec>/var/log/epel.log  #同步日志输出reposync-d-repel-p/var/www/html/  #Synchronize镜像源if[$?-eq0];thencreaterepo--update/var/www/html/epel  #每增加一个新rpm,都要更新epel索引信息echo"SUCESS:$datetimeepelupdatesuccessful"elseecho"ERROR:$datetimeepelupdatefailed"fireposync-d-rbase-p/var/www/html/  #同步镜像源if[$?-eq0];thencreaterepo--update/var/www/html/base  #每增加一个新rpm,都要更新epel索引信息echo"SUCESS:$datetimebaseupdatesuccessful"elseecho"错误:$datetime基准更新失败”fi4.在服务器A上,更改yum-update.sh文件权限,添加定时任务chmodu+x/root/yum-update.shcrontab-e03**6/bin/bash/root/yum-update.sh类似,虽然服务器C是centos6.5和服务器B不一样,但是服务器A也可以继续创建base6私有库。由于服务器A的CentOS-Base.repo已经是centos6的库,直接执行reposync-rbase-p/var/www/html/,后续过程同上。除了基础库,我们还可以私有化epel库、cdh库等。