很多时候为了加速自己内部的rpm包安装速度,都会搭建自己的yum源仓库,而使用系统光盘自带的源,由于软件版本比较落后,所以不太适用,而大家都在用的阿里仓库比较好用,所以就想到了把阿里仓库的rpm全部拉到本地,并做yum仓库的定时更新。这样既能保证软件包是最新的,也能保证软件的安装速度。那么下面来具体实施,搭建自己的yum本地仓库,并定时从阿里仓库同步过来。
第一步:下载阿里镜像的repo安装包,centos6就下载6的,7的就下载7的地址:https://mirrors.aliyun.com/repo/
我们以centos7的镜像为例
- cd /etc/yum.repos.d/
- mkdir bak
- mv Centos* bak #将系统自带的源备份到bak目录下
- wget https://mirrors.aliyun.com/repo/Centos-7.repo
- cat Centos-7.repo
- # CentOS-Base.repo
- #
- # The mirror system uses the connecting IP address of the client and the
- # update status of each mirror to pick mirrors that are updated to and
- # geographically close to the client. You should use this for CentOS updates
- # unless you are manually picking other mirrors.
- #
- # If the mirrorlist= does not work for you, as a fall back you can try the
- # remarked out baseurl= line instead.
- #
- #
- [base]
- name=CentOS-$releasever - Base - mirrors.aliyun.com
- failovermethod=priority
- baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
- http://mirrors.aliyuncs.com/centos/$releasever/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]
- name=CentOS-$releasever - Updates - mirrors.aliyun.com
- failovermethod=priority
- baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
- http://mirrors.aliyuncs.com/centos/$releasever/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]
- name=CentOS-$releasever - Extras - mirrors.aliyun.com
- failovermethod=priority
- baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
- http://mirrors.aliyuncs.com/centos/$releasever/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]
- name=CentOS-$releasever - Plus - mirrors.aliyun.com
- failovermethod=priority
- baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
- http://mirrors.aliyuncs.com/centos/$releasever/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
已经配置好的阿里仓库
- yum repolist #查看阿里的可用仓库,有启用的表示已经成功了
- 从阿里服务器将rpm同步到本地需要两个rpm软件createrepo 和 yum-utils
- yum install createrepo yum-utils -y #yum安装这两个包
- mkdir -p /mirrors/Packege #创建rpm包的存放目录
- reposync -r base -p /mirrors/Packege #将已经配置好的阿里仓库镜像内的rpm包拉到本地,b ase为本地已经配置好的仓库名,可以用yum repolist查看到
- createrepo -pdo /mirrors/ /mirrors/Packege #创建repo数据库
###############################同步rpm包,需要相当长一段时间################################
同步完成之后,本地的yum仓库已经基本完成了,只剩下定时更新了
- vim /cron/repository.sh #编写同步脚本
- reposync -r base -p /mirrors/Packege -d #来删除本地老旧
- reposync -r base -p /mirrors/Packege
- crontab -e #添加定时任务
- 0 0 1 * * sh /cron/repository.sh #每月1日0时更新yum仓库
原文地址:https://www.cnblogs.com/momenglin/p/8485678.html
时间: 2024-10-27 02:02:01