一共三台主机 192.168.19.4 192.168.19.5 192.168.19.6
192.168.19.4 设置主机名
[root@centos redis-cluster]
[root@centos redis-cluster]
初始化swarm集群
[root@centos redis-cluster]
Swarm initialized: current node (lfjk87d0pguk7tkgoj69fu9nq) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-adqinc1qrub0uyti0683hjqvw 192.168.19.4:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
获取加入令牌
[root@centos redis-cluster]
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-b1r2kkd4ccic3jpdlpsh8sjlq 192.168.19.4:2377
[root@centos redis-cluster]
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-526bzo5skkyhb509xk6mpbmsm5wepnbt12clg68ozr0n93emtf-adqinc1qrub0uyti0683hjqvw 192.168.19.4:2377
[root@centos redis-cluster]
查询集群的所有节点
[root@centos redis-cluster]
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
lfjk87d0pguk7tkgoj69fu9nq * manager Ready Active Leader 20.10.11
192.168.19.5 设置机器名
[root@centos ~]
加入集群
[root@centos ~]
This node joined a swarm as a worker.
192.168.19.4 创建服务
[root@centos redis-cluster]
puajwi3kllcgd482vdyqdm4mn
overall progress: 1 out of 1 tasks
1/1: running [==================================================>]
verify: Service converge
查看服务
[root@centos redis-cluster]
ID NAME MODE REPLICAS IMAGE PORTS
puajwi3kllcg mynginx replicated 1/1 nginx:latest *:80->80/tcp
[root@centos redis-cluster]
ID: yirs931yqmkzwjkuhhlrvyex3
Name: mynginx
Service Mode: Replicated
Replicas: 1
Placement:
UpdateConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Update order: stop-first
RollbackConfig:
Parallelism: 1
On failure: pause
Monitoring Period: 5s
Max failure ratio: 0
Rollback order: stop-first
ContainerSpec:
Image: nginx:latest@sha256:9522864dd661dcadfd9958f9e0de192a1fdda2c162a35668ab6ac42b465f0603
Init: false
Resources:
Endpoint Mode: vip
Ports:
PublishedPort = 80
Protocol = tcp
TargetPort = 80
PublishMode = ingress
动态扩容
[root@centos redis-cluster]
mynginx scaled to 2
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged
[root@centos redis-cluster]
ID NAME MODE REPLICAS IMAGE PORTS
puajwi3kllcg mynginx replicated 2/2 nginx:latest *:80->80/tcp
查看192.168.19.4机器
[root@centos redis-cluster]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
fe5299cd8172 nginx:latest "/docker-entrypoint.…" 7 minutes ago Up 7 minutes 80/tcp mynginx.1.4d3c535tl0jid28z5i54info9
5ae1db544afc redis "docker-entrypoint.s…" 29 minutes ago Exited (0) 27 minutes ago redis-6372
查看192.168.19.5机器
[root@centos ~]
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5d7aa8a46a8c nginx:latest "/docker-entrypoint.…" About a minute ago Up About a minute 80/tcp mynginx.2.jqpo0xtpdo6usuavhmiptu0py
都部署了 nginx
查看服务跑在那台机器上 注意:只能在manage节点使用
[root@centos redis-cluster]
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTS
4d3c535tl0ji mynginx.1 nginx:latest manager Running Running 12 minutes ago
jqpo0xtpdo6u mynginx.2 nginx:latest worker Running Running 6 minutes ago
服务应用滚动更新
[root@centos redis-cluster]
mynginx
overall progress: 2 out of 2 tasks
1/2: running [==================================================>]
2/2: running [==================================================>]
verify: Service converged
注意:
- manager节点加入不上;关闭机器的防火墙就可以了
|