码迷,mamicode.com
首页 > 系统相关 > 详细

linux 下rpm仓库搭建

时间:2019-09-08 18:40:41      阅读:148      评论:0      收藏:0      [点我收藏+]

标签:基于   The   仓库服务   track   inf   创建仓库   sqlite   failed   direct   

一、概念

1.rpm是什么?在帮助文档里我们可以看到,rpm的名字是rpm package manage 的缩写, 从名字上看就可以知道rpm就是一个包管理工具。简单说rpm包就是把一些程序编译成二进制,和一些配置文件以及帮助文档等一些程序所依赖库打包在一起,这样形成的一个包。rpm大大的简化用户在Linux上安装软件的复杂度。

2.rpm仓库是什么?从字面理解仓库,就是集中存放东西的地方叫仓库,同样rpm仓库就是集中存放rpm包的一个地方。这里说的‘地方’就是服务器。把很多rpm包放在一个特定的服务器的特定目录里,在由特定的方式,比如http、https、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 `/rpmmkdir: created directory `/rpm/centosmkdir: created directory `/rpm/centos/6mkdir: created directory `/rpm/centos/6/osmkdir: created directory `/rpm/centos/6/os/x86_64mkdir: created directory `/rpm/centos/7mkdir: created directory `/rpm/centos/7/osmkdir: created directory `/rpm/centos/7/os/x86_64

说明:本次实验以centos6和7,平台架构上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验证,当然等于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个包。看到以上信息就表示我们仓库在客户端配置上成功的。

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/centosmkdir: created directory `/var/www/html/centos/6mkdir: created directory `/var/www/html/centos/6/osmkdir: created directory `/var/www/html/centos/6/os/x86_64mkdir: created directory `/var/www/html/centos/7mkdir: created directory `/var/www/html/centos/7/osmkdir: 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

说明:我这里只挂载了6的一个安装光盘,7下面的目录也可以用同样的方式挂载7的安装光盘,这里用6作为演示。这里还要说一下安装光盘本身就就有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 servers 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仓库就搭建完毕!!

linux 下rpm仓库搭建

标签:基于   The   仓库服务   track   inf   创建仓库   sqlite   failed   direct   

原文地址:https://www.cnblogs.com/qiuhom-1874/p/11487456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!