Centos 7.2.1511 安裝 Docker 遇到的問題與解決方案

一、前言

最近在一個集羣上安裝 Docker,本來多麼簡單的事卻因爲網絡原因以及系統版本變得曲折了,也由於找到了不適合的解決方案,饒了一個彎,所以特此記錄一下安裝過程,防止重複踩坑。

==系統版本:Centos 7.2.1511==

二、下載與上傳

由於服務器不能連接外網,所以服務器使用的是公司自帶的 yum 倉庫,但是倉庫內沒有 Docker 安裝包,所以需要自己下載。

下載地址:https://yum.dockerproject.org/repo/main/centos/7/Packages/

下載文件:

下載完成後,上傳到服務器等待安裝

三、安裝

依次輸入如下命令:

$ sudo yum -y localinstall docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm
$ sudo yum -y localinstall docker-engine-1.13.1-1.el7.centos.x86_64.rpm

這裏使用yum -y localinstall命令,而不是rpm -ivh,是因爲它會自動從倉庫中下載並安裝相應的依賴包,那麼如果指定的倉庫中有系統對應的版本,安裝就應該是沒問題的,但是我所使用的倉庫中沒有7.2.1511版本的安裝包,在該目錄下有一個readme文件(通過瀏覽器打開),內容如下:

This directory (and version of CentOS) is deprecated.  For normal users,
you should use /7/ and not /7.2.1511/ in your path. Please see this FAQ
concerning the CentOS release scheme:

https://wiki.centos.org/FAQ/General

If you know what you are doing, and absolutely want to remain at the 7.2.1511
level, go to http://vault.centos.org/ for packages. 

Please keep in mind that 7.2.1511 no longer gets any updates, nor
any security fix's.

嗯,大概意思就是讓我使用版本7目錄下的…

==由於對應版本的安裝包不存在時發生的異常見附錄1==

四、修改 yum 獲取的版本

使用如下命令進入修改界面:

sudo vi /etc/yum.repos.d/CentOS-Base.repo

原文件如下:

[base]
name=CentOS-$releasever - Base

baseurl=http://s7repo01/centos/7.2.1511/os/$basearch/
gpgcheck=1
gpgkey=http://s7repo01/centos/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=http://s7repo01/centos/7.2.1511/updates/$basearch/
gpgcheck=1
gpgkey=http://s7repo01/centos/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=http://s7repo01/centos/7.2.1511/extras/$basearch/
gpgcheck=1
gpgkey=http://s7repo01/centos/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=http://s7repo01/centos/7.2.1511/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://s7repo01/centos/RPM-GPG-KEY-CentOS-7

將所有的baseurl屬性修改爲版本7對應的目錄路徑,baseurl屬性修改後如下:

baseurl=http://s7repo01/centos/7/centosplus/$basearch/

注:只修改版本號即可,對應的倉庫地址可能與此不同,能訪問則不必修改。

五、繼續安裝

繼續使用如下命令安裝:

$ sudo yum -y localinstall docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm
$ sudo yum -y localinstall docker-engine-1.13.1-1.el7.centos.x86_64.rpm

如果出現某個倉庫不能連接的情況,可使用如下命令禁用掉,例(查看具體的錯誤信息可獲知倉庫名稱,這裏是dockerrepo):

sudo yum-config-manager --disable dockerrepo

重新輸入命令,安裝成功

附錄1:安裝中的問題

Loaded plugins: fastestmirror
Repository cloudera-manager is listed more than once in the configuration
Examining docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm: docker-engine-selinux-1.13.1-1.el7.centos.noarch
Marking docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package docker-engine-selinux.noarch 0:1.13.1-1.el7.centos will be installed
--> Processing Dependency: selinux-policy-base >= 3.13.1-102 for package: docker-engine-selinux-1.13.1-1.el7.centos.noarch
http://s7repo01/centos/7.2.1511/os/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below knowledge base article 

https://access.redhat.com/articles/1320623

If above article doesn't help to resolve this issue please create a bug on https://bugs.centos.org/

http://s7repo01/centos/7.2.1511/extras/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
http://s7repo01/centos/7.2.1511/updates/x86_64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
Loading mirror speeds from cached hostfile

... 省略

Error: Package: docker-engine-selinux-1.13.1-1.el7.centos.noarch (/docker-engine-selinux-1.13.1-1.el7.centos.noarch)
           Requires: selinux-policy-base >= 3.13.1-102
           Installed: selinux-policy-targeted-3.13.1-60.el7.noarch (@anaconda)
               selinux-policy-base = 3.13.1-60.el7
           Available: selinux-policy-minimum-3.13.1-60.el7.noarch (base)
               selinux-policy-base = 3.13.1-60.el7
           Available: selinux-policy-minimum-3.13.1-60.el7_2.3.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.3
           Available: selinux-policy-minimum-3.13.1-60.el7_2.7.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.7
           Available: selinux-policy-minimum-3.13.1-60.el7_2.9.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.9
           Available: selinux-policy-mls-3.13.1-60.el7.noarch (base)
               selinux-policy-base = 3.13.1-60.el7
           Available: selinux-policy-mls-3.13.1-60.el7_2.3.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.3
           Available: selinux-policy-mls-3.13.1-60.el7_2.7.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.7
           Available: selinux-policy-mls-3.13.1-60.el7_2.9.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.9
           Available: selinux-policy-targeted-3.13.1-60.el7_2.3.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.3
           Available: selinux-policy-targeted-3.13.1-60.el7_2.7.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.7
           Available: selinux-policy-targeted-3.13.1-60.el7_2.9.noarch (updates)
               selinux-policy-base = 3.13.1-60.el7_2.9
Error: Package: docker-engine-selinux-1.13.1-1.el7.centos.noarch (/docker-engine-selinux-1.13.1-1.el7.centos.noarch)
           Requires: selinux-policy-targeted >= 3.13.1-102
           Installed: selinux-policy-targeted-3.13.1-60.el7.noarch (@anaconda)
               selinux-policy-targeted = 3.13.1-60.el7
           Available: selinux-policy-targeted-3.13.1-60.el7_2.3.noarch (updates)
               selinux-policy-targeted = 3.13.1-60.el7_2.3
           Available: selinux-policy-targeted-3.13.1-60.el7_2.7.noarch (updates)
               selinux-policy-targeted = 3.13.1-60.el7_2.7
           Available: selinux-policy-targeted-3.13.1-60.el7_2.9.noarch (updates)
               selinux-policy-targeted = 3.13.1-60.el7_2.9
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

使用rpm命令安裝,可看見需要的依賴包

sudo rpm -ivh docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm 

warning: docker-engine-selinux-1.13.1-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY
error: Failed dependencies:
        policycoreutils-python is needed by docker-engine-selinux-1.13.1-1.el7.centos.noarch
        selinux-policy-base >= 3.13.1-102 is needed by docker-engine-selinux-1.13.1-1.el7.centos.noarch
        selinux-policy-targeted >= 3.13.1-102 is needed by docker-engine-selinux-1.13.1-1.el7.centos.noarch

附錄2:參考鏈接

http://www.cnblogs.com/mchina/archive/2013/01/04/2842275.html \
http://www.178linux.com/11404 \
http://www.jianshu.com/p/1fc580b71ea4 \
https://my.oschina.net/hanhanztj/blog/504915

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章