1、准备机器
manager-ha-master 172.31.72.142
manager-ha-backup 172.31.82.187
manager3 172.31.61.130
woker-smarthome 172.31.80.14
woker-justfitv2 172.31.76.147
work-oss 172.31.56.103
2、Docker Ce版安装
yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo (国外)
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo (国内)
yum-config-manager --disable docker-ce-edge
yum install docker-ce -y
3、启动Docker
systemctl enable docker && systemctl start docker
systemctl status docker
4、manager机器1:
docker swarm init --advertise-addr 172.31.72.142
5、为mananger1添加worker:
docker swarm join --token SWMTKN-1-5q21bxnln5799he8fnll8yggp8caxryickc3j9xmaozvgwe97s-e11wyfdcrsbewpx97823ep6xa 172.31.72.142:2377
To get manager token:
docker swarm join-token manager
To get worker token:
docker swarm join-token worker
6、把manager2添加到swarm中。
[root@master1 centos]# docker swarm join-token manager
To add a manager to this swarm, run the following command:
docker swarm join --token SWMTKN-1-5q21bxnln5799he8fnll8yggp8caxryickc3j9xmaozvgwe97s-44dqddtgbamyu8s292jyuy66k 172.31.72.142:2377
7、安装docker swarm UI portainer
# mypassword is plaintext here
$ echo -n bosma2018 | docker secret create portainer-pass -
$ docker service create \
--name portainer \
--secret portainer-pass \
--publish 9000:9000 \
--replicas=1 \
--constraint 'node.role == manager' \
--mount type=bind,src=/var/run/docker.sock,dst=/var/run/docker.sock \
portainer/portainer \
--admin-password-file '/run/secrets/portainer-pass' \
-H unix:///var/run/docker.sock
8、利用软链接,修改docker默认的数据路径。
systemctl stop docker
mv /var/lib/docker /app/
ln -s /app/docker /var/lib/docker
systemctl start docker
systemctl status docker
9、在haproxy配置
frontend dashboard
bind 172.31.72.142:80
mode tcp
option tcplog
default_backend docker-dashboard
backend docker-dashboard
mode tcp
option tcplog
option tcp-check
balance roundrobin
default-server inter 10s downinter 5s rise 2 fall 2 slowstart 60s maxconn 250 maxqueue 256 weight 100
server m1 172.31.72.142:9000 check
server m2 172.31.82.187:9000 check
server m3 172.31.61.130:9000 check
server n1 172.31.76.147:9000 check
server n2 172.31.80.14:9000 check
server n3 172.31.56.103:9000 check