1. 程式人生 > >docker swarm集群搭建

docker swarm集群搭建

status led gif 關閉selinux running CP 詳細信息 heal server

docker swarm集群搭建

原文:https://www.cnblogs.com/galengao/p/5780948.html

摘要:

  • swarm是docker原生的集群管理軟件,與kubernetes比起來比較簡單

1、部署

系統時centos7上
關閉防火墻 systemctl stop firewalld.service
關閉selinux vi /etc/selinux/comfig

192.168.10.140 swarm manager
192.168.10.141 swarm node
192.168.10.142 swarm mode

2、分別在manager節點和node節點上安裝docker

安裝方式參照我的另一篇文章docker安裝http://galengao.github.io/docker/2016/06/03/mydocker-use.html

技術分享圖片
yum update

tee /etc/yum.repos.d/docker.repo<<EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF

yum install docker-engine
技術分享圖片
 

3、分別在manager節點和node節點上配置docker

技術分享圖片
vi /lib/systemd/system/docker.service
# 修改ExecStart項為如下:
ExecStart=/usr/bin/docker daemon -H 0.0.0.0:2375 -H unix:///var/run/docker.sock
# 重新載入配置,使修改生效。
systemctl daemon-reload
# 重啟docker。
systemctl restart docker
技術分享圖片
 

4、在manager節點和node節點上push swarm鏡像

技術分享圖片
[root@swarm1 ~]# docker pull swarm
Using default tag: latest
latest: Pulling from library/swarm
1e61bbec5d24: Pull complete 
8c7b2f6b74da: Pull complete 
245a8db4f1e1: Pull complete 
Digest: sha256:661f2e4c9470e7f6238cebf603bcf5700c8b948894ac9e35f2cf6f63dcda723a
Status: Downloaded newer image for swarm:latest
技術分享圖片
 

5、創建集群token,獲取全球唯一的 token,作為集群唯一標識

# 在任何節點都可以,但是要記住該值,以後要用到
[root@swarm1 ~]# docker run --rm swarm create
eca9b4ab85feb53f8a9676c72dd01b1a
 

6、加入集群

技術分享圖片
# 在manager也就是節點node1
[root@swarm1 ~]# docker run -d swarm join -addr=192.168.10.140:2375 token://eca9b4ab85feb53f8a9676c72dd01b1a
109da11914295c588c6afe5f83ab731bd0d0012897c39c311de89534e2f5bc13
# node2上
[root@swarm1 ~]# docker run -d swarm join -addr=192.168.10.141:2375 token://eca9b4ab85feb53f8a9676c72dd01b1a
1da02eb6a00a8860eefe965a0aded446aebff8b502962c717dd3f494b546841a
# node3上
[root@swarm1 ~]# docker run -d swarm join -addr=192.168.10.142:2375 token://eca9b4ab85feb53f8a9676c72dd01b1a
b5483c91bff0ad21e19700af51990d631e991f9d67188c7419f147652d494972
技術分享圖片
 

7、啟動管理機

# 在管理機上執行:
[root@swarm1 ~]# docker run -d -p 2376:2375 swarm manage token://eca9b4ab85feb53f8a9676c72dd01b1a
3073a3dd59a5782f706d6481cfd1a36e8090f21764dfec2532899450bd719456
 

8、查看節點信息

技術分享圖片
# 本機上查看節點信息
[root@swarm1 ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
1da02eb6a00a        swarm               "/swarm join -addr=19"   27 minutes ago      Up 27 minutes       2375/tcp            sick_bose
# 查看集群所有節點信息,在任何一臺機器上執行
[root@swarm1 ~]# docker run --rm swarm list token://eca9b4ab85feb53f8a9676c72dd01b1a
192.168.10.142:2375
192.168.10.141:2375
192.168.10.140:2375
# 查看集群詳細信息。在任何一臺機器上執行:
# 該IP地址是manager的地址
[root@swarm1 ~]# docker -H 192.168.10.140:2376 info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: swarm/1.2.3
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 3
 (unknown): 192.168.10.142:2375
  └ ID: 
  └ Status: Pending
  └ Containers: 0
  └ Reserved CPUs: 0 / 0
  └ Reserved Memory: 0 B / 0 B
  └ Labels: 
  └ UpdatedAt: 2016-07-28T07:54:39Z
  └ ServerVersion: 
 (unknown): 192.168.10.141:2375
  └ ID: 
  └ Status: Pending
  └ Containers: 0
  └ Reserved CPUs: 0 / 0
  └ Reserved Memory: 0 B / 0 B
  └ Labels: 
  └ UpdatedAt: 2016-07-28T07:54:39Z
  └ ServerVersion: 
 (unknown): 192.168.10.140:2375
  └ ID: 
  └ Status: Pending
  └ Containers: 0
  └ Reserved CPUs: 0 / 0
  └ Reserved Memory: 0 B / 0 B
  └ Labels: 
  └ UpdatedAt: 2016-07-28T07:54:39Z
  └ ServerVersion: 
Plugins: 
 Volume: 
 Network: 
Kernel Version: 3.10.0-229.el7.x86_64
Operating System: linux
Architecture: amd64
CPUs: 0
Total Memory: 0 B
Name: 3073a3dd59a5
Docker Root Dir: 
Debug mode (client): false
Debug mode (server): false
WARNING: No kernel memory limit support

docker swarm集群搭建