这里写图片描述

在docker1.12中我们知道docker内置了swarm, 接下来当然会首先来验证这个功能.体验一下是否像docker自己说的那样好. 在使用swarm构筑docker的集群时, 事前需要有所准备, 我们准备3-4台虚拟机,内存和CPU以及Disk不用太多,能动即可.

Node构成

节点名称IP
host31192.168.32.31
host32192.168.32.32
host33192.168.32.33
host34192.168.32.34

各节点网络设定

  • 关闭防火墙
  • 关闭selinux
  • 清除iptables规则

可使用下面的脚本,稍微减少本来就不多的动作,有100台以上的节点的话,估计无论多简单你都绝对不想手动操作吧。

[root@host31 ~]# cat set_network.sh
#!/bin/bash

echo "## disable selinux"
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/sysconfig/selinux
grep disabled /etc/sysconfig/selinux

echo "## disable firewalld"
systemctl disable firewalld
systemctl stop firewalld

echo "## clear iptables rules"
iptables -F
[root@host31 ~]#
[root@host31 ~]# sh set_network.sh
## disable selinux
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
## disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.
## clear iptables rules
[root@host31 ~]#

各节点安装docker1.12

可以使用如下脚本,在centos7上进行安装。结合baseurl实际路径,自行修正应该适合其它版本。

[root@host31 ~]# cat /tmp/install_docker.sh
#!/bin/bash

LINUXOS=centos
VERSION=7


echo "## Setting yum repos"
cat > /etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/experimental/${LINUXOS}/${VERSION}/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

echo "## yum install docker"
yum install -y docker-engine

echo "## setting restart service for OS boot"
systemctl enable docker

echo "## start docker"
systemctl start docker

echo "## docker version confrim"
docker info |grep Version
[root@host31 ~]#

执行结果

[root@host31 ~]# sh /tmp/install_docker.sh
## Setting yum repos
## yum install docker
Loaded plugins: fastestmirror
base                                                                                                                        | 3.6 kB  00:00:00
dockerrepo                                                                                                                  | 2.9 kB  00:00:00
extras                                                                                                                      | 3.4 kB  00:00:00
updates                                                                                                                     | 3.4 kB  00:00:00
(1/5): base/7/x86_64/group_gz                                                                                               | 155 kB  00:00:01
(2/5): base/7/x86_64/primary_db                                                                                             | 5.3 MB  00:00:07
(3/5): updates/7/x86_64/primary_db                                                                                          | 6.4 MB  00:00:17
(4/5): dockerrepo/primary_db                                                                                                |  49 kB  00:00:18
extras/7/x86_64/primary_db     FAILED
http://mirror.bit.edu.cn/centos/7.2.1511/extras/x86_64/repodata/bafd5e7438d36d63030e1ac0029c7a0be8f20ebc26bf7196c16ce2752fd63dff-primary.sqlite.bz2: [Errno 12] Timeout on http://mirror.bit.edu.cn/centos/7.2.1511/extras/x86_64/repodata/bafd5e7438d36d63030e1ac0029c7a0be8f20ebc26bf7196c16ce2752fd63dff-primary.sqlite.bz2: (28, 'Resolving timed out after 30574 milliseconds')
Trying other mirror.
(5/5): extras/7/x86_64/primary_db                                                                                           | 160 kB  00:00:00
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package docker-engine.x86_64 0:1.12.0-1.el7.centos will be installed
--> Processing Dependency: docker-engine-selinux >= 1.12.0-1.el7.centos for package: docker-engine-1.12.0-1.el7.centos.x86_64
--> Processing Dependency: libcgroup for package: docker-engine-1.12.0-1.el7.centos.x86_64
--> Processing Dependency: libseccomp.so.2()(64bit) for package: docker-engine-1.12.0-1.el7.centos.x86_64
--> Processing Dependency: libltdl.so.7()(64bit) for package: docker-engine-1.12.0-1.el7.centos.x86_64
--> Running transaction check
---> Package docker-engine-selinux.noarch 0:1.12.0-1.el7.centos will be installed
--> Processing Dependency: policycoreutils-python for package: docker-engine-selinux-1.12.0-1.el7.centos.noarch
---> Package libcgroup.x86_64 0:0.41-8.el7 will be installed
---> Package libseccomp.x86_64 0:2.2.1-1.el7 will be installed
---> Package libtool-ltdl.x86_64 0:2.4.2-21.el7_2 will be installed
--> Running transaction check
---> Package policycoreutils-python.x86_64 0:2.2.5-20.el7 will be installed
--> Processing Dependency: libsemanage-python >= 2.1.10-1 for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: audit-libs-python >= 2.1.3-4 for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: python-IPy for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.4)(64bit) for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: libqpol.so.1(VERS_1.2)(64bit) for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: libapol.so.4(VERS_4.0)(64bit) for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: checkpolicy for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: libqpol.so.1()(64bit) for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Processing Dependency: libapol.so.4()(64bit) for package: policycoreutils-python-2.2.5-20.el7.x86_64
--> Running transaction check
---> Package audit-libs-python.x86_64 0:2.4.1-5.el7 will be installed
---> Package checkpolicy.x86_64 0:2.1.12-6.el7 will be installed
---> Package libsemanage-python.x86_64 0:2.1.10-18.el7 will be installed
---> Package python-IPy.noarch 0:0.75-6.el7 will be installed
---> Package setools-libs.x86_64 0:3.3.7-46.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
 Package                                   Arch                      Version                                   Repository                     Size
