当前位置: > Linux服务器 > Docker >

本地yum库制作及本地安装Docker

时间:2016-06-06 00:18来源:linux.it.net.cn 作者:IT

生产环境中,我们总是会遇到服务器无法连接外网的情况,这样,如果想安装某个应用,而这个应用依赖的其他类库又特别多,就很痛苦了。这个时候,就需要自己制作个本地的yum库,进行本地安装。本文将以Docker本地安装为例,详细介绍如何制作本地yum库。

  1、首先,在能够上网的、与不能上网服务器的Linux发行版本相同的服务器上,执行安装命令,得到安装所需的各种依赖包,如下:

 
[root@localhost ~]# yum install libdevmapper* docker
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.btte.net
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.skyshe.cn
updates/7/x86_64/primary_db                                                                              
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-event-libs.x86_64 7:1.02.93-3.el7 will be updated
--> Processing Dependency: device-mapper-event-libs = 7:1.02.93-3.el7 for package: 7:device-mapper-event-
---> Package device-mapper-event-libs.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package device-mapper-libs.x86_64 7:1.02.93-3.el7 will be updated
--> Processing Dependency: device-mapper-libs = 7:1.02.93-3.el7 for package: 7:device-mapper-1.02.93-3.el
---> Package device-mapper-libs.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package docker.x86_64 0:1.9.1-25.el7.centos will be installed
--> Processing Dependency: docker-forward-journald = 1.9.1-25.el7.centos for package: docker-1.9.1-25.el7
--> Processing Dependency: docker-selinux >= 1.9.1-25.el7.centos for package: docker-1.9.1-25.el7.centos.
--> Processing Dependency: libsystemd.so.0(LIBSYSTEMD_209)(64bit) for package: docker-1.9.1-25.el7.centos
--> Processing Dependency: libsystemd.so.0()(64bit) for package: docker-1.9.1-25.el7.centos.x86_64
---> Package lvm2-libs.x86_64 7:2.02.115-3.el7 will be updated
--> Processing Dependency: lvm2-libs = 7:2.02.115-3.el7 for package: 7:lvm2-2.02.115-3.el7.x86_64
---> Package lvm2-libs.x86_64 7:2.02.130-5.el7_2.1 will be an update
--> Running transaction check
---> Package device-mapper.x86_64 7:1.02.93-3.el7 will be updated
---> Package device-mapper.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package device-mapper-event.x86_64 7:1.02.93-3.el7 will be updated
---> Package device-mapper-event.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package docker-forward-journald.x86_64 0:1.9.1-25.el7.centos will be installed
---> Package docker-selinux.x86_64 0:1.9.1-25.el7.centos will be installed
---> Package lvm2.x86_64 7:2.02.115-3.el7 will be updated
---> Package lvm2.x86_64 7:2.02.130-5.el7_2.1 will be an update
--> Processing Dependency: device-mapper-persistent-data >= 0.5.5-1 for package: 7:lvm2-2.02.130-5.el7_2.
---> Package systemd-libs.x86_64 0:208-20.el7_1.2 will be updated
--> Processing Dependency: systemd-libs = 208-20.el7_1.2 for package: systemd-208-20.el7_1.2.x86_64
---> Package systemd-libs.x86_64 0:219-19.el7_2.7 will be an update
--> Running transaction check
---> Package device-mapper-persistent-data.x86_64 0:0.4.1-2.el7 will be updated
---> Package device-mapper-persistent-data.x86_64 0:0.5.5-1.el7 will be an update
---> Package systemd.x86_64 0:208-20.el7_1.2 will be updated
--> Processing Dependency: systemd = 208-20.el7_1.2 for package: systemd-python-208-20.el7_1.2.x86_64
--> Processing Dependency: systemd = 208-20.el7_1.2 for package: systemd-sysv-208-20.el7_1.2.x86_64
--> Processing Dependency: systemd = 208-20.el7_1.2 for package: libgudev1-208-20.el7_1.2.x86_64
---> Package systemd.x86_64 0:219-19.el7_2.7 will be an update
--> Processing Dependency: kmod >= 18-4 for package: systemd-219-19.el7_2.7.x86_64
--> Running transaction check
---> Package kmod.x86_64 0:14-10.el7 will be updated
---> Package kmod.x86_64 0:20-5.el7 will be an update
---> Package libgudev1.x86_64 0:208-20.el7_1.2 will be updated
---> Package libgudev1.x86_64 0:219-19.el7_2.7 will be an update
---> Package systemd-python.x86_64 0:208-20.el7_1.2 will be updated
---> Package systemd-python.x86_64 0:219-19.el7_2.7 will be an update
---> Package systemd-sysv.x86_64 0:208-20.el7_1.2 will be updated
---> Package systemd-sysv.x86_64 0:219-19.el7_2.7 will be an update
--> Processing Conflict: systemd-219-19.el7_2.7.x86_64 conflicts initscripts < 9.49.28-1
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package initscripts.x86_64 0:9.49.24-1.el7 will be updated
---> Package initscripts.x86_64 0:9.49.30-1.el7_2.2 will be an update
--> Processing Conflict: systemd-219-19.el7_2.7.x86_64 conflicts dracut < 033-243
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package dracut.x86_64 0:033-241.el7_1.1 will be updated
--> Processing Dependency: dracut = 033-241.el7_1.1 for package: dracut-network-033-241.el7_1.1.x86_64
--> Processing Dependency: dracut = 033-241.el7_1.1 for package: dracut-config-rescue-033-241.el7_1.1.x86
---> Package dracut.x86_64 0:033-360.el7_2 will be an update
--> Running transaction check
---> Package dracut-config-rescue.x86_64 0:033-241.el7_1.1 will be updated
---> Package dracut-config-rescue.x86_64 0:033-360.el7_2 will be an update
---> Package dracut-network.x86_64 0:033-241.el7_1.1 will be updated
---> Package dracut-network.x86_64 0:033-360.el7_2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                                                       Arch                                   Ver
=========================================================================================================
Installing:
 docker                                                        x86_64                                 1.9
