docker swarm

docker swarm

系统:CentOS 7
docker版本:docker-ce-18.03.1
2台主机

主机名ip
manager192.168.10.131
woker192.168.10.130

环境搭建

配置安装yum管理工具,添加dokcer阿里源

配置阿里的docker yum源,快速下载docker-ce

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

安装docker-ce

[root@manager ~]# yum list docker-ce --showduplicates | sort -r
 * updates: mirrors.aliyun.com
Loading mirror speeds from cached hostfile
Loaded plugins: fastestmirror
Installed Packages
 * extras: mirrors.aliyun.com
docker-ce.x86_64            3:18.09.0-3.el7                    docker-ce-stable 
docker-ce.x86_64            18.06.1.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.06.0.ce-3.el7                   docker-ce-stable 
docker-ce.x86_64            18.03.1.ce-1.el7.centos            docker-ce-stable 
# 我这里选择docker-ce-18.03.1.ce版本 
yum -y install docker-ce-18.03.1.ce

配置docker

vim /lib/systemd/system/docker.service
在ExecStart后添加 -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock
–bip是docker默认初始化网络网段,可不加。

# the default is not to use systemd for cgroups because the delegate issues still
# exists and systemd currently does not support the cgroup feature set required
# for containers run by docker
ExecStart=/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --bip=10.18.18.1/24

禁用selinux

vim /etc/selinux/config

SELINUX=disable

reboot
重启后生效

上面2个主机都这样配置

docker swarm

启动docker服务

systemctl start docker

初始化管理节点

在manager主机

[root@manager ~]# docker swarm init --advertise-addr  192.168.10.131
Swarm initialized: current node (7jfig6733t8gf6afzrzr5ro2g) is now a manager.

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

    docker swarm join --token SWMTKN-1-0jdml8q0tnvxn6jet7qgyj88xn5dls0sp9q1xwf8egcx5pxss4-bm0cf6fytdolbvcidod73ispw 192.168.10.131:2377

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

其它节点加入docker swarm集群

在woker主机
有2个关键信息,令牌与管理节点通信地址

[root@worker ~]# docker swarm join --token SWMTKN-1-0jdml8q0tnvxn6jet7qgyj88xn5dls0sp9q1xwf8egcx5pxss4-bm0cf6fytdolbvcidod73ispw 192.168.10.131:2377
This node joined a swarm as a worker.

查看节点列表

在管理节点上

[root@manager ~]# docker node ls
ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
7jfig6733t8gf6afzrzr5ro2g *   manager             Ready               Active              Leader              18.03.1-ce
3q7tggdv8kd4czlywgshz88q1     worker              Ready               Active                                  18.03.1-ce

创建docker service

[root@manager ~]# docker pull nginx
[root@manager ~]# docker service create --replicas 1 --name nginx -p 8080:80  nginx
58onndkgy9c18oxxlovyz7aj0
overall progress: 1 out of 1 tasks 
1/1: running   [==================================================>] 
verify: Service converged 

可以从swarm集群任意1节点访问到nginx

在这里插入图片描述
https://docs.docker.com/engine/swarm/images/ingress-routing-mesh.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值