===================================================================================================================================================
Installing:
 docker-engine                             x86_64                    1.12.0-1.el7.centos                       dockerrepo                     19 M
Installing for dependencies:
 audit-libs-python                         x86_64                    2.4.1-5.el7                               base                           69 k
 checkpolicy                               x86_64                    2.1.12-6.el7                              base                          247 k
 docker-engine-selinux                     noarch                    1.12.0-1.el7.centos                       dockerrepo                     28 k
 libcgroup                                 x86_64                    0.41-8.el7                                base                           64 k
 libseccomp                                x86_64                    2.2.1-1.el7                               base                           49 k
 libsemanage-python                        x86_64                    2.1.10-18.el7                             base                           94 k
 libtool-ltdl                              x86_64                    2.4.2-21.el7_2                            updates                        49 k
 policycoreutils-python                    x86_64                    2.2.5-20.el7                              base                          435 k
 python-IPy                                noarch                    0.75-6.el7                                base                           32 k
 setools-libs                              x86_64                    3.3.7-46.el7                              base                          485 k

Transaction Summary
===================================================================================================================================================
Install  1 Package (+10 Dependent packages)

Total download size: 21 M
Installed size: 84 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/audit-libs-python-2.4.1-5.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEYETA
Public key for audit-libs-python-2.4.1-5.el7.x86_64.rpm is not installed
(1/11): audit-libs-python-2.4.1-5.el7.x86_64.rpm                                                                            |  69 kB  00:00:00
(2/11): checkpolicy-2.1.12-6.el7.x86_64.rpm                                                                                 | 247 kB  00:00:01
(3/11): libseccomp-2.2.1-1.el7.x86_64.rpm                                                                                   |  49 kB  00:00:00
(4/11): libsemanage-python-2.1.10-18.el7.x86_64.rpm                                                                         |  94 kB  00:00:00
(5/11): libcgroup-0.41-8.el7.x86_64.rpm                                                                                     |  64 kB  00:00:01
(6/11): python-IPy-0.75-6.el7.noarch.rpm                                                                                    |  32 kB  00:00:00
(7/11): setools-libs-3.3.7-46.el7.x86_64.rpm                                                                                | 485 kB  00:00:00
(8/11): policycoreutils-python-2.2.5-20.el7.x86_64.rpm                                                                      | 435 kB  00:00:01
Public key for libtool-ltdl-2.4.2-21.el7_2.x86_64.rpm is not installed==-                                        ] 423 kB/s | 3.8 MB  00:00:40 ETA
(9/11): libtool-ltdl-2.4.2-21.el7_2.x86_64.rpm                                                                              |  49 kB  00:00:06
warning: /var/cache/yum/x86_64/7/dockerrepo/packages/docker-engine-selinux-1.12.0-1.el7.centos.noarch.rpm: Header V4 RSA/SHA512 Signature, key ID 2c52609d: NOKEY
Public key for docker-engine-selinux-1.12.0-1.el7.centos.noarch.rpm is not installed
(10/11): docker-engine-selinux-1.12.0-1.el7.centos.noarch.rpm                                                               |  28 kB  00:00:12
(11/11): docker-engine-1.12.0-1.el7.centos.x86_64.rpm                                                                       |  19 MB  00:00:51
---------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                              409 kB/s |  21 MB  00:00:51
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-2.1511.el7.centos.2.10.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Retrieving key from https://yum.dockerproject.org/gpg
Importing GPG key 0x2C52609D:
 Userid     : "Docker Release Tool (releasedocker) <docker@docker.com>"
 Fingerprint: 5811 8e89 f3a9 1289 7c07 0adb f762 2157 2c52 609d
 From       : https://yum.dockerproject.org/gpg
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libcgroup-0.41-8.el7.x86_64                                                                                                    1/11
  Installing : libsemanage-python-2.1.10-18.el7.x86_64                                                                                        2/11
  Installing : audit-libs-python-2.4.1-5.el7.x86_64                                                                                           3/11
  Installing : libseccomp-2.2.1-1.el7.x86_64                                                                                                  4/11
  Installing : python-IPy-0.75-6.el7.noarch                                                                                                   5/11
  Installing : checkpolicy-2.1.12-6.el7.x86_64                                                                                                6/11
  Installing : libtool-ltdl-2.4.2-21.el7_2.x86_64                                                                                             7/11
  Installing : setools-libs-3.3.7-46.el7.x86_64                                                                                               8/11
  Installing : policycoreutils-python-2.2.5-20.el7.x86_64                                                                                     9/11
  Installing : docker-engine-selinux-1.12.0-1.el7.centos.noarch                                                                              10/11