Updating:
 device-mapper-event-libs                                      x86_64                                 7:1
 device-mapper-libs                                            x86_64                                 7:1
 dracut                                                        x86_64                                 033
 initscripts                                                   x86_64                                 9.4
 lvm2-libs                                                     x86_64                                 7:2
Installing for dependencies:
 docker-forward-journald                                       x86_64                                 1.9
 docker-selinux                                                x86_64                                 1.9
Updating for dependencies:
 device-mapper                                                 x86_64                                 7:1
 device-mapper-event                                           x86_64                                 7:1
 device-mapper-persistent-data                                 x86_64                                 0.5
 dracut-config-rescue                                          x86_64                                 033
 dracut-network                                                x86_64                                 033
 kmod                                                          x86_64                                 20-
 libgudev1                                                     x86_64                                 219
 lvm2                                                          x86_64                                 7:2
 systemd                                                       x86_64                                 219
 systemd-libs                                                  x86_64                                 219
 systemd-python                                                x86_64                                 219
 systemd-sysv                                                  x86_64                                 219

Transaction Summary
=========================================================================================================
Install  1 Package  (+ 2 Dependent packages)
Upgrade  5 Packages (+12 Dependent packages)

Total download size: 23 M
Is this ok [y/d/N]: n
Exiting on user command
Your transaction was saved, rerun it with:
 yum load-transaction /tmp/yum_save_tx.2016-05-06.10-41.56BPrh.yumtx
[root@localhost ~]# yum install libdevmapper* docker
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * extras: mirrors.zju.edu.cn
 * updates: mirrors.skyshe.cn
