docker swarm 集群

**1.规划网络的拓扑图
在这里插入图片描述

2.准备机器,安装软件,并开启服务
1.准备6台linux centos7.9的服务器
2.安装nfs并开启服务

下载nfs服务

[root@localhost ~] yum install nfs-utils -y

开启nfs服务

[root@localhost ~]  service nfs-server start
Redirecting to /bin/systemctl start nfs-server.service

建立需要挂载的目录并授权

[root@localhost ~] mkdir /web
[root@localhost ~] chmod 777 /web

使用exportfs导出目录,无需重启nfs服务

[root@localhost ~b] exportfs -v
/web  192.168.133.0/24(rw,all_squash,sync)

3.3台使用yum安装docker 1.13的版本,设置并开启swarm集群
选择manager节点,配置host文件,添加ip和域名的对应记录

[root@localhost ~] cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
 
192.168.133.136 manager1
192.168.133.137 node2
192.168.133.138 node3

使用scp传输到另外两台节点

[root@localhost ~] scp /etc/hosts root@192.168.133.137:/etc/hosts
[root@localhost ~] scp /etc/hosts root@192.168.133.138:/etc/hosts

所有机器上关闭防火墙和selinux

[root@localhost ~] service firewalld stop
[root@localhost ~] sed  -i '/^SELINUX=/ s/enforcing/disabled/' /etc/selinux/config

创建swarm集群


[root@localhost ~] docker swarm init --advertise-addr 192.168.133.136
Swarm initialized: current node (g8hyq7b24dsfy93s6l9mx3c6g) is now a manager.
 
To add a worker to this swarm, run the following command:
 
docker swarm join --token SWMTKN-1-5y27v1oaiwrb9jvedcv9hssfxnqjw4mubjkd8vwwmyqdsaumbl-2gy1wvaraly12bko6hhe4qcy1 192.168.174.128:2377
 
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

复制docker swarm join…到其他节点上运行,加入manager节点
创建一个overlay类型的网络

[root@localhost] docker network create -d overlay ng_net

使用swarm创建容器并将数据卷挂载到nfs服务器的/web目录下

[root@localhost]docker service create -d \
    --name nfs-service \
    --mount 'type=volume,source=nfsvolume,target=/usr/share/nginx/html,volume-driver=local,volume-opt=type=nfs,volume-opt=device=:/web,"volume-opt=o=addr=192.168.133.136,rw,nfsvers=4,async"' \
    --replicas 5  \
    -p 80:80 \
    nginx:latest

3.配置前端的nginx负载均衡
1.下载nginx服务
2.修改/etc/nginx./nginx.conf 里面的配置(添加在server代码的上面)

upstream mydownload {
        server  192.168.133.136 weight=1;
        server  192.168.133.137 weight=1;
        server  192.168.133.138 weight=1;
        }

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值