創建yum本地倉庫,將阿裏倉庫同步到本地,並定時更新
阿新 • • 發佈:2018-02-28
nal 成了 creat yum .com for 我們 extend sed
很多時候為了加速自己內部的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倉庫
創建yum本地倉庫,將阿裏倉庫同步到本地,並定時更新