docker swarm集群搭建及用Portainer管理用Docker Swarm环境

作者 : 开心源码 本文共4074个字,预计阅读时间需要11分钟 发布时间: 2022-05-12 共57人阅读

一、规划

1、swarm01作为manager节点,swarm02和swarm03作为worker节点。

$cat /etc/hosts

172.18.144.188 node1 node1

172.18.144.191 node2

172.18.144.190 node3

172.18.144.189 node4

2、配置SSH免密登陆

这一步参考https://blog.csdn.net/zxf_668899/article/details/53927391#13-%E9%85%8D%E7%BD%AEssh%E5%85%8D%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95

配置完成

二、安装docker和ansible

1、安装配置ansible

$ yum -y install ansible

$ cat /etc/ansible/hosts | grep -v ^# | grep -v ^$

[node]

172.18.144.188

172.18.144.191

172.18.144.190

172.18.144.189

$ sed -i “s/SELINUX=enforcing/SELINUX=disabled” /etc/selinux/config

$ ansible node -m copy -a 'src=/etc/selinux/config dest=/etc/selinux/'

$ systemctl stop firewalld

$ systemctl disable firewalld

$ ansible node -a 'systemctl stop firewalld'

$ ansible node -a 'systemctl disable firewalld'

注:这里选择关闭防火墙,实际环境中可自行开放端口。

2、安装docker

  • 在manager节点安装docker

$ yum install -y yum-utils device-mapper-persistent-data lvm2

$ yum-config-manager –add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

$ yum list docker-ce –showduplicates | sort -r

$ yum -y install docker-ce

$ docker –version

Docker version 18.05.0-ce, build f150324

$ systemctl start docker

$ systemctl status docker

$ systemctl enable docker

  • 用ansible在worker节点安装docker

$ ansible node -m copy -a 'src=/etc/yum.repos.d/docker-ce.repo dest=/etc/yum.repos.d/'

$ ansible node -m yum -a “state=present name=docker-ce”

$ ansible node -a 'docker –version'

172.18.144.191 | SUCCESS | rc=0 >>

Docker version 18.05.0-ce, build f150324

1172.18.144.190 | SUCCESS | rc=0 >>

Docker version 18.05.0-ce, build f150324

172.18.144.189 | SUCCESS | rc=0 >>

Docker version 18.05.0-ce, build f150324

$ ansible node -a 'systemctl start docker'

$ ansible node -a 'systemctl status docker'

$ ansible node -a 'systemctl enable docker'

三、配置docker swarm集群

1、创立docker swarm集群

$ docker swarm init –listen-addr 0.0.0.0

Swarm initialized: current node (a1tno675d14sm6bqlc512vf10) is now a manager.

To add a worker to this swarm, run the following command:

docker swarm join –token SWMTKN-1-3sp9uxzokgr252u1jauoowv74930s7f8f5tsmm5mlk5oim359e-dk52k5uul50w49gbq4j1y7zzb 172.18.144.188:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

2、查看节点

$ docker node ls

ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS

a1tno675d14sm6bqlc512vf10 * swarm01 Ready Active Leader

3、查看加入集群manager管理节点的命令

$ docker swarm join-token manager

To add a manager to this swarm, run the following command:

docker swarm join –token SWMTKN-1-3sp9uxzokgr252u1jauoowv74930s7f8f5tsmm5mlk5oim359e-7tdlpdnkyfl1bnq34ftik9wxw 172.18.144.188:2377

4、查看加入集群worker节点的命令

$ docker swarm join-token worker

To add a worker to this swarm, run the following command:

docker swarm join –token SWMTKN-1-3sp9uxzokgr252u1jauoowv74930s7f8f5tsmm5mlk5oim359e-dk52k5uul50w49gbq4j1y7zzb 172.18.144.188:2377

5、将前面规划的三个worker节点加入集群

$ docker swarm join –token SWMTKN-1-3sp9uxzokgr252u1jauoowv74930s7f8f5tsmm5mlk5oim359e-dk52k5uul50w49gbq4j1y7zzb 172.18.144.188:2377

This node joined a swarm as a worker.

6、查看worker节点能否已加入集群

$ docker node ls

ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION

mcc9hge72y8dhnxms6jwdqhrd * node1 Ready Active Leader 18.05.0-ce

rc8xoueu78vp2lmyv9afd5wkf node2 Ready Active 18.05.0-ce

lu8qsmf31ubk9s77bawmsxzw2 node3 Ready Active 18.05.0-ce

yl71cs8qs7s24yhvuwmdatfzp node4 Ready Active 18.05.0-ce

7、查看docker swarm的管理网络

$ docker network ls

NETWORK ID NAME DRIVER SCOPE

91e24f0c4c6b bridge bridge local

6f6790a75aee docker_gwbridge bridge local

8add841bce4f host host local

jqzdbhspwicz ingress overlay swarm

6e8c1ff220be none null local

31e09aaeec48 redis-net bridge local

这里,一个docker swarm集群就搭建好了

四、搭建docker swarm的UI—Portainer

Portainer地址:https://portainer.io/

1、用该命令部署Portainer

$ docker volume create portainer_data

$ docker service create \

–name portainer \

–publish 9000:9000 \

–replicas=1 \

–constraint 'node.role == manager' \

–mount type=bind,src=//var/run/docker.sock,dst=/var/run/docker.sock \

–mount type=volume,src=portainer_data,dst=/data \

portainer/portainer \

-H unix:///var/run/docker.sock

# docker images |grep portainer

portainer/portainer latest 07cde96d4789 2 weeks ago 10.4MB

# docker service ls ###查看集群列表

ID NAME MODE REPLICAS IMAGE PORTS

p5bo3n0fmqgz portainer replicated 1/1 portainer/portainer:latest *:9000->9000/tcp

这就部署好了

2、浏览器输入http://localhost:9000进入该UI界面,如下所示,第一次进入Portainer,配置8位数的admin密码

密码修改完成后点击“validate”验证

如下图所示,输入admin使用户名和密码进入Portainer

首页如下

docker swarm集群搭建及用Portainer管理用Docker Swarm环境

说明
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是摆设,本站源码仅提供给会员学习使用!
7. 如遇到加密压缩包,请使用360解压,如遇到无法解压的请联系管理员
开心源码网 » docker swarm集群搭建及用Portainer管理用Docker Swarm环境

发表回复