restorecon:  lstat(/var/lib/docker) failed:  No such file or directory
warning: %post(docker-engine-selinux-1.12.0-1.el7.centos.noarch) scriptlet failed, exit status 255
Non-fatal POSTIN scriptlet failure in rpm package docker-engine-selinux-1.12.0-1.el7.centos.noarch
  Installing : docker-engine-1.12.0-1.el7.centos.x86_64                                                                                      11/11
  Verifying  : setools-libs-3.3.7-46.el7.x86_64                                                                                               1/11
  Verifying  : docker-engine-selinux-1.12.0-1.el7.centos.noarch                                                                               2/11
  Verifying  : libcgroup-0.41-8.el7.x86_64                                                                                                    3/11
  Verifying  : libtool-ltdl-2.4.2-21.el7_2.x86_64                                                                                             4/11
  Verifying  : checkpolicy-2.1.12-6.el7.x86_64                                                                                                5/11
  Verifying  : python-IPy-0.75-6.el7.noarch                                                                                                   6/11
  Verifying  : libseccomp-2.2.1-1.el7.x86_64                                                                                                  7/11
  Verifying  : docker-engine-1.12.0-1.el7.centos.x86_64                                                                                       8/11
  Verifying  : audit-libs-python-2.4.1-5.el7.x86_64                                                                                           9/11
  Verifying  : policycoreutils-python-2.2.5-20.el7.x86_64                                                                                    10/11
  Verifying  : libsemanage-python-2.1.10-18.el7.x86_64                                                                                       11/11

Installed:
  docker-engine.x86_64 0:1.12.0-1.el7.centos

Dependency Installed:
  audit-libs-python.x86_64 0:2.4.1-5.el7    checkpolicy.x86_64 0:2.1.12-6.el7               docker-engine-selinux.noarch 0:1.12.0-1.el7.centos
  libcgroup.x86_64 0:0.41-8.el7             libseccomp.x86_64 0:2.2.1-1.el7                 libsemanage-python.x86_64 0:2.1.10-18.el7
  libtool-ltdl.x86_64 0:2.4.2-21.el7_2      policycoreutils-python.x86_64 0:2.2.5-20.el7    python-IPy.noarch 0:0.75-6.el7
  setools-libs.x86_64 0:3.3.7-46.el7

Complete!
## setting restart service for OS boot
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
## start docker
## docker version confrim
 WARNING: Usage of loopback devices is strongly discouraged for production use. Use `--storage-opt dm.thinpooldev` to specify a custom block storage device.
WARNING: bridge-nf-call-iptables is disabled
WARNING: bridge-nf-call-ip6tables is disabled
Server Version: 1.12.0
 Library Version: 1.02.107-RHEL7 (2015-10-14)
Kernel Version: 3.10.0-327.el7.x86_64
[root@host31 ~]#
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