• 利用etcd实现docker跨主机通信


    etcd实现分布是存储,然后让通信等数据共享。

    步骤:

    安装etcd

    docker重启加载etcd参数

    建立docker overlay网络验证跨主机通信

    准备:两台安装了docker 的linux主机

    安装etcd

    
    
    在docker-node1上

     
    ubuntu@docker-node1:~$ wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gz
    ubuntu@docker-node1:~$ tar zxvf etcd-v3.0.12-linux-amd64.tar.gz
    ubuntu@docker-node1:~$ cd etcd-v3.0.12-linux-amd64
    ubuntu@docker-node1:~$ nohup ./etcd --name docker-node1 --initial-advertise-peer-urls http://192.168.205.10:2380
    --listen-peer-urls http://192.168.205.10:2380
    --listen-client-urls http://192.168.205.10:2379,http://127.0.0.1:2379
    --advertise-client-urls http://192.168.205.10:2379
    --initial-cluster-token etcd-cluster
    --initial-cluster docker-node1=http://192.168.205.10:2380,docker-node2=http://192.168.205.11:2380
    --initial-cluster-state new&
     

    在docker-node2上

     
    ubuntu@docker-node2:~$ wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gz
    ubuntu@docker-node2:~$ tar zxvf etcd-v3.0.12-linux-amd64.tar.gz
    ubuntu@docker-node2:~$ cd etcd-v3.0.12-linux-amd64/
    ubuntu@docker-node2:~$ nohup ./etcd --name docker-node2 --initial-advertise-peer-urls http://192.168.205.11:2380
    --listen-peer-urls http://192.168.205.11:2380
    --listen-client-urls http://192.168.205.11:2379,http://127.0.0.1:2379
    --advertise-client-urls http://192.168.205.11:2379
    --initial-cluster-token etcd-cluster
    --initial-cluster docker-node1=http://192.168.205.10:2380,docker-node2=http://192.168.205.11:2380
    --initial-cluster-state new&
     

    重启docker加载etcd

    检查cluster状态
    
    
    ubuntu@docker-node2:~/etcd-v3.0.12-linux-amd64$ ./etcdctl cluster-health
    member 21eca106efe4caee is healthy: got healthy result from http://192.168.205.10:2379
    member 8614974c83d1cc6d is healthy: got healthy result from http://192.168.205.11:2379
    cluster is healthy
    
    
    ## 重启docker服务
    
    
    在docker-node1上
    
    $ sudo service docker stop
    $ sudo /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://192.168.205.10:2379 --cluster-advertise=192.168.205.10:2375&
    
    
    在docker-node2上
    
    
    $ sudo service docker stop
    $ sudo /usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://192.168.205.11:2379 --cluster-advertise=192.168.205.11:2375&
    
    

      

    创建docker overlay网络验证通信

    在docker-node1上创建一个demo的overlay network
    
    ubuntu@docker-node1:~$ sudo docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    0e7bef3f143a        bridge              bridge              local
    a5c7daf62325        host                host                local
    3198cae88ab4        none                null                local
    ubuntu@docker-node1:~$ sudo docker network create -d overlay demo
    3d430f3338a2c3496e9edeccc880f0a7affa06522b4249497ef6c4cd6571eaa9
    ubuntu@docker-node1:~$ sudo docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    0e7bef3f143a        bridge              bridge              local
    3d430f3338a2        demo                overlay             global
    a5c7daf62325        host                host                local
    3198cae88ab4        none                null                local

    在docker-node2上也看到一个demo的overlay network
    ubuntu@docker-node2:~$ sudo docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE
    0e7bef3f143a        bridge              bridge              local
    3d430f3338a2        demo                overlay             global
    a5c7daf62325        host                host                local
    3198cae88ab4        none                null                local
    
    

      

  • 相关阅读:
    为自己的应用程序添加脚本支持
    关于Excel VBA程序的界面编程及其他
    下载JAVA SDK 1.5
    在软件产品中使用VBA的软件和企业
    VBHelper:坚守脚本(转载)
    Google Desktop Search试用手记
    几个不错的开源的.net界面控件
    C++强大背后
    extern用法详解
    条款1:尽量用const和inline而不用#define
  • 原文地址:https://www.cnblogs.com/soymilk2019/p/13109616.html
Copyright © 2020-2023  润新知