Resolving Dependencies
--> Running transaction check
---> Package device-mapper-event-libs.x86_64 7:1.02.93-3.el7 will be updated
--> Processing Dependency: device-mapper-event-libs = 7:1.02.93-3.el7 for package: 7:device-mapper-event-1.02.93-3.el7.x86_64
---> Package device-mapper-event-libs.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package device-mapper-libs.x86_64 7:1.02.93-3.el7 will be updated
--> Processing Dependency: device-mapper-libs = 7:1.02.93-3.el7 for package: 7:device-mapper-1.02.93-3.el7.x86_64
---> Package device-mapper-libs.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package docker.x86_64 0:1.9.1-25.el7.centos will be installed
--> Processing Dependency: docker-forward-journald = 1.9.1-25.el7.centos for package: docker-1.9.1-25.el7.centos.x86_64
--> Processing Dependency: docker-selinux >= 1.9.1-25.el7.centos for package: docker-1.9.1-25.el7.centos.x86_64
--> Processing Dependency: libsystemd.so.0(LIBSYSTEMD_209)(64bit) for package: docker-1.9.1-25.el7.centos.x86_64
--> Processing Dependency: libsystemd.so.0()(64bit) for package: docker-1.9.1-25.el7.centos.x86_64
---> Package lvm2-libs.x86_64 7:2.02.115-3.el7 will be updated
--> Processing Dependency: lvm2-libs = 7:2.02.115-3.el7 for package: 7:lvm2-2.02.115-3.el7.x86_64
---> Package lvm2-libs.x86_64 7:2.02.130-5.el7_2.1 will be an update
--> Running transaction check
---> Package device-mapper.x86_64 7:1.02.93-3.el7 will be updated
---> Package device-mapper.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package device-mapper-event.x86_64 7:1.02.93-3.el7 will be updated
---> Package device-mapper-event.x86_64 7:1.02.107-5.el7_2.1 will be an update
---> Package docker-forward-journald.x86_64 0:1.9.1-25.el7.centos will be installed
---> Package docker-selinux.x86_64 0:1.9.1-25.el7.centos will be installed
---> Package lvm2.x86_64 7:2.02.115-3.el7 will be updated
---> Package lvm2.x86_64 7:2.02.130-5.el7_2.1 will be an update
--> Processing Dependency: device-mapper-persistent-data >= 0.5.5-1 for package: 7:lvm2-2.02.130-5.el7_2.1.x86_64
---> Package systemd-libs.x86_64 0:208-20.el7_1.2 will be updated
--> Processing Dependency: systemd-libs = 208-20.el7_1.2 for package: systemd-208-20.el7_1.2.x86_64
---> Package systemd-libs.x86_64 0:219-19.el7_2.7 will be an update
--> Running transaction check
---> Package device-mapper-persistent-data.x86_64 0:0.4.1-2.el7 will be updated
---> Package device-mapper-persistent-data.x86_64 0:0.5.5-1.el7 will be an update
---> Package systemd.x86_64 0:208-20.el7_1.2 will be updated
--> Processing Dependency: systemd = 208-20.el7_1.2 for package: systemd-python-208-20.el7_1.2.x86_64
--> Processing Dependency: systemd = 208-20.el7_1.2 for package: systemd-sysv-208-20.el7_1.2.x86_64
--> Processing Dependency: systemd = 208-20.el7_1.2 for package: libgudev1-208-20.el7_1.2.x86_64
---> Package systemd.x86_64 0:219-19.el7_2.7 will be an update
--> Processing Dependency: kmod >= 18-4 for package: systemd-219-19.el7_2.7.x86_64
--> Running transaction check
---> Package kmod.x86_64 0:14-10.el7 will be updated
---> Package kmod.x86_64 0:20-5.el7 will be an update
---> Package libgudev1.x86_64 0:208-20.el7_1.2 will be updated
---> Package libgudev1.x86_64 0:219-19.el7_2.7 will be an update
---> Package systemd-python.x86_64 0:208-20.el7_1.2 will be updated
---> Package systemd-python.x86_64 0:219-19.el7_2.7 will be an update
---> Package systemd-sysv.x86_64 0:208-20.el7_1.2 will be updated
---> Package systemd-sysv.x86_64 0:219-19.el7_2.7 will be an update
--> Processing Conflict: systemd-219-19.el7_2.7.x86_64 conflicts initscripts < 9.49.28-1
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package initscripts.x86_64 0:9.49.24-1.el7 will be updated
---> Package initscripts.x86_64 0:9.49.30-1.el7_2.2 will be an update
--> Processing Conflict: systemd-219-19.el7_2.7.x86_64 conflicts dracut < 033-243
--> Restarting Dependency Resolution with new changes.
--> Running transaction check
---> Package dracut.x86_64 0:033-241.el7_1.1 will be updated
--> Processing Dependency: dracut = 033-241.el7_1.1 for package: dracut-network-033-241.el7_1.1.x86_64
--> Processing Dependency: dracut = 033-241.el7_1.1 for package: dracut-config-rescue-033-241.el7_1.1.x86_64
---> Package dracut.x86_64 0:033-360.el7_2 will be an update
--> Running transaction check
---> Package dracut-config-rescue.x86_64 0:033-241.el7_1.1 will be updated
---> Package dracut-config-rescue.x86_64 0:033-360.el7_2 will be an update
---> Package dracut-network.x86_64 0:033-241.el7_1.1 will be updated
---> Package dracut-network.x86_64 0:033-360.el7_2 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                               Arch           Version                      Repository       Size
=========================================================================================================
Installing:
 docker                                x86_64         1.9.1-25.el7.centos          extras           13 M
