Linux下rpm倉庫搭建

1、概念html

1.rpm是什麼?在幫助文檔裏咱們能夠看到,rpm的名字是rpm package manage 的縮寫, 從名字上看就能夠知道rpm就是一個包管理工具。簡單說rpm包就是把一些程序編譯成二進制,和一些配置文件以及幫助文檔等一些程序所依賴庫打包在一塊兒,這樣造成的一個包。rpm大大的簡化用戶在Linux上安裝軟件的複雜度。前端

2.rpm倉庫是什麼?從字面理解,倉庫就是集中存放東西的地方,一樣rpm倉庫就是集中存放rpm包的一個地方。這裏說的‘地方’就是服務器。把不少rpm包放在一個特定的服務器的特定目錄裏, 再由好比http、nfs、ftp、file這些協議是用來提供給其餘服務器下載rpm包的服務器,咱們把這樣的服務器稱爲rpm倉庫服務器。java

3.yum是什麼?yum是Yellowdog Updater Modified 的縮寫,翻譯過來就是Yellowdog 更新修改,徹底沒有搞懂這個翻譯究竟是什麼意思,查下百度百科吧!yum是一個在Fedora、Redhat以及CentOS中的shell前端軟件包管理器。基於rpm包管理,可以從指定的服務器自下載rpm包而且安裝,能夠自動處理包依賴關係,而且可以一次安裝全部所依賴的軟件包,無需頻繁的一次次下載安裝。看了百度的解釋,咱們應該知道yum是什麼了吧!簡單說就是基於rpm包的前端管理工具,它能夠幫咱們解決包與包的依賴關係。web

4.yum的工做機制。yum是c/s架構的工做機制,服務端提供rpm倉庫,客戶端根據服務端提供的倉庫,經過特定協議去服務端下載所須要的包來進行安裝。第一次去服務端,它會把服務端的倉庫元數據緩存到本地,這樣就不須要每次下載都去服務端查詢。所謂倉庫的元數據就是記錄着該倉庫有哪些包,包名,包與包的依賴關係等一些數據。每次要裝包的時候,yum會去看看本地緩存的元數據,有沒有須要的包的信息,若是有,他們會把相應的包以及所依賴的包一併去服務端下載下來,一併安裝。sql

2、倉庫的搭建shell

瞭解了以上的基本概念,下面咱們開始來搭建rpm倉庫吧centos

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的系統上來建立的目錄tomcat

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倉庫就搭建完畢!!

相關文章
相關標籤/搜索