yum倉庫搭建分爲以下幾步驟:
1、蒐集rpm包
2、安裝httpd 服務
3、生成rpm包的依賴關係
4、創建配置文件
5、測試
步驟:
首先檢查系統的版本:
[root@m01 ~]# uname -r 2.6.32-573.el6.x86_64 [root@m01 ~]# cat /etc/centos-release CentOS release 6.7 (Final)
1、蒐集rpm包
[root@web02 ~]# grep "keepcache=0" /etc/yum.conf keepcache=0 [root@web02 ~]# sed -i 's#keepcache=0#keepcache=1#g' /etc/yum.conf [root@web02 ~]# grep "keepcache=1" /etc/yum.conf keepcache=1
提前創建好目錄,把所有的rpm包都統一放到/var/www/html/centos下(httpd 的默認訪問路徑是/var/www/html) [root@m01 yum.repos.d]# mkdir /var/www/html/centos
修改keepcache=1後,以後每次再yum安裝的rpm包都會默認存到本地,使用
find / -type f -name "*.rpm" |xargs -i mv {} /var/www/html/centos
[root@web02 yum.repos.d]# yumdownloader dhcp 已加載插件:fastestmirror Loading mirror speeds from cached hostfile centos | 2.9 kB 00:00 centos/primary_db | 56 kB 00:00 dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm | 823 kB 00:00 [root@web02 yum.repos.d]# ls bak dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm oldboy.repo
2、安裝httpd 服務
[root@m01 yum.repos.d]# yum -y install httpd
[root@m01 ~]# /etc/init.d/httpd start 正在啓動 httpd:httpd: Could not reliably determine the server's fully qualified domain name, using 172.16.1.61 for ServerName [確定]
3、生成rpm包的依賴關係
[root@m01 html]# cd /var/www/html/centos/ [root@m01 centos]# createrepo . #使用createrepo命令生成rpm包依賴關係 Spawning worker 0 with 78 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@m01 centos]# ls repodata/ #當前目錄下會自動創建repodata目錄,目錄內有以下文件 285b777c14d998d3e74320f744a7d9b4f19878960caaf43ffb4f4bec4b2c28e0-filelists.xml.gz 702c65d1e7598653eb04b7c964caf7a0c50eb39aa7f90fb298824f73186bd2d2-filelists.sqlite.bz2 83de689974912c613cbe052307ca736e49c51d36cb008f1012793ae95aee1fa2-primary.sqlite.bz2 b1e874353d11d75247937b73761a47de5a0b21af1ac2fe1a12f17b83e9e018c0-other.sqlite.bz2 bc994749d127935f2aadef680edce4922d2d590bca1dbad8a8982872426a88ef-other.xml.gz e34bfa8116770f2b12eba92c08a5ef00b3f0b72e1d6ee65c9b39a08c844ae89d-primary.xml.gz repomd.xml
當yum倉庫包更新了以後,使用“createrepo --update rpm包目錄” 命令更新yum 倉庫包的依賴關係
4、創建配置文件(名字隨意,只要是以.repo結尾的就可以)
[root@m01 ~]# cat /etc/yum.repos.d/oldboy.repo [oldboyedu] name=Server baseurl=http://10.0.0.61/centos enable=1 gpgcheck=0
說明:
[oldboyedu] #倉庫名稱 name=Server #名稱隨便寫 baseurl=http://10.0.0.61/centos #yum倉庫的地址 如果是本機使用的話,可以寫成 baseurl=file:///var/www/html/centos/ 是通用地址,本機可以這樣設置,客戶端也是這樣設置 enable=1 #啓用倉庫 gpgcheck=0 #不啓用校驗
5、測試
使用yum list 可以顯示出倉庫裏的所有安裝包和可以安裝的哪些包,此刻yum倉庫搭建成功
[root@m01 centos]# yum list 已加載插件:fastestmirror, security Loading mirror speeds from cached hostfile 已安裝的軟件包 ConsoleKit.x86_64 0.4.1-3.el6 @anaconda-CentOS-201508042137.x86_64/6.7 ConsoleKit-libs.x86_64 0.4.1-3.el6 @anaconda-CentOS-201508042137.x86_64/6.7 MAKEDEV.x86_64 3.24-6.el6 @anaconda-CentOS-201508042137.x86_64/6.7 ..... 可安裝的軟件包 curl.x86_64 7.19.7-52.el6 oldboyedu dhclient.x86_64 12:4.1.1-51.P1.el6.centos oldboyedu dhcp.x86_64 12:4.1.1-51.P1.el6.centos oldboyedu dhcp-common.x86_64 12:4.1.1-51.P1.el6.centos oldboyedu fontconfig-devel.x86_64 2.8.0-5.el6 oldboyedu freetype.x86_64 2.3.11-17.el6 oldboyedu
安裝軟件包:
[root@m01 ~]# yum -y install dhcp 已加載插件:fastestmirror, security 設置安裝進程 Loading mirror speeds from cached hostfile 解決依賴關係 --> 執行事務檢查 ---> Package dhcp.x86_64 12:4.1.1-51.P1.el6.centos will be 安裝 --> 處理依賴關係 dhcp-common = 12:4.1.1-51.P1.el6.centos,它被軟件包 12:dhcp-4.1.1-51.P1.el6.centos.x86_64 需要 --> 處理依賴關係 portreserve,它被軟件包 12:dhcp-4.1.1-51.P1.el6.centos.x86_64 需要 --> 執行事務檢查 ---> Package dhcp-common.x86_64 12:4.1.1-49.P1.el6.centos will be 升級 --> 處理依賴關係 dhcp-common = 12:4.1.1-49.P1.el6.centos,它被軟件包 12:dhclient-4.1.1-49.P1.el6.centos.x86_64 需要 ---> Package dhcp-common.x86_64 12:4.1.1-51.P1.el6.centos will be an update ---> Package portreserve.x86_64 0:0.0.4-11.el6 will be 安裝 --> 執行事務檢查 ---> Package dhclient.x86_64 12:4.1.1-49.P1.el6.centos will be 升級 ---> Package dhclient.x86_64 12:4.1.1-51.P1.el6.centos will be an update --> 完成依賴關係計算 依賴關係解決 ===================================================================================================================================== 軟件包 架構 版本 倉庫 大小 ===================================================================================================================================== 正在安裝: dhcp x86_64 12:4.1.1-51.P1.el6.centos oldboyedu 823 k 爲依賴而安裝: portreserve x86_64 0.0.4-11.el6 oldboyedu 23 k 爲依賴而更新: dhclient x86_64 12:4.1.1-51.P1.el6.centos oldboyedu 321 k dhcp-common x86_64 12:4.1.1-51.P1.el6.centos oldboyedu 144 k 事務概要 ===================================================================================================================================== Install 2 Package(s) Upgrade 2 Package(s) 總下載量:1.3 M 下載軟件包: (1/4): dhclient-4.1.1-51.P1.el6.centos.x86_64.rpm | 321 kB 00:00 (2/4): dhcp-4.1.1-51.P1.el6.centos.x86_64.rpm | 823 kB 00:00 (3/4): dhcp-common-4.1.1-51.P1.el6.centos.x86_64.rpm | 144 kB 00:00 (4/4): portreserve-0.0.4-11.el6.x86_64.rpm | 23 kB 00:00 ------------------------------------------------------------------------------------------------------------------------------------- 總計 16 MB/s | 1.3 MB 00:00 運行 rpm_check_debug 執行事務測試 事務測試成功 執行事務 Warning: RPMDB altered outside of yum. 正在升級 : 12:dhcp-common-4.1.1-51.P1.el6.centos.x86_64 1/6 正在安裝 : portreserve-0.0.4-11.el6.x86_64 2/6 正在安裝 : 12:dhcp-4.1.1-51.P1.el6.centos.x86_64 3/6 正在升級 : 12:dhclient-4.1.1-51.P1.el6.centos.x86_64 4/6 清理 : 12:dhclient-4.1.1-49.P1.el6.centos.x86_64 5/6 清理 : 12:dhcp-common-4.1.1-49.P1.el6.centos.x86_64 6/6 Verifying : 12:dhclient-4.1.1-51.P1.el6.centos.x86_64 1/6 Verifying : portreserve-0.0.4-11.el6.x86_64 2/6 Verifying : 12:dhcp-common-4.1.1-51.P1.el6.centos.x86_64 3/6 Verifying : 12:dhcp-4.1.1-51.P1.el6.centos.x86_64 4/6 Verifying : 12:dhcp-common-4.1.1-49.P1.el6.centos.x86_64 5/6 Verifying : 12:dhclient-4.1.1-49.P1.el6.centos.x86_64 6/6