2018年第12周-yum私库搭建
此实验过程仅在centos上实践过 先顶一下角色,假设我有三台服务器A,B,C。 安装步骤1.在服务器A备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup 2.在服务器A下载新的CentOS-Base.repo 到/etc/yum.repos.d/ # CentOS 5 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-5.repo # CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo # CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 在这里,我们只有6和7版本的centos,于是我们下载centos6和centos7的Centos-Base.repo,这时候需进去修改下centos7的名字 # CentOS 6 wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo # CentOS 7 wget -O /etc/yum.repos.d/CentOS-Base-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo 在服务器A修改CentOS-Base-7.repo,把$releasever都改为7 vim /etc/yum.repos.d/CentOS-Base-7.repo [base-7] name=CentOS-7 - Base - mirrors.aliyun.com failovermethod=priority baseurl=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=os gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates [updates-7] name=CentOS-7 - Updates - mirrors.aliyun.com failovermethod=priority baseurl=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=updates gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras-7] name=CentOS-7 - Extras - mirrors.aliyun.com failovermethod=priority baseurl=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=extras gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages [centosplus-7] name=CentOS-7 - Plus - mirrors.aliyun.com failovermethod=priority baseurl=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=centosplus gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #contrib - packages by Centos Users [contrib] name=CentOS-$releasever - Contrib - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/ #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 3.在服务器A安装apache http服务器,可参考文章https://segmentfault.com/a/11... reposync -r base-7 -p /var/www/html/ reposync命令不存在则需安装: yum-utils createrepo yum-plugin-priorities -y reposync命令是一个python脚本。包含在yum-utils包中。 createrepo -pdo /var/www/html/base-7/ /var/www/html/base-7/ 6.这时候就能访问http://serverA/base-7 看到目录信息了 7.然后配置服务器B,在服务器B的/etc/yum.repos.d/下,删除(备份)其他repo文件,新建一个base.repo文件,内容如下: [base] name=base baseurl=http://server/base-7 enabled=1 gpgcheck=0 8.然后在服务器B清除yum缓存信息 yum clean all 9.在服务器B缓存yum库新信息,这时候就能看到新的base库信息 yum makecache 更新步骤1.在服务器A更新base-7库的信息,在服务器A执行一下命令: reposync -d -r base-7 -p /var/www/html/ #同步镜像源 2.在服务器A更新base-7库的索引信息,在服务器A执行一下命令: createrepo --update /var/www/html/epel #每次添加新的rpm时,必须更新epel索引信息 3.在服务器A,上述步骤可以生成一个文件yum-update.sh,每周定时执行一下 #!/bin/bash datetime=`date +"%Y-%m-%d"` #exec > /var/log/epel.log #同步日志输出 reposync -d -r epel -p /var/www/html/ #同步镜像源 if [ $? -eq 0 ];then createrepo --update /var/www/html/epel #每次添加新的rpm时,必须更新epel索引信息 echo "SUCESS: $datetime epel update successful" else echo "ERROR: $datetime epel update failed" fi reposync -d -r base -p /var/www/html/ #同步镜像源 if [ $? -eq 0 ];then createrepo --update /var/www/html/base #每次添加新的rpm时,必须更新epel索引信息 echo "SUCESS: $datetime base update successful" else echo "ERROR: $datetime base update failed" fi 4.在服务器A,更改yum-update.sh文件权限,并添加定时任务 chmod u+x /root/yum-update.sh crontab -e 0 3 * * 6 /bin/bash /root/yum-update.sh 举一反十类似的,服务器C虽然是centos6.5,与服务器B不太一样,但服务器A的也可以继续创建base6的私库,由于服务器A的CentOS-Base.repo就已经是centos6的库,所以直接执行 reposync -r base -p /var/www/html/ 然后后续过程就和上面的一样了。 除了base库,我们还可以将epel库,cdh库等,私有化。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |