swarmクラスタ操作の詳細

21899 ワード

文書ディレクトリ
  • swarmクラスタ共通動作
  • ノード情報表示
  • 修正ノード
  • ノード
  • を除去する.
  • 導入アプリケーション
  • サービス作成
  • サービスパラメータ修正(ここでのミラーは、ネットワーク速度のために最小のhello-worldを使用しており、エラー箇所はしばらく無視)
  • サービス
  • の表示
  • タスクリストを表示
  • サービス詳細を表示
  • 削除サービス
  • サービスログを表示
  • 前編のクラスタ構築操作の終了後、クラスタに関する操作コマンドについて説明します
    swarmクラスタの一般的な操作
  • は、クラスタが破損した場合、クラスタトラフィックに影響を及ぼさずにリセットする必要がある
  •   docker swarm init --force-new-cluste
    

    ノード情報の表示
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active              Reachable           18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    
          
    
    ①   id
    [root@swarm01 /]# docker node ls -q
    2g6592p43eonilcjvivw3ww1f
    x64fuzm4y70ov30i5txx327a9
    hka4wtaqt05hsme3c5ycp2nmp
    [root@swarm01 /]# 
    ②      (     name id)
    [root@swarm01 /]# docker node ls -f name=swarm01
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    

    ノードの変更
        :    
    
        :manager-> worker
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active              Reachable           18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    [root@swarm01 /]# docker node demote swarm02
    Manager swarm02 demoted in the swarm.
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    
        : worker -> manager
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    [root@swarm01 /]# docker node promote swarm02
    Node swarm02 promoted to a manager in the swarm.
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active              Reachable           18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    
          
    --advertise-addr: ip
    --listen-addr: ip   
    --availability:       ("active"|"pause"|"drain")
    --role:worker manager
    
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active              Reachable           18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    [root@swarm01 /]# docker node update --role worker swarm02
    swarm02
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    
    

    ノードの削除
            
    ①    : swarm03(       )
    [root@swarm03 ~]# docker swarm leave
    Node left the swarm.
    [root@swarm03 ~]# 
    ②    :swarm01(    )
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Ready               Active                                  18.09.4
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
    hka4wtaqt05hsme3c5ycp2nmp     swarm03             Down                Active                                  18.09.4
    [root@swarm01 /]# docker node rm swarm03
    swarm03
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
          docker node leave           Down,         docker node rm   
    
              ,       
    [root@swarm01 /]# docker node rm swarm03
    Error response from daemon: rpc error: code = FailedPrecondition desc = node 2wo6hxhxa3loms06o3midxhdj is not down and can't be removed
          
    [root@swarm01 /]# docker node rm -f swarm03
    swarm03
    [root@swarm01 /]# docker node ls
    ID                            HOSTNAME            STATUS              AVAILABILITY        MANAGER STATUS      ENGINE VERSION
    2g6592p43eonilcjvivw3ww1f *   swarm01             Ready               Active              Leader              18.09.4
    x64fuzm4y70ov30i5txx327a9     swarm02             Ready               Active                                  18.09.4
    [root@swarm01 /]# 
    

    アプリケーションの配備
    サービスの作成
    docker service create–detach、-d:コンテナがフロントで実行されるかバックグラウンドで実行されるかを指定します.デフォルトはfalse–name:サービス名–network:ネットワーク接続–publish、-p:ポートマッピング–env、-e:環境変数–tty、-t:ttyデバイスの割り当てをサポートします.これは、端末登録–mount:ファイルマウント–replicas:タスク数の指定をサポートします.
      hello-world          demo
    [root@swarm01 usr]# docker service create --replicas 3 -p 443:8080 --name hello \
    > --mount type=bind,source=/storage/apiapp_log,destination=/go/src/logs \
    > --mount type=bind,source=/root/apiapp/app.conf,destination=/root/app.conf \
    > --mount type=bind,source=/root/apiapp/run_application.sh,destination=/root/run_application.sh \
    > -e RUN_MODE=Production \
    > -td hello-wrold:latest
    image hello-wrold:latest could not be accessed on a registry to record
    its digest. Each node will access hello-wrold:latest independently,
    possibly leading to different nodes running different
    versions of the image.
    
    xfmlwf4eo9b27jlhrh889wooy
    [root@swarm01 usr]# 
    
            
    [root@swarm01 usr]# docker service ls
    ID                  NAME                MODE                REPLICAS            IMAGE                PORTS
    xfmlwf4eo9b2        hello               replicated          0/3                 hello-wrold:latest   *:443->8080/tcp
    [root@swarm01 usr]# 
    

    サービスパラメータ修正(ここでのミラーはネット速度のため最小のhello-worldを使用しており、エラー箇所はしばらく無視)
    docker service update [OPTIONS] SERVICE
    
    [root@swarm01 /]# docker service update --replicas 2 hello
    hello
    overall progress: 0 out of 2 tasks 
    1/2: preparing [=================================>                 ] 
    2/2: preparing [=================================>                 ] 
    service update paused: update paused due to failure or early termination of task 4yk09qa7z8rw11517ucmxgxku
    
            ,          :docker service scale service=replicas。。。       
    
    

    サービスの表示
    [root@swarm01 ~]# docker service ls (options)
    ID                  NAME                MODE                REPLICAS            IMAGE                PORTS
    xfmlwf4eo9b2        hello               replicated          0/3                 hello-wrold:latest   *:443->8080/tcp
    
    --filter             
    

    タスク・リストの表示
    docker service ps [OPTIONS] SERVICE [SERVICE...]  (  filter    )【      】
    [    ,          ,             ]
    [root@swarm01 /]# docker service ps hello
    ID                  NAME                IMAGE                NODE                DESIRED STATE       CURRENT STATE                 ERROR                              PORTS
    jfpqsqh46n4h        hello.1             hello-wrold:latest   swarm02             Running             Preparing 11 seconds ago                                         
    vovkm6h5g4zk         \_ hello.1         hello-wrold:latest   swarm01             Shutdown            Rejected 12 seconds ago       "invalid mount config for type??   
    unuabe9yy49l         \_ hello.1         hello-wrold:latest   swarm03             Shutdown            Rejected 38 seconds ago       "invalid mount config for type??   
    l8apmw48cjiq         \_ hello.1         hello-wrold:latest   swarm02             Shutdown            Rejected about a minute ago   "invalid mount config for type??   
    ue2057am4lps         \_ hello.1         hello-wrold:latest   swarm01             Shutdown            Rejected about a minute ago   "invalid mount config for type??   
    k1i9e990753w        hello.2             hello-wrold:latest   swarm02             Running             Preparing 40 seconds ago                                         
    2ezv34jno81a         \_ hello.2         hello-wrold:latest   swarm03             Shutdown            Rejected 41 seconds ago       "invalid mount config for type??   
    k3qwlh6ocukc         \_ hello.2         hello-wrold:latest   swarm02             Shutdown            Rejected about a minute ago   "invalid mount config for type??   
    h9jqy8coh3qd         \_ hello.2         hello-wrold:latest   swarm03             Shutdown            Rejected about a minute ago   "invalid mount config for type??   
    nujear2hj645         \_ hello.2         hello-wrold:latest   swarm01             Shutdown            Rejected 2 minutes ago        "invalid mount config for type??   
    hyhstj0fngak        hello.3             hello-wrold:latest   swarm02             Running             Preparing 15 seconds ago                                         
    xeqe7xgebbd4         \_ hello.3         hello-wrold:latest   swarm01             Shutdown            Rejected 15 seconds ago       "invalid mount config for type??   
    elmh2v12o16s         \_ hello.3         hello-wrold:latest   swarm03             Shutdown            Rejected 51 seconds ago       "invalid mount config for type??   
    d7u4yxhu70db         \_ hello.3         hello-wrold:latest   swarm01             Shutdown            Rejected about a minute ago   "invalid mount config for type??   
    vcwia4wqthfq         \_ hello.3         hello-wrold:latest   swarm02             Shutdown            Rejected about a minute ago   "invalid mount config for type??
    

    サービス詳細の表示
    docker service inspect [OPTIONS] SERVICE [SERVICE...]       
    
    [root@swarm01 /]# docker service inspect hello
    
    

    サービスの削除
    docker service rm SERVICE [SERVICE...]
    
    [root@swarm01 /]# docker service ls
    ID                  NAME                MODE                REPLICAS            IMAGE                PORTS
    xfmlwf4eo9b2        hello               replicated          0/3                 hello-wrold:latest   *:443->8080/tcp
    [root@swarm01 /]# docker service rm hello
    hello
    [root@swarm01 /]# docker service ls
    ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
    [root@swarm01 /]# 
    

    サービスログの表示
    docker service logs [OPTIONS] SERVICE|TASK
    --follow , -f:     
    --tail:      N   
    --since:               
    --timestamps , -t:      
    

    この記事はdokcer swarmクラスタの構築が完了したベースペーパーに作成されています.アドレスを参照してください.https://zhuanlan.zhihu.com/p/61535537