Updating:
 device-mapper-event-libs              x86_64         7:1.02.107-5.el7_2.1         updates         169 k
 device-mapper-libs                    x86_64         7:1.02.107-5.el7_2.1         updates         304 k
 dracut                                x86_64         033-360.el7_2                updates         311 k
 initscripts                           x86_64         9.49.30-1.el7_2.2            updates         429 k
 lvm2-libs                             x86_64         7:2.02.130-5.el7_2.1         updates         872 k
Installing for dependencies:
 docker-forward-journald               x86_64         1.9.1-25.el7.centos          extras          824 k
 docker-selinux                        x86_64         1.9.1-25.el7.centos          extras           70 k
Updating for dependencies:
 device-mapper                         x86_64         7:1.02.107-5.el7_2.1         updates         252 k
 device-mapper-event                   x86_64         7:1.02.107-5.el7_2.1         updates         167 k
 device-mapper-persistent-data         x86_64         0.5.5-1.el7                  base            350 k
 dracut-config-rescue                  x86_64         033-360.el7_2                updates          49 k
 dracut-network                        x86_64         033-360.el7_2                updates          90 k
 kmod                                  x86_64         20-5.el7                     base            114 k
 libgudev1                             x86_64         219-19.el7_2.7               updates          65 k
 lvm2                                  x86_64         7:2.02.130-5.el7_2.1         updates         1.0 M
 systemd                               x86_64         219-19.el7_2.7               updates         5.1 M
 systemd-libs                          x86_64         219-19.el7_2.7               updates         357 k
 systemd-python                        x86_64         219-19.el7_2.7               updates          99 k
 systemd-sysv                          x86_64         219-19.el7_2.7               updates          53 k

Transaction Summary
=========================================================================================================
Install  1 Package  (+ 2 Dependent packages)
Upgrade  5 Packages (+12 Dependent packages)

Total download size: 23 M
Is this ok [y/d/N]: 
 


  2、下载对应版本的rpm包,网址:

http://rpmfind.net/linux/rpm2html/search.php


  3、制作本地yum库。将全部的rpm包拷贝到一个文件夹中,例如docker_rpms,执行如下命令:

 
