日日操夜夜添-日日操影院-日日草夜夜操-日日干干-精品一区二区三区波多野结衣-精品一区二区三区高清免费不卡

公告:魔扣目錄網為廣大站長提供免費收錄網站服務,提交前請做好本站友鏈:【 網站目錄:http://www.ylptlb.cn 】, 免友鏈快審服務(50元/站),

點擊這里在線咨詢客服
新站提交
  • 網站:51998
  • 待審:31
  • 小程序:12
  • 文章:1030137
  • 會員:747

目錄
  • 創建etcd數據目錄
  • 創建docker網絡
  • etcd-cluster-compose.yml
  • 啟動并驗證集群
    • 啟動
    • 驗證集群
  • k/v操作
    • CURL
    • etcdctl
  • 總結

    需要安裝:

    • docker
    • docker-compose

    參數詳細:

    • –name:設置成員節點的別名,建議為每個成員節點配置可識別的命名
    • –advertise-client-urls:廣播到集群中本成員的監聽客戶端請求的地址
    • –initial-advertise-peer-urls:廣播到集群中本成員的Peer監聽通信地址
    • –listen-client-urls:客戶端請求的監聽地址列表
    • –listen-peer-urls:Peer消息的監聽服務地址列表
    • –initial-cluster-token:啟動集群的時候指定集群口令,只有相同token的幾點才能加入到同一集群
    • –initial-cluster:所有集群節點的地址列表
    • –initial-cluster-state:初始化集群狀態,默認為new,也可以指定為exi-string表示要加入到一個已有集群

    創建etcd數據目錄

    mkdir -p ./etcd-node{1,2,3}

    創建docker網絡

    docker network create --driver bridge --subnet 172.62.0.0/16 --gateway 172.62.0.1 etcd-cluster

    etcd-cluster-compose.yml

    version: '3'
    
    networks:
      etcd-cluster:
        external: true
    
    services:
      etcd-node1:
        image: quay.io/coreos/etcd:v3.3.1
        container_name: etcd-node1
        ports:
          - "12379:2379"
          - "12380:2380"
        restart: always
        volumes:
          - ./etcd-node1:/data/app/etcd
        command: etcd --name etcd-node1 --data-dir /data/app/etcd/ --advertise-client-urls http://172.62.0.10:2379 --initial-advertise-peer-urls http://172.62.0.10:2380 --listen-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-node1=http://172.62.0.10:2380,etcd-node2=http://172.62.0.11:2380,etcd-node3=http://172.62.0.12:2380" --initial-cluster-state new
        networks:
          etcd-cluster:
            ipv4_address: 172.62.0.10
    
      etcd-node2:
        image: quay.io/coreos/etcd:v3.3.1
        container_name: etcd-node2
        ports:
          - "22379:2379"
          - "22380:2380"
        restart: always
        volumes:
          - ./etcd-node2:/data/app/etcd
        command: etcd --name etcd-node2 --data-dir /data/app/etcd/ --advertise-client-urls http://172.62.0.11:2379 --initial-advertise-peer-urls http://172.62.0.11:2380 --listen-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-node1=http://172.62.0.10:2380,etcd-node2=http://172.62.0.11:2380,etcd-node3=http://172.62.0.12:2380" --initial-cluster-state new
        networks:
          etcd-cluster:
            ipv4_address: 172.62.0.11
    
      etcd-node3:
        image: quay.io/coreos/etcd:v3.3.1
        container_name: etcd-node3
        ports:
          - "32379:2379"
          - "32380:2380"
        restart: always
        volumes:
          - ./etcd-node3:/data/app/etcd
        command: etcd --name etcd-node3 --data-dir /data/app/etcd/ --advertise-client-urls http://172.62.0.12:2379 --initial-advertise-peer-urls http://172.62.0.12:2380 --listen-client-urls http://0.0.0.0:2379 --listen-peer-urls http://0.0.0.0:2380 --initial-cluster-token etcd-cluster --initial-cluster "etcd-node1=http://172.62.0.10:2380,etcd-node2=http://172.62.0.11:2380,etcd-node3=http://172.62.0.12:2380" --initial-cluster-state new
        networks:
          etcd-cluster:
            ipv4_address: 172.62.0.12
    

    啟動并驗證集群

    啟動

    [root@k8s-node1 etcd-cluster]# docker-compose -f etcd-cluster-compose.yml up -d
    Pulling etcd-node1 (quay.io/coreos/etcd:v3.3.1)...
    v3.3.1: Pulling from coreos/etcd
    ff3a5c916c92: Pull complete
    dec5fcc85a18: Pull complete
    3944f16f0112: Pull complete
    0b6d29b049fe: Pull complete
    d8c39ae91d38: Pull complete
    42fcea4864ba: Pull complete
    Digest: sha256:454e69370d87554dcb4272833b8f07ce1b5d457caa153bda4070b76d89a1cc97
    Status: Downloaded newer image for quay.io/coreos/etcd:v3.3.1
    Creating etcd-node1 ... done
    Creating etcd-node2 ... done
    Creating etcd-node3 ... done
    
    [root@k8s-node1 etcd-cluster]# docker-compose -f etcd-cluster-compose.yml ps -a
       Name                 Command               State                        Ports
    ------------------------------------------------------------------------------------------------------
    etcd-node1   etcd --name etcd-node1 --d ...   Up      0.0.0.0:12379->2379/tcp, 0.0.0.0:12380->2380/tcp
    etcd-node2   etcd --name etcd-node2 --d ...   Up      0.0.0.0:22379->2379/tcp, 0.0.0.0:22380->2380/tcp
    etcd-node3   etcd --name etcd-node3 --d ...   Up      0.0.0.0:32379->2379/tcp, 0.0.0.0:32380->2380/tcp
    

    驗證集群

    通過etcdctl member list命令可以查詢出所有集群節點的列表并且結果一致即為成功

    [root@k8s-node1 etcd-cluster]# docker exec -it  etcd-node1 /bin/sh
    / # etcdctl member list
    8cef47d732d4acff: name=etcd-node1 peerURLs=http://172.62.0.10:2380 clientURLs=http://172.62.0.10:2379 isLeader=false
    c93af917b643516f: name=etcd-node3 peerURLs=http://172.62.0.12:2380 clientURLs=http://172.62.0.12:2379 isLeader=true
    cdee7114ad135065: name=etcd-node2 peerURLs=http://172.62.0.11:2380 clientURLs=http://172.62.0.11:2379 isLeader=false
    / # exit
    [root@k8s-node1 etcd-cluster]# docker exec -it  etcd-node2 /bin/sh
    / # etcdctl member list
    8cef47d732d4acff: name=etcd-node1 peerURLs=http://172.62.0.10:2380 clientURLs=http://172.62.0.10:2379 isLeader=false
    c93af917b643516f: name=etcd-node3 peerURLs=http://172.62.0.12:2380 clientURLs=http://172.62.0.12:2379 isLeader=true
    cdee7114ad135065: name=etcd-node2 peerURLs=http://172.62.0.11:2380 clientURLs=http://172.62.0.11:2379 isLeader=false
    [root@k8s-node1 etcd-cluster]# docker exec -it  etcd-node3 /bin/sh
    / # etcdctl member list
    8cef47d732d4acff: name=etcd-node1 peerURLs=http://172.62.0.10:2380 clientURLs=http://172.62.0.10:2379 isLeader=false
    c93af917b643516f: name=etcd-node3 peerURLs=http://172.62.0.12:2380 clientURLs=http://172.62.0.12:2379 isLeader=true
    cdee7114ad135065: name=etcd-node2 peerURLs=http://172.62.0.11:2380 clientURLs=http://172.62.0.11:2379 isLeader=false
    

    k/v操作

    CURL

    新增

    [root@k8s-node1 etcd-cluster]# docker-compose -f etcd-cluster-compose.yml ps -a
       Name                 Command               State                        Ports
    ------------------------------------------------------------------------------------------------------
    etcd-node1   etcd --name etcd-node1 --d ...   Up      0.0.0.0:12379->2379/tcp, 0.0.0.0:12380->2380/tcp
    etcd-node2   etcd --name etcd-node2 --d ...   Up      0.0.0.0:22379->2379/tcp, 0.0.0.0:22380->2380/tcp
    etcd-node3   etcd --name etcd-node3 --d ...   Up      0.0.0.0:32379->2379/tcp, 0.0.0.0:32380->2380/tcp
    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/version
    {"etcdserver":"3.3.1","etcdcluster":"3.3.0"}[root@k8s-node1 etcd-cluster]#
    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X PUT -d value=https://blog.alexcld.com
    {"action":"set","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
    

    查詢

    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X GET
    {"action":"get","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:22379/v2/keys/Alexclownfish -X GET
    {"action":"get","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:32379/v2/keys/Alexclownfish -X GET
    {"action":"get","node":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
    

    修改

    同新建一樣

    刪除

    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X DELETE
    {"action":"delete","node":{"key":"/Alexclownfish","modifiedIndex":20,"createdIndex":19},"prevNode":{"key":"/Alexclownfish","value":"https://blog.alexcld.com","modifiedIndex":19,"createdIndex":19}}
    [root@k8s-node1 etcd-cluster]# curl -L http://127.0.0.1:12379/v2/keys/Alexclownfish -X GET
    {"errorCode":100,"message":"Key not found","cause":"/Alexclownfish","index":20}

    etcdctl

    新增

    / # etcdctl set clownfish 1234567
    1234567
    / # etcdctl get clownfish
    1234567

    查詢

    / # etcdctl get clownfish
    1234567

    修改

    / # etcdctl get clownfish
    1234567
    / # etcdctl set clownfish 987654321ddd
    987654321ddd
    / # etcdctl get clownfish
    987654321ddd

    刪除

    / # etcdctl rm clownfish
    PrevNode.Value: 987654321ddd
    / # etcdctl get clownfish
    Error: ?100: Key not found (/clownfish) [23]

    總結

    以上為個人經驗,希望能給大家一個參考,也希望大家多多支持。

    分享到:
    標簽:Docker etcd 服務器 部署 集群
    用戶無頭像

    網友整理

    注冊時間:

    網站:5 個   小程序:0 個  文章:12 篇

    • 51998

      網站

    • 12

      小程序

    • 1030137

      文章

    • 747

      會員

    趕快注冊賬號,推廣您的網站吧!
    最新入駐小程序

    數獨大挑戰2018-06-03

    數獨一種數學游戲,玩家需要根據9

    答題星2018-06-03

    您可以通過答題星輕松地創建試卷

    全階人生考試2018-06-03

    各種考試題,題庫,初中,高中,大學四六

    運動步數有氧達人2018-06-03

    記錄運動步數,積累氧氣值。還可偷

    每日養生app2018-06-03

    每日養生,天天健康

    體育訓練成績評定2018-06-03

    通用課目體育訓練成績評定