一、概念 1.rpm是什麼?在幫助文檔里我們可以看到,rpm的名字是rpm package manage 的縮寫, 從名字上看就可以知道rpm就是一個包管理工具。簡單說rpm包就是把一些程式編譯成二進位,和一些配置文件以及幫助文檔等一些程式所依賴庫打包在一起,這樣形成的一個包。rpm大大的簡化用戶在 ...
一、概念
1.rpm是什麼?在幫助文檔里我們可以看到,rpm的名字是rpm package manage 的縮寫, 從名字上看就可以知道rpm就是一個包管理工具。簡單說rpm包就是把一些程式編譯成二進位,和一些配置文件以及幫助文檔等一些程式所依賴庫打包在一起,這樣形成的一個包。rpm大大的簡化用戶在Linux上安裝軟體的複雜度。
2.rpm倉庫是什麼?從字面理解,倉庫就是集中存放東西的地方,同樣rpm倉庫就是集中存放rpm包的一個地方。這裡說的‘地方’就是伺服器。把很多rpm包放在一個特定的伺服器的特定目錄里, 再由比如http、nfs、ftp、file這些協議是用來提供給其他伺服器下載rpm包的伺服器,我們把這樣的伺服器稱為rpm倉庫伺服器。
3.yum是什麼?yum是Yellowdog Updater Modified 的縮寫,翻譯過來就是Yellowdog 更新修改,完全沒有搞懂這個翻譯到底是什麼意思,查下百度百科吧!yum是一個在Fedora、Redhat以及CentOS中的shell前端軟體包管理器。基於rpm包管理,能夠從指定的伺服器自下載rpm包並且安裝,可以自動處理包依賴關係,並且能夠一次安裝所有所依賴的軟體包,無需頻繁的一次次下載安裝。看了百度的解釋,我們應該知道yum是什麼了吧!簡單說就是基於rpm包的前端管理工具,它可以幫我們解決包與包的依賴關係。
4.yum的工作機制。yum是c/s架構的工作機制,服務端提供rpm倉庫,客戶端根據服務端提供的倉庫,通過特定協議去服務端下載所需要的包來進行安裝。第一次去服務端,它會把服務端的倉庫元數據緩存到本地,這樣就不需要每次下載都去服務端查詢。所謂倉庫的元數據就是記錄著該倉庫有哪些包,包名,包與包的依賴關係等一些數據。每次要裝包的時候,yum會去看看本地緩存的元數據,有沒有需要的包的信息,如果有,他們會把相應的包以及所依賴的包一併去服務端下載下來,一併安裝。
二、倉庫的搭建
瞭解了以上的基本概念,下麵我們開始來搭建rpm倉庫吧
1.創建目錄結構
[root@test ~]$mkdir -pv /rpm/centos/{6,7}/os/x86_64 mkdir: created directory `/rpm' mkdir: created directory `/rpm/centos' mkdir: created directory `/rpm/centos/6' mkdir: created directory `/rpm/centos/6/os' mkdir: created directory `/rpm/centos/6/os/x86_64' mkdir: created directory `/rpm/centos/7' mkdir: created directory `/rpm/centos/7/os' mkdir: created directory `/rpm/centos/7/os/x86_64'
說明:本次實驗是在centos6或centos7平臺架構是x86_64的系統上來創建的目錄
2.上傳包
[root@test ~]$cd /rpm/centos/6/os/x86_64/ [root@test x86_64]$pwd /rpm/centos/6/os/x86_64 [root@test x86_64]$mv /root/samba-3.6.23-41.el6.x86_64.rpm /root/vsftpd-2.2.2-24.el6.x86_64.rpm . [root@test x86_64]$cd ../../../7/os/x86_64/ [root@test x86_64]$pwd /rpm/centos/7/os/x86_64 [root@test x86_64]$mv /root/tomcat-7.0.76-2.el7.noarch.rpm /root/samba-4.6.2-8.el7.x86_64.rpm .
說明: 上傳了4個包,在/rpm/centos/6/os/x86_64/ 放了samba-3.6.23-41.el6.x86_64.rpm和vsftpd-2.2.2-24.el6.x86_64.rpm兩個包,在/rpm/centos/7/os/x86_64放了samba-4.6.2-8.el7.x86_64.rpm和tomcat-7.0.76-2.el7.noarch.rpm兩個包,本人先是把包傳到伺服器,然後移動到相應的目錄里。
3.創建元數據
首先要檢查自己的伺服器有沒有裝createrepo這個工具
[root@test x86_64]$rpm -q createrepo
package createrepo is not installed
如果沒有就安裝
[root@test x86_64]$yum install -y createrepo
創建倉庫元數據
[root@test ~]$createrepo /rpm/centos/6/os/x86_64/ Spawning worker 0 with 2 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@test ~]$createrepo /rpm/centos/7/os/x86_64/ Spawning worker 0 with 2 pkgs Workers Finished Gathering worker results Saving Primary metadata Saving file lists metadata Saving other metadata Generating sqlite DBs Sqlite DBs complete [root@test ~]$ll /rpm/centos/6/os/x86_64/ total 5368 drwxr-xr-x 2 root root 4096 Sep 8 16:18 repodata -rw-r--r--+ 1 root root 5331428 Sep 8 16:02 samba-3.6.23-41.el6.x86_64.rpm -rw-r--r--+ 1 root root 159332 Sep 8 16:02 vsftpd-2.2.2-24.el6.x86_64.rpm [root@test ~]$ll /rpm/centos/7/os/x86_64/ total 732 drwxr-xr-x 2 root root 4096 Sep 8 16:18 repodata -rw-r--r--+ 1 root root 647996 Sep 8 16:04 samba-4.6.2-8.el7.x86_64.rpm -rw-r--r--+ 1 root root 91820 Sep 8 16:04 tomcat-7.0.76-2.el7.noarch.rpm
說明:可以看到在兩個倉庫下各自生成了一個repodata的目錄,這裡說一下,要確定倉庫的路徑就是要看repodata這個目錄的父目錄是什麼,repodata目錄所在的父目錄就是倉庫的路徑。
4.在客戶端編寫repo配置文件
[root@test ~]$cd /etc/yum.repos.d/ [root@test yum.repos.d]$ls CentOS-Base.repo CentOS-Debuginfo.repo CentOS-fasttrack.repo CentOS-Media.repo CentOS-Vault.repo epel.repo epel-testing.repo [root@test yum.repos.d]$mkdir repo_bak [root@test yum.repos.d]$mv *.repo repo_bak [root@test yum.repos.d]$ls repo_bak
說明:本人採用的是客戶端服務端在同一臺設備上,為了不受其他repo配置文件的干擾,我們把以前的repo文件全部移動到另外一個備份目錄里,然後在/etc/yum.repo.d/ 下創建一個repo文件。
[my_base] name=this is test repo baseurl=file:///rpm/centos/$releasever/os/$basearch gpgcheck=0
說明:創建一個.repo的文件,將以上內容添加到該文件,解釋一下這個文件的內容,第一個中括弧里表示倉庫的名字,通常這個名字可以順便起,一般不建議裡面帶空格,name=表示倉庫的簡要說明,baseurl= 表示倉庫的路徑,也就是repodata所在的目錄的父目錄,gpgcheck=0表示不檢查包的gpg驗證,若gpgcheck=1表示要驗證。添加以上內容我們客戶端就可以根據以上定義的baseurl去伺服器倉庫里找相應的包。
5.在客戶端清除yum緩存,查看倉庫列表
[root@test yum.repos.d]$yum clean all Loaded plugins: fastestmirror, security Cleaning repos: my_base Cleaning up Everything Cleaning up list of fastest mirrors [root@test yum.repos.d]$yum repolist Loaded plugins: fastestmirror, security Determining fastest mirrors my_base | 2.9 kB 00:00 ... my_base/primary_db | 6.0 kB 00:00 ... repo id repo name status my_base this is test repo 2 repolist: 2
說明:可以看到我們剛纔配置的倉庫信息,repo id 就是我們剛纔在repo文件中寫的,也可看到裡面有2個包。看到以上信息就表示rpm倉庫在客戶端上的配置成功了。
6.裝包驗證
[root@test yum.repos.d]$yum install vsftpd Loaded plugins: fastestmirror, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package vsftpd.x86_64 0:2.2.2-24.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Installing: vsftpd x86_64 2.2.2-24.el6 my_base 156 k Transaction Summary =================================================================================================================================== Install 1 Package(s) Total download size: 156 k Installed size: 340 k Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : vsftpd-2.2.2-24.el6.x86_64 1/1 Verifying : vsftpd-2.2.2-24.el6.x86_64 1/1 Installed: vsftpd.x86_64 0:2.2.2-24.el6 Complete!
說明:本人以兩個包作為例子來演示搭建rpm的過程,可能裝這個包還有其他依賴包,但是倉庫裡面沒有其他依賴,可能會出現報錯的情況。
以上就是本地搭建repo倉庫的過程。
下麵我再說下如何搭建網路rpm倉庫
1.先安裝httpd web伺服器
[root@test yum.repos.d]$yum install httpd -y Loaded plugins: fastestmirror, security Setting up Install Process Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.7 kB 00:00 base/primary_db | 4.7 MB 00:00 epel | 5.3 kB 00:00 epel/primary_db | 6.1 MB 00:00 extras | 3.4 kB 00:00 extras/primary_db | 29 kB 00:00 updates | 3.4 kB 00:00 updates/primary_db | 5.7 MB 00:00 Resolving Dependencies --> Running transaction check ---> Package httpd.x86_64 0:2.2.15-69.el6.centos will be installed --> Finished Dependency Resolution Dependencies Resolved =================================================================================================================================== Package Arch Version Repository Size =================================================================================================================================== Installing: httpd x86_64 2.2.15-69.el6.centos base 836 k Transaction Summary =================================================================================================================================== Install 1 Package(s) Total download size: 836 k Installed size: 3.0 M Downloading Packages: httpd-2.2.15-69.el6.centos.x86_64.rpm | 836 kB 00:00 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : httpd-2.2.15-69.el6.centos.x86_64 1/1 Verifying : httpd-2.2.15-69.el6.centos.x86_64 1/1 Installed: httpd.x86_64 0:2.2.15-69.el6.centos Complete!
說明:httpd預設工作路徑在/var/www/html/ 下,也就是放html網頁代碼的地方。
2.在httpd 的工作路徑下 創建目錄結構
[root@test ~]$mkdir -pv /var/www/html/centos/{6,7}/os/x86_64 mkdir: created directory `/var/www/html/centos' mkdir: created directory `/var/www/html/centos/6' mkdir: created directory `/var/www/html/centos/6/os' mkdir: created directory `/var/www/html/centos/6/os/x86_64' mkdir: created directory `/var/www/html/centos/7' mkdir: created directory `/var/www/html/centos/7/os' mkdir: created directory `/var/www/html/centos/7/os/x86_64'
3.掛載安裝光碟到相應的位置
[root@test ~]$mount /dev/sr0 /var/www/html/centos/6/os/x86_64/ mount: block device /dev/sr0 is write-protected, mounting read-only
說明:我這裡只掛載了centos6的一個安裝光碟,centos7下麵的目錄也可以使用同樣的方式掛載centos7的安裝光碟,這裡用centos6作為演示。這裡還要說一下安裝光碟本身就有repodata目錄,我們這裡就不需要再創建元數據信息。
4.開啟httpd
[root@test ~]$/etc/init.d/httpd start Starting httpd: httpd: apr_sockaddr_info_get() failed for test httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName [ OK ]
5.客戶端配置repo文件
[my_base] name=this is test repo baseurl=http://127.0.0.1/centos/$releasever/os/$basearch gpgcheck=0
說明:這裡只需要把倉庫的路徑改成以http的協議方式去獲取,當然為了不受其他yum源的影響,本次實驗我們也要把其他的repo文件放在一個備份目錄。
6.客戶端清除yum緩存,並查看倉庫列表
[root@test x86_64]$yum clean all Loaded plugins: fastestmirror, security Cleaning repos: my_base Cleaning up Everything [root@test x86_64]$yum repolist Loaded plugins: fastestmirror, security Determining fastest mirrors my_base | 4.0 kB 00:00 my_base/primary_db | 4.6 MB 00:00 repo id repo name status my_base this is test repo 6,575 repolist: 6,575
說明:可以看到剛纔搭建的倉庫成功的出現在倉庫列表中了。
7.安裝一個包,驗證倉庫
[root@test ~]$yum install java -y Loaded plugins: fastestmirror, security Setting up Install Process Loading mirror speeds from cached hostfile Resolving Dependencies --> Running transaction check ---> Package java-1.8.0-openjdk.x86_64 1:1.8.0.45-35.b13.el6 will be installed --> Processing Dependency: java-1.8.0-openjdk-headless = 1:1.8.0.45-35.b13.el6 for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: xorg-x11-fonts-Type1 for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libjvm.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libjli.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libjava.so(SUNWprivate_1.1)(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libjli.so()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libjava.so()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libgif.so.4()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: libawt.so()(64bit) for package: 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 --> Running transaction check ---> Package giflib.x86_64 0:4.1.6-3.1.el6 will be installed ---> Package java-1.8.0-openjdk-headless.x86_64 1:1.8.0.45-35.b13.el6 will be installed --> Processing Dependency: tzdata-java >= 2014f-1 for package: 1:java-1.8.0-openjdk-headless-1.8.0.45-35.b13.el6.x86_64 --> Processing Dependency: jpackage-utils for package: 1:java-1.8.0-openjdk-headless-1.8.0.45-35.b13.el6.x86_64 ---> Package xorg-x11-fonts-Type1.noarch 0:7.2-11.el6 will be installed --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Processing Dependency: ttmkfdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Processing Dependency: mkfontdir for package: xorg-x11-fonts-Type1-7.2-11.el6.noarch --> Running transaction check ---> Package jpackage-utils.noarch 0:1.7.5-3.14.el6 will be installed ---> Package ttmkfdir.x86_64 0:3.0.9-32.1.el6 will be installed ---> Package tzdata-java.noarch 0:2015e-1.el6 will be installed ---> Package xorg-x11-font-utils.x86_64 1:7.2-11.el6 will be installed --> Processing Dependency: libfontenc.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.2-11.el6.x86_64 --> Processing Dependency: libXfont.so.1()(64bit) for package: 1:xorg-x11-font-utils-7.2-11.el6.x86_64 --> Running transaction check ---> Package libXfont.x86_64 0:1.4.5-4.el6_6 will be installed ---> Package libfontenc.x86_64 0:1.0.5-2.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved =========================================================================================================================================================================== Package Arch Version Repository Size =========================================================================================================================================================================== Installing: java-1.8.0-openjdk x86_64 1:1.8.0.45-35.b13.el6 my_base 188 k Installing for dependencies: giflib x86_64 4.1.6-3.1.el6 my_base 37 k java-1.8.0-openjdk-headless x86_64 1:1.8.0.45-35.b13.el6 my_base 32 M jpackage-utils noarch 1.7.5-3.14.el6 my_base 60 k libXfont x86_64 1.4.5-4.el6_6 my_base 137 k libfontenc x86_64 1.0.5-2.el6 my_base 24 k ttmkfdir x86_64 3.0.9-32.1.el6 my_base 43 k tzdata-java noarch 2015e-1.el6 my_base 176 k xorg-x11-font-utils x86_64 1:7.2-11.el6 my_base 75 k xorg-x11-fonts-Type1 noarch 7.2-11.el6 my_base 520 k Transaction Summary =========================================================================================================================================================================== Install 10 Package(s) Total download size: 33 M Installed size: 104 M Downloading Packages: (1/10): ttmkfdir-3.0.9-32.1.el6.x86_64.rpm | 43 kB 00:00 (2/10): java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64.rpm | 188 kB 00:00 (3/10): jpackage-utils-1.7.5-3.14.el6.noarch.rpm | 60 kB 00:00 (4/10): tzdata-java-2015e-1.el6.noarch.rpm | 176 kB 00:00 (5/10): java-1.8.0-openjdk-headless-1.8.0.45-35.b13.el6.x86_64.rpm | 32 MB 00:00 (6/10): xorg-x11-font-utils-7.2-11.el6.x86_64.rpm | 75 kB 00:00 (7/10): libXfont-1.4.5-4.el6_6.x86_64.rpm | 137 kB 00:00 (8/10): xorg-x11-fonts-Type1-7.2-11.el6.noarch.rpm | 520 kB 00:00 (9/10): giflib-4.1.6-3.1.el6.x86_64.rpm | 37 kB 00:00 (10/10): libfontenc-1.0.5-2.el6.x86_64.rpm | 24 kB 00:00 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Total 33 MB/s | 33 MB 00:01 Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : libfontenc-1.0.5-2.el6.x86_64 1/10 Installing : libXfont-1.4.5-4.el6_6.x86_64 2/10 Installing : 1:xorg-x11-font-utils-7.2-11.el6.x86_64 3/10 Installing : giflib-4.1.6-3.1.el6.x86_64 4/10 Installing : tzdata-java-2015e-1.el6.noarch 5/10 Installing : jpackage-utils-1.7.5-3.14.el6.noarch 6/10 Installing : 1:java-1.8.0-openjdk-headless-1.8.0.45-35.b13.el6.x86_64 7/10 Installing : ttmkfdir-3.0.9-32.1.el6.x86_64 8/10 Installing : xorg-x11-fonts-Type1-7.2-11.el6.noarch 9/10 Installing : 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 10/10 Verifying : ttmkfdir-3.0.9-32.1.el6.x86_64 1/10 Verifying : 1:java-1.8.0-openjdk-1.8.0.45-35.b13.el6.x86_64 2/10 Verifying : jpackage-utils-1.7.5-3.14.el6.noarch 3/10 Verifying : tzdata-java-2015e-1.el6.noarch 4/10 Verifying : 1:java-1.8.0-openjdk-headless-1.8.0.45-35.b13.el6.x86_64 5/10 Verifying : 1:xorg-x11-font-utils-7.2-11.el6.x86_64 6/10 Verifying : libXfont-1.4.5-4.el6_6.x86_64 7/10 Verifying : xorg-x11-fonts-Type1-7.2-11.el6.noarch 8/10 Verifying : giflib-4.1.6-3.1.el6.x86_64 9/10 Verifying : libfontenc-1.0.5-2.el6.x86_64 10/10 Installed: java-1.8.0-openjdk.x86_64 1:1.8.0.45-35.b13.el6 Dependency Installed: giflib.x86_64 0:4.1.6-3.1.el6 java-1.8.0-openjdk-headless.x86_64 1:1.8.0.45-35.b13.el6 jpackage-utils.noarch 0:1.7.5-3.14.el6 libXfont.x86_64 0:1.4.5-4.el6_6 libfontenc.x86_64 0:1.0.5-2.el6 ttmkfdir.x86_64 0:3.0.9-32.1.el6 tzdata-java.noarch 0:2015e-1.el6 xorg-x11-font-utils.x86_64 1:7.2-11.el6 xorg-x11-fonts-Type1.noarch 0:7.2-11.el6 Complete!
到此網路rpm倉庫就搭建完畢!!