1. 程式人生 > >Centos7配置Docker Swarm及安裝Portainer

Centos7配置Docker Swarm及安裝Portainer

創建集群 add blog RKE rtai pre -c 服務器 rest

一、創建集群

1、初始化manager節點(xxx為manager的ip地址)

docker swarm init --advertise-addr xxx.xxx.xxx.xxx

會輸出以下內容,註意加粗斜體命令,加入集群需要使用

Swarm initialized: current node (pk4p936t4e03cpse3izuws07s) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token xxx xxx.xxx.xxx.xxx:2377


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

2、worker加入集群,在其他docker服務器運行上面命令

docker swarm join --token xxx xxx.xxx.xxx.xxx:2377

3、查看集群情況

docker node ls

技術分享圖片

二、安裝Portainer

1、創建portainer-stack.yml文件

version: ‘3‘
services:

  portainer:
    image: portainer/portainer
    volumes:
      - "/var/run/docker.sock:/var/run/docker.sock"
      - "/data/portainer:/data"
    deploy:
      placement:
        constraints: [node.role == manager] # 控制管理界面部署在manager上
      replicas: 1
      restart_policy:
        condition: on-failure
      resources:
        limits:
          cpus: "0.2"
          memory: 200M
      labels: [svc=portainer]
    ports:
      - 9000:9000

2、啟動portainer服務

docker stack deploy -c portainer-stack.yml portainer

3、訪問portainer並修改密碼(xxx為集群的任意一臺ip,swarm會自動做負載均衡)

訪問http://xxx.xxx.xxx.xxx:9000

Centos7配置Docker Swarm及安裝Portainer