Swarm管理分散式docker
作者:【吳業亮】雲端計算開發工程師
部落格:https://wuyeliang.blog.csdn.net/
在各個節點上
# yum -y install docker
# systemctl start docker
# systemctl enable docker
docker版本必須在v1.12以上,如果不是用 yum upgrade docker
# docker -v
Docker version 1.12.6, build 96d83a5/1.12.6
禁用live-restore(各個節點)
vi /etc/docker/daemon.json
{
"live-restore": false
}
重啟服務(各個節點)
# systemctl restart docker
初始化管理節點(管理節點)
# docker swarm init
Swarm initialized: current node (4ejgdnkv3ldew0ol6rpxrw1it) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join \
--token SWMTKN-1-1fhqkce0ryjzthluf5lro4mesmfuuk2apbr8339e6ybu7sj4bx-27n8grtwz9aa0cpqr7crjz2ru \
192.168.10.226:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
將work節點加入到Swarm Cluste中(work節點)
# docker swarm join \
--token SWMTKN-1-1fhqkce0ryjzthluf5lro4mesmfuuk2apbr8339e6ybu7sj4bx-27n8grtwz9aa0cpqr7crjz2ru \
192.168.10.226:2377
以下操作均在manager節點
驗證各個節點已經加入叢集中
# docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
4ejgdnkv3ldew0ol6rpxrw1it * host-192-168-10-226 Ready Active Leader
7xykqelamornqz4ovzzzw51yl host-192-168-10-227 Ready Active
ebb3mnzguc94qycs6g3q8gy2y host-192-168-10-228 Ready Active
在各個節點上構建image
節點1上Dockerfile
FROM centos
MAINTAINER serverworld <admin@cloud>
RUN yum -y install httpd
RUN echo "Hello DockerFile 1" > /var/www/html/index.html
EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
# docker build -t web_server:latest .
節點2上Dockerfile
FROM centos
MAINTAINER serverworld <admin@cloud>
RUN yum -y install httpd
RUN echo "Hello DockerFile 2 " > /var/www/html/index.html
EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
# docker build -t web_server:latest .
節點3上Dockerfile
FROM centos
MAINTAINER serverworld <admin@cloud>
RUN yum -y install httpd
RUN echo "Hello DockerFile 3 " > /var/www/html/index.html
EXPOSE 80
CMD ["-D", "FOREGROUND"]
ENTRYPOINT ["/usr/sbin/httpd"]
# docker build -t web_server:latest .
在管理節點上建立負載均衡叢集
# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
web_server latest 18494cba819c About a minute ago 318.4 MB
建立叢集
# docker service create --name swarm_cluster --replicas=2 -p 80:80 web_server:latest
20o5l3yrtssfi7au86s7t4m1f
檢視叢集
# docker service ls
ID NAME REPLICAS IMAGE COMMAND
20o5l3yrtssf swarm_cluster 0/2 web_server:latest
檢視詳細資訊
# docker service inspect swarm_cluster --pretty
ID: 20o5l3yrtssfi7au86s7t4m1f
Name: swarm_cluster
Mode: Replicated
Replicas: 2
Placement:
UpdateConfig:
Parallelism: 1
On failure: pause
ContainerSpec:
Image: web_server:latest
Resources:
Ports:
Protocol = tcp
TargetPort = 80
PublishedPort = 80
檢視容器狀態
# docker service ps swarm_cluster
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
abcz5de7owcw681mdmxwrce74 swarm_cluster.1 web_server:latest host-192-168-10-227 Running Running 26 seconds ago
euuvlsvo5fe1p79g49yo5yjrd swarm_cluster.2 web_server:latest host-192-168-10-228 Running Running 12 seconds ago
18tf6wzuc9zl5e3kkf822z17e \_ swarm_cluster.2 web_server:latest host-192-168-10-226 Shutdown Rejected 32 seconds ago "No such image: web_server:lat…"
測試
# curl http://192.168.10.226/
Hello DockerFile 3
[root@host-192-168-10-226 ~]# curl http://192.168.10.226/
Hello DockerFile 2
更改叢集的數量
# docker service scale swarm_cluster=3
swarm_cluster scaled to 3
檢視數量
# docker service ps swarm_cluster
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
abcz5de7owcw681mdmxwrce74 swarm_cluster.1 web_server:latest host-192-168-10-227 Running Running 2 minutes ago
euuvlsvo5fe1p79g49yo5yjrd swarm_cluster.2 web_server:latest host-192-168-10-228 Running Running 2 minutes ago
18tf6wzuc9zl5e3kkf822z17e \_ swarm_cluster.2 web_server:latest host-192-168-10-226 Shutdown Rejected 2 minutes ago "No such image: web_server:lat…"
5fb0cew9ih12wm4wioanm13up swarm_cluster.3 web_server:latest host-192-168-10-226 Running Preparing 11 seconds ago
相關文章
- 使用Docker Swarm搭建分散式爬蟲叢集DockerSwarm分散式爬蟲
- Docker Machine, Swarm,和Compose編排分散式應用DockerMacSwarm分散式
- 用 Docker swarm 快速部署分散式圖資料庫 Nebula Graph 叢集DockerSwarm分散式資料庫
- 【Docker】 SwarmDockerSwarm
- Docker進階-資源管理Swarm+PortainerDockerSwarmAI
- Docker管理工具 - Swarm部署記錄DockerSwarm
- Docker Swarm modeDockerSwarm
- Swirl:Docker Swarm 叢集管理的新選擇DockerSwarm
- Docker學習—SwarmDockerSwarm
- Docker Swarm:叢集DockerSwarm
- Docker Swarm叢集DockerSwarm
- Docker(六):Docker 三劍客之 Docker SwarmDockerSwarm
- Docker Swarm 叢集搭建DockerSwarm
- Docker Swarm叢集初探DockerSwarm
- Docker Swarm Mode簡介DockerSwarm
- docker swarm部署介紹DockerSwarm
- Docker Swarm入門教程DockerSwarm
- 8、docker swarm操作使用DockerSwarm
- docker 1.12 版本 docker swarm 叢集DockerSwarm
- Docker Swarm 叢集搭建教程DockerSwarm
- Docker swarm叢集搭建教程DockerSwarm
- Docker Swarm常用命令DockerSwarm
- 用docker-machine建立Docker Swarm叢集DockerMacSwarm
- Docker 學習筆記(第十集:docker 叢集管理工具 swarm )Docker筆記Swarm
- 容器技術之Docker-swarmDockerSwarm
- K8s vs Docker SwarmK8SDockerSwarm
- Docker Swarm 叢集搭建實踐DockerSwarm
- 使用Docker Swarm模式路由網格DockerSwarm模式路由
- Docker 多容器編排Swarm(六)DockerSwarm
- 1.07 容器編排docker SwarmDockerSwarm
- Docker Swarm從部署到基本操作DockerSwarm
- 利用docker-machine安裝swarmDockerMacSwarm
- Docker + Swarm + etcd 叢集搭建DockerSwarm
- 容器技術|Docker三劍客之docker-swarmDockerSwarm
- Docker Swarm 日常運維命令筆記DockerSwarm運維筆記
- Docker Swarm:建立伺服器叢集DockerSwarm伺服器
- 分散式爬蟲的部署之Gerapy分散式管理分散式爬蟲
- Docker Swarm叢集中的服務發現DockerSwarm