[root@localhost test]# ls
docker_rpms
[root@localhost test]# createrepo .
Spawning worker 0 with 18 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[root@localhost test]# ls
docker_rpms  repodata
 

 

  4、编辑docker.repo文件

 
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=file:///home/dockeryum
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[update]
name=CentOS-$releasever - update
baseurl=file:///home/dockeryum
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
 


  5、将docker_rpms文件夹、repodata文件夹、docker.repo拷贝到/home/dockeryum(因为docker.repo文件中做的如此配置)文件夹下。执行如下操作: 

 
[root@localhost home]# ls
dockeryum  laizy
[root@localhost home]# cp -r /etc/yum.repos.d/ /etc/yum.repos.d.bak        (备份原始yum源)
[root@localhost home]# rm -rf /etc/yum.repos.d/*                           (清空原始yum源)
[root@localhost home]# cp /home/dockeryum/docker.repo /etc/yum.repos.d/    (拷贝自己写的yum源)
[root@localhost home]# ll /etc/yum.repos.d/
total 4
-rw-r--r--. 1 root root 682 May  6 10:26 docker.repo
[root@localhost home]# yum install libdevmapper* docker                    (yum安装)
Loaded plugins: fastestmirror, langpacks
Existing lock /var/run/yum.pid: another copy is running as pid 13870.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  48 M RSS (922 MB VSZ)
    Started: Fri May  6 10:23:42 2016 - 04:13 ago
    State  : Sleeping, pid: 13870
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: PackageKit
    Memory :  48 M RSS (922 MB VSZ)
    Started: Fri May  6 10:23:42 2016 - 04:15 ago
    State  : Running, pid: 13870
^C

Exiting on user cancel.
[root@localhost home]# kill -9 13870
[root@localhost home]# yum install libdevmapper* docker
Loaded plugins: fastestmirror, langpacks
base                                                                              | 2.9 kB  00:00:00     
update                                                                            | 2.9 kB  00:00:00     
(1/2): base/primary_db                                                            |  23 kB  00:00:00     
(2/2): update/primary_db                                                          |  23 kB  00:00:00     
Loading mirror speeds from cached hostfile
Package 7:device-mapper-event-libs-1.02.93-3.el7.x86_64 already installed and latest version
Package 7:device-mapper-libs-1.02.93-3.el7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package docker.x86_64 0:1.8.2-7.el7.centos will be installed
--> Processing Dependency: docker-selinux >= 1.8.2-7.el7.centos for package: docker-1.8.2-7.el7.centos.x86_64
--> Running transaction check
---> Package docker-selinux.x86_64 0:1.8.2-7.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================
 Package                     Arch                Version                         Repository         Size
=========================================================================================================
Installing:
 docker                      x86_64              1.8.2-7.el7.centos              base              8.7 M
Installing for dependencies:
 docker-selinux              x86_64              1.8.2-7.el7.centos              base               61 k

Transaction Summary
=========================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 8.7 M
Installed size: 37 M
Is this ok [y/d/N]: y
Downloading packages:
---------------------------------------------------------------------------------------------------------
Total                                                                    160 MB/s | 8.7 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : docker-selinux-1.8.2-7.el7.centos.x86_64                                              1/2 
restorecon:  lstat(/var/lib/docker) failed:  No such file or directory
warning: %post(docker-selinux-1.8.2-7.el7.centos.x86_64) scriptlet failed, exit status 255
Non-fatal POSTIN scriptlet failure in rpm package docker-selinux-1.8.2-7.el7.centos.x86_64
  Installing : docker-1.8.2-7.el7.centos.x86_64                                                      2/2 
  Verifying  : docker-1.8.2-7.el7.centos.x86_64                                                      1/2 
  Verifying  : docker-selinux-1.8.2-7.el7.centos.x86_64                                              2/2 

Installed:
  docker.x86_64 0:1.8.2-7.el7.centos                                                                     

Dependency Installed:
  docker-selinux.x86_64 0:1.8.2-7.el7.centos                                                             

Complete!
[root@localhost home]# docker -v
Docker version 1.8.2, build bb472f0/1.8.2
 

   安装完成!



 


(责任编辑:IT)
------分隔线----------------------------
栏目列表
推荐内容