Конфигурация и управление на Docker Swarm клъстер

Конфигурация и инсталация на Docker Swarm клъстер

 

Ще използваме 3 CentOS 7 Linux сървъра за да създадем нашият Docker Swarm клъстер.

В случаят искаме да имаме 2 хоста които да бъдат в роля manager и 1 хост който да бъде worker.

manager1 192.168.203.202

manager2 192.168.203.203

worker1 192.168.203.204

 

 

Нека инсталираме docker по всички линукс сървъри:

Хост 1

[root@manager1 src]# curl -fsSL https://get.docker.com/ | sh
[root@manager1 src]# docker --version
Docker version 18.09.6, build 481bc77156

[root@manager1 src]# systemctl start docker

[root@manager1 src]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Хост 2

[root@manager2 src]# curl -fsSL https://get.docker.com/ | sh
[root@manager2 src]# docker --version
Docker version 18.09.6, build 481bc77156

[root@manager2 src]# systemctl start docker

[root@manager2 src]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

Хост 3

[root@worker1 src]# curl -fsSL https://get.docker.com/ | sh
[root@worker1 src]# docker --version
Docker version 18.09.6, build 481bc77156

[root@worker1 src]# systemctl start docker

[root@worker1 src]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.

 

Инициализираме docker swarm клъстера

[root@manager1 src]# docker swarm init --advertise-addr 192.168.203.202
Swarm initialized: current node (sgdny5h0p6locxx5jzvg3uhot) is now a manager.

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

docker swarm join –token SWMTKN-1-6a3qnogynlk7gemdzslgks8238ad213b3gyr56th8vkzelll-ebc4xr05sydjmkzrzh6bkqy14 192.168.203.202:2377

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

 

 

Нека видим статуса на нашият swarm cluster.

[root@manager1 src]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
sgdny5h0p6locxx5jzvg3uhot * manager1 Ready Active Leader 18.09.6
[root@manager1 src]#

Добавяме worker нода.

[root@worker1 ~]# docker swarm join --token SWMTKN-1-6a3qnogynlk7gemdzslgks8238ad213b3gyr56th8vkzelll-ebc4xr05sydjmkzrzh6bkqy14 192.168.203.202:2377
This node joined a swarm as a worker.

Проверяваме статуса на swarm клъстера от manager1 хоста.

[root@manager1 src]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
sgdny5h0p6locxx5jzvg3uhot * manager1 Ready Active Leader 18.09.6
2yo66vj01k4tus6hqceoa61nu worker1 Ready Active 18.09.6

За да добавим втори manager нод, трябва да генерираме друг token за присъединяване в swarm клъстера.

[root@manager1 src]# docker swarm join-token manager
To add a manager to this swarm, run the following command:

docker swarm join –token SWMTKN-1-6a3qnogynlk7gemdzslgks9uxgf3s9wyqb3gyr78th8vkzelll-bsm9zljlogmkq2wamdo0tb4q2 192.168.203.202:2377

Сега, от manager2 нода изпълняваме следното:

docker swarm join --token SWMTKN-1-6a3qnogynlk7gemdzslgks9uxgf3s9wyqb3gyr78th8vkzelll-bsm9zljlogmkq2wamdo0tb4q2 192.168.203.202:2377
This node joined a swarm as a manager.

Проверяваме статуса отново:

[root@manager1 src]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
sgdny5h0p6locxx5jzvg3uhot * manager1 Ready Active Leader 18.09.6
uqmse3jw6g54twdrxdyw4qgyj manager2 Ready Active Reachable 18.09.6
2yo66vj01k4tus6hqceoa61nu worker1 Ready Active 18.09.6

Проверяваме статус и от manager2:

[root@manager2 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
sgdny5h0p6locxx5jzvg3uhot manager1 Ready Active Leader 18.09.6
uqmse3jw6g54twdrxdyw4qgyj * manager2 Ready Active Reachable 18.09.6
2yo66vj01k4tus6hqceoa61nu worker1 Ready Active 18.09.6

Когато имаме инфраструктура която налага използване на повече от един manager, препоръчва се да се използва нечетен брой число за нодове които да работят като „manager“ , например 1, 3 5 .

По този начин може да променим ролята на нод worker1 да бъде в роля на manager:

[root@manager1 ~]# docker node promote worker1
Node worker1 promoted to a manager in the swarm.


[root@manager1 ~]# docker node inspect worker1
[
{
"ID": "7feqyrkai0ovsxchu8ztglnb7",
"Version": {
"Index": 69
},
"CreatedAt": "2019-06-04T09:58:48.220152558Z",
"UpdatedAt": "2019-06-04T10:03:16.287182059Z",
"Spec": {
"Labels": {},
"Role": "manager",
"Availability": "active"
},

Нека проверим нодовете от worker1 който има роля на manager в момента:

[root@worker1 ~]# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
sgdny5h0p6locxx5jzvg3uhot manager1 Ready Active Reachable 18.09.6
uqmse3jw6g54twdrxdyw4qgyj manager2 Ready Active Leader 18.09.6
7feqyrkai0ovsxchu8ztglnb7 * worker1 Ready Active Reachable 18.09.6

Заявете безплатна оферта

Ние предлагаме професионални услуги в сферата на ..

Още от нашия блог

Всички постове

Recent Posts