1. 程式人生 > >創建yum本地倉庫,將阿裏倉庫同步到本地,並定時更新

創建yum本地倉庫,將阿裏倉庫同步到本地,並定時更新

nal 成了 creat yum .com for 我們 extend sed

很多時候為了加速自己內部的rpm包安裝速度,都會搭建自己的yum源倉庫,而使用系統光盤自帶的源,由於軟件版本比較落後,所以不太適用,而大家都在用的阿裏倉庫比較好用,所以就想到了把阿裏倉庫的rpm全部拉到本地,並做yum倉庫的定時更新。這樣既能保證軟件包是最新的,也能保證軟件的安裝速度。那麽下面來具體實施,搭建自己的yum本地倉庫,並定時從阿裏倉庫同步過來。

第一步:下載阿裏鏡像的repo安裝包,centos6就下載6的,7的就下載7的地址:https://mirrors.aliyun.com/repo/

我們以centos7的鏡像為例

  1. cd /etc/yum.repos.d/
  2. mkdir bak
  3. mv Centos* bak #將系統自帶的源備份到bak目錄下
  4. wget https://mirrors.aliyun.com/repo/Centos-7.repo
  5. cat Centos-7.repo
  6. # CentOS-Base.repo
  7. #
  8. # The mirror system uses the connecting IP address of the client and the
  9. # update status of each mirror to pick mirrors that are updated to and
  10. # geographically close to the client. You should use this for CentOS updates
  11. # unless you are manually picking other mirrors.
  12. #
  13. # If the mirrorlist= does not work for you, as a fall back you can try the
  14. # remarked out baseurl= line instead.
  15. #
  16. #
  17. [base]
  18. name=CentOS-$releasever - Base - mirrors.aliyun.com
  19. failovermethod=priority
  20. baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
  21. http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
  22. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
  23. gpgcheck=1
  24. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  25. #released updates
  26. [updates]
  27. name=CentOS-$releasever - Updates - mirrors.aliyun.com
  28. failovermethod=priority
  29. baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
  30. http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
  31. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
  32. gpgcheck=1
  33. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  34. #additional packages that may be useful
  35. [extras]
  36. name=CentOS-$releasever - Extras - mirrors.aliyun.com
  37. failovermethod=priority
  38. baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
  39. http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
  40. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
  41. gpgcheck=1
  42. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  43. #additional packages that extend functionality of existing packages
  44. [centosplus]
  45. name=CentOS-$releasever - Plus - mirrors.aliyun.com
  46. failovermethod=priority
  47. baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
  48. http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  49. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
  50. gpgcheck=1
  51. enabled=0
  52. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
  53. #contrib - packages by Centos Users
  54. [contrib]
  55. name=CentOS-$releasever - Contrib - mirrors.aliyun.com
  56. failovermethod=priority
  57. baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
  58. http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
  59. #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=contrib
  60. gpgcheck=1
  61. enabled=0
  62. gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

已經配置好的阿裏倉庫

  1. yum repolist #查看阿裏的可用倉庫,有啟用的表示已經成功了
  2. 從阿裏服務器將rpm同步到本地需要兩個rpm軟件createrepo 和 yum-utils
  3. yum install createrepo yum-utils -y #yum安裝這兩個包
  4. mkdir -p /mirrors/Packege #創建rpm包的存放目錄
  5. reposync -r base -p /mirrors/Packege #將已經配置好的阿裏倉庫鏡像內的rpm包拉到本地,b ase為本地已經配置好的倉庫名,可以用yum repolist查看到
  6. createrepo -pdo /mirrors/ /mirrors/Packege #創建repo數據庫

###############################同步rpm包,需要相當長一段時間################################ 同步完成之後,本地的yum倉庫已經基本完成了,只剩下定時更新了
  1. vim /cron/repository.sh #編寫同步腳本
  2. reposync -r base -p /mirrors/Packege -d #來刪除本地老舊
  3. reposync -r base -p /mirrors/Packege
  4. crontab -e #添加定時任務
  5. 0 0 1 * * sh /cron/repository.sh #每月1日0時更新yum倉庫

創建yum本地倉庫,將阿裏倉庫同步到本地,並